asserts/tool,cmd/snap: introduce hidden "snap sign" #1573

Merged
merged 33 commits into from Sep 1, 2016

Conversation

Projects
None yet
5 participants
Contributor

pedronis commented Jul 20, 2016

No description provided.

Member

chipaca commented Jul 21, 2016

👍

@pedronis pedronis added the Blocked label Jul 21, 2016

Do we have plan to sign device-serial assertion via this "snap sign" command? Or is any alternative tool for signing device-serial?

@niemeyer niemeyer added the Decaying label Aug 26, 2016

asserts/tool/sign.go
+// Sign produces the text of a signed assertion as specified by req.
+func Sign(req *SignRequest, keypairMgr asserts.KeypairManager) ([]byte, error) {
+ var headers map[string]interface{}
+ err := yaml.Unmarshal(req.Statement, &headers)
@mvo5

mvo5 Aug 29, 2016

Collaborator

(nitpick) This could be a single line, i.e. if err := yaml.Unmarshal(...); err != nil {

asserts/tool/sign_test.go
+ "gadget": "brand-gadget",
+ "kernel": "baz-linux",
+ "store": "brand-store",
+ "required-snaps": []interface{}{"foo", "bar"},
@mvo5

mvo5 Aug 29, 2016

Collaborator

Silly question, why []interface{} here instead of []string{}?

@pedronis

pedronis Aug 29, 2016

Contributor

because that's what the parsing produces (because it could also be a list of lists), and the two are not comparable for free

asserts/tool/sign.go
+}
+
+// Sign produces the text of a signed assertion as specified by req.
+func Sign(req *SignRequest, keypairMgr asserts.KeypairManager) ([]byte, error) {
@mvo5

mvo5 Aug 29, 2016

Collaborator

Will SignRequest grow more struct members? It seems like for just two we might as well have sign(key, statement, keypairmgr). Of course if it will grow or if there are other good reasons thats totally fine, just wondering a bit :)

@pedronis

pedronis Aug 29, 2016

Contributor

@mvo5 it started with a lot of members, and now is down to two otoh exactly what members has changed as well quite a bit so I'm on a fence of simplifying to just args, anyway I expect it two grow a couple more (if we want to kill some duplication in a similar tool used for service admin)

asserts/tool/sign_test.go
+ req := tool.SignRequest{
+ KeyID: s.testKeyID,
+
+ Statement: []byte(modelYaml + `body: "BODY"
@mvo5

mvo5 Aug 29, 2016

Collaborator

I wonder if it makes sense to test a multi line body here. But given that its just yaml maybe I'm overthinking it.

@pedronis

pedronis Aug 29, 2016

Contributor

it would be testing YAML Unmarshal afaict

asserts/tool/sign_test.go
+ },
+ }
+
+ for _, t := range tests {
@mvo5

mvo5 Aug 29, 2016

Collaborator

Nice tests!

Collaborator

mvo5 commented Aug 29, 2016

Looks very nice, some nitpick/question, but certainly no blockers.

Collaborator

mvo5 commented Aug 29, 2016

Thanks for your replies! 👍

Contributor

pedronis commented Aug 29, 2016

discussed with @niemeyer, this should move to take only JSON

cmd/snap/cmd_sign.go
+`)
+
+type cmdSign struct {
+ KeyName string `long:"key-name" description:"name of the key to use, otherwise use the default key" default:"default"`
@niemeyer

niemeyer Aug 29, 2016

Contributor

s/key-name/key/, or perhaps even just -k?

@pedronis

pedronis Aug 31, 2016

Contributor

went for just -k

asserts/tool/sign.go
+import (
+ "fmt"
+
+ "gopkg.in/yaml.v2"
@niemeyer

niemeyer Aug 29, 2016

Contributor

JSON per conversation today (rationale for the record: this is about inter-tooling communication rather than human, and JSON has a much simpler syntax which is harder to get wrong - better for security concerns).

asserts/tool/sign.go
+ */
+
+// Package tool offers tooling to sign assertions.
+package tool
@niemeyer

niemeyer Aug 29, 2016

Contributor

Can we call this something like signtool instead? Will be nicer when using and when navigating the FS.

asserts/tool/sign.go
+)
+
+// SignRequest specifies the complete input for signing an assertion.
+type SignRequest struct {
@niemeyer

niemeyer Aug 29, 2016

Contributor

s/Request/Options/ would be more typical.

Contributor

niemeyer commented Aug 29, 2016

Only trivials. LGTM, and thanks!

@niemeyer niemeyer added the Reviewed label Aug 29, 2016

@pedronis pedronis merged commit bce07f2 into snapcore:master Sep 1, 2016

1 check failed

continuous-integration/travis-ci/pr The Travis CI build failed
Details

@pedronis pedronis deleted the pedronis:tool-sign-mk2 branch Sep 1, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment