Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wildcarded trustpinning for cert ids #1126

Merged
merged 3 commits into from
Apr 5, 2017

Conversation

endophage
Copy link
Contributor

Closes #1123

Signed-off-by: David Lawrence david.lawrence@docker.com (github: endophage)

@endophage endophage force-pushed the wildcard_trustpin_key branch from 1ff3f2a to d13ebc4 Compare March 30, 2017 17:40
Signed-off-by: David Lawrence <david.lawrence@docker.com> (github: endophage)
@endophage endophage force-pushed the wildcard_trustpin_key branch from d13ebc4 to d7352fc Compare March 30, 2017 18:01
@endophage
Copy link
Contributor Author

@ecordell figure you'll be interested in this. It basically makes individual key pinning useful in light of your wildcarded root cert CNs PR we merged. It'll also be useful when we roll back the requirement for root keys to be certs in the first place.

@endophage endophage requested review from riyazdf and ecordell March 31, 2017 00:10
@endophage
Copy link
Contributor Author

@riyazdf you did trustpinning originally so would like your review too.

Copy link
Contributor

@riyazdf riyazdf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code generally LGTM but have a test case and a couple of nits before the final green light 👍

@@ -363,6 +363,26 @@ func TestValidateRootWithPinnedCertAndIntermediates(t *testing.T) {
}
}
require.Equal(t, typedSignedRoot, validatedRoot)

// test is also works with a wildcarded gun in certs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nit: s/is/it/

@@ -37,6 +37,11 @@ func NewTrustPinChecker(trustPinConfig TrustPinConfig, gun data.GUN, firstBootst
t.pinnedCertIDs = pinnedCerts
return t.certsCheck, nil
}
var ok bool
t.pinnedCertIDs, ok = wildcardMatch(gun, trustPinConfig.Certs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think you can get away with := here and avoiding the extra var, but only because this is the last use of t.pinnedCertIDs. I'm generally of the opinion of the way you wrote this is more defensive though, so 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will double check but I think one of the go tools was shouting at me when I originally had :=

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it complains about non-name t.pinnedCertIDs on left side of :=

longest = ""
ids []string
)
for k, v := range certs {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we rename k and v to something more descriptive like gunPrefix and keyIDs?

},
DisableTOFU: true,
},
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add another test case or two for the precedence between globbed and non-globbed matches?

Ex:
this fails

Certs: map[string][]string{
    "docker.io/notary": {"badID"},
    "docker.io/notar*": {ecdsax509Key.ID()},
 },

this succeeds

Certs: map[string][]string{
    "docker.io/notary": {ecdsax509Key.ID()},
    "docker.io/notar*": {"badID"},
 },

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are the other way around right? The first should succeed and the second should fail?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that exact matches had precedence over wildcards?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nevermind, misunderstood because the docker.io/notary was short, you meant it to be docker.io/notary/test right? (i.e. the gun in use in the test)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, yes that's what I meant!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to this, can we also add a test that the more specific glob takes precedence over the less specific glob?
e.g.

			Certs: map[string][]string{
 				"docker.io/notary/te*": {"badID"},
 				"docker.io/notar*":      {ecdsax509Key.ID()},
 			},

fails while

			Certs: map[string][]string{
 				"docker.io/notary/te*": {ecdsax509Key.ID()},
 				"docker.io/notar*":      {"badID"},
 			},

succeeds?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@endophage
Copy link
Contributor Author

@riyazdf I think I addressed all your comments.

Copy link
Contributor

@riyazdf riyazdf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM on green - I wasn't able to view the logs for the circleci failure but seemed like it was just on one container (the one with linting and postgres)

@endophage
Copy link
Contributor Author

@riyazdf /go/src/github.com/docker/notary/trustpinning/certs_test.go:388:2: ineffectual assignment to validatedRoot fixing it now :-P

@endophage endophage force-pushed the wildcard_trustpin_key branch from ff3d1b1 to dc7fbd9 Compare April 3, 2017 17:38
require.True(t, ok)

// wildcardMatch should also match between segment boundaries, and take
// the first match is finds as the ONLY match.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is docker.io/endophage/b* actually the first match it finds? Since we can't depend on map order, couldn't the keys have come in any order? It chooses the longest matching one, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah sorry, I need to update the comment. I originally did first and was just going to have the user prioritize in their config file however they want, but that was before I remembered the random map ordering. Will update the comment.

@cyli
Copy link
Contributor

cyli commented Apr 5, 2017

Minor nitpick on a comment, but other than that LGTM!

Signed-off-by: David Lawrence <david.lawrence@docker.com> (github: endophage)
@endophage endophage force-pushed the wildcard_trustpin_key branch from dc7fbd9 to 576bdbf Compare April 5, 2017 03:33
@GordonTheTurtle
Copy link

Please sign your commits following these rules:
https://github.com/docker/docker/blob/master/CONTRIBUTING.md#sign-your-work
The easiest way to do this is to amend the last commit:

$ git clone -b "wildcard_trustpin_key" git@github.com:endophage/notary.git somewhere
$ cd somewhere
$ git rebase -i HEAD~842354364088
editor opens
change each 'pick' to 'edit'
save the file and quit
$ git commit --amend -s --no-edit
$ git rebase --continue # and repeat the amend for each commit
$ git push -f

Amending updates the existing PR. You DO NOT need to open a new one.

@endophage endophage merged commit 86e2ee9 into notaryproject:master Apr 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants