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

Reorder groups in cert Subjects #18837

Merged
merged 1 commit into from
Mar 7, 2018

Conversation

simo5
Copy link
Contributor

@simo5 simo5 commented Mar 5, 2018

This is to workaround Bug #18715, which is caused by Golang Crypto's x509
certificate generation ordering Subjects RDN incorrectly and GNUTLS'
bug that "fixes" client certs on read with the correct encoding.

To avoid issues until both are fixed we set the correct ordering ourself

Fixes #18715
xref golang/go#24254 https://gitlab.com/gnutls/gnutls/issues/403#note_61687722

@openshift-ci-robot openshift-ci-robot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Mar 5, 2018
@simo5
Copy link
Contributor Author

simo5 commented Mar 5, 2018

@martinpitt PTAL

@mrogers950
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 5, 2018
@enj
Copy link
Contributor

enj commented Mar 5, 2018

If there is a bug in Go itself, should not we fix this generically in:

Organization: u.GetGroups(),

by forcing the ordering that DER expects? Otherwise any other cert we generate with more than one organization will have this issue.

@simo5
Copy link
Contributor Author

simo5 commented Mar 5, 2018

We might do that as well, let's see if the bug goes away with this simple fix first.
Ideally we get golang fixed and we do not need no complex workaround code.

@enj
Copy link
Contributor

enj commented Mar 5, 2018

Ideally we get golang fixed and we do not need no complex workaround code.

If the Go bug gets fixed today, it will take 3 - 6+ months to show up in origin.

@martinpitt
Copy link

Thanks, this looks like an okay first bandaid!

This still feels a bit unpredictable, though - is there any chance this could not be a set (using the + syntax) but a plain good old list with two O: entries? Same as what would be generated by -subj '/O=system:masters/O=system:cluster-admins/CN=system:admin'?

@enj
Copy link
Contributor

enj commented Mar 5, 2018

is there any chance this could not be a set

The DER encoding is handled by the Go standard library, which uses the SET notation and is not configurable.

@simo5
Copy link
Contributor Author

simo5 commented Mar 5, 2018

@martinpitt I see no reason why we are trying to use multivalued RDNs, @liggitt may know if there is a good reason. We could certainly just have many RDNs and a deeper tree, but this PR fixes the iimediate Pain in an easy backportable way.
Once we know how we want to proceed we can make more complex changes in a different PR?

@@ -145,7 +145,7 @@ func DefaultClusterAdminClientCertInfo(certDir string) ClientCertInfo {
},
UnqualifiedUser: "admin",
User: "system:admin",
Groups: sets.NewString(bootstrappolicy.ClusterAdminGroup, bootstrappolicy.MastersGroup),
Groups: sets.NewString(bootstrappolicy.MastersGroup, bootstrappolicy.ClusterAdminGroup),
Copy link
Contributor

Choose a reason for hiding this comment

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

A string set is an order independent map. You cannot depend on order in a go map. This could easily change in different go versions or in different invocations (map iteration order is randomized per invocation)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can never be simple :-)

@liggitt
Copy link
Contributor

liggitt commented Mar 5, 2018

/hold

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 5, 2018
@simo5
Copy link
Contributor Author

simo5 commented Mar 5, 2018

@liggitt would it be ok to change ClientCertInfo to use []string instead of sets.String ?
Or is it preferable, at this point to introduce and explit reordering function in userToSubject() ?

@liggitt
Copy link
Contributor

liggitt commented Mar 5, 2018

Golang Crypto's x509 certificate generation ordering Subjects RDN incorrectly

can you clarify the bug here? either order should result in a valid x509 cert, right?

@liggitt
Copy link
Contributor

liggitt commented Mar 5, 2018

at this point to introduce and explit reordering function in userToSubject() ?

userToSubject isn't involved... the code that turns ClientCertInfo into a cert template for creation is at
https://github.com/openshift/origin/blob/master/pkg/cmd/server/admin/create_mastercerts.go#L306 and calls clientCertInfo.Groups.List(), which returns the groups in sorted order.

@enj
Copy link
Contributor

enj commented Mar 5, 2018

userToSubject isn't involved

It is the last thing we do to set the cert subject, but the order fixing could be done elsewhere. For example:

Subject: subject,

could have the fixup logic.

@simo5
Copy link
Contributor Author

simo5 commented Mar 5, 2018

@liggitt you need to go deeper, that code ends up calling https://github.com/openshift/origin/blob/master/pkg/cmd/server/crypto/crypto.go#L555 which ends up calling userToSubject() in signCertificate()

@simo5
Copy link
Contributor Author

simo5 commented Mar 5, 2018 via email

@liggitt
Copy link
Contributor

liggitt commented Mar 5, 2018

that code ends up calling https://github.com/openshift/origin/blob/master/pkg/cmd/server/crypto/crypto.go#L555 which ends up calling userToSubject() in signCertificate()

userToSubject just passes through whatever order was set in CreateClientCertOptions, it doesn't impose any ordering at all

@simo5
Copy link
Contributor Author

simo5 commented Mar 5, 2018

@LiGgit I know userToSubject() does not impose any ordering, but it is the place where all caller of signCertificate ends up into. If I change only CreateClientCertOptions I may miss some code paths.

@liggitt
Copy link
Contributor

liggitt commented Mar 5, 2018

@LiGgit I know userToSubject() does not impose any ordering, but it is the place where all caller of signCertificate ends up into. If I change only CreateClientCertOptions I may miss some code paths.

I see. Something like:

func userToSubject(u user.Info) pkix.Name {
	// Sort shortest first to workaround go DER encoding bug
	groups := u.GetGroups()
	sort.Slice(groups, func(i, j int) bool {
		if l := len(groups[i]) - len(groups[j]); l != 0 {
			return l < 0
		}
		return groups[i] < groups[j]
	})

	return pkix.Name{
		CommonName:   u.GetName(),
		SerialNumber: u.GetUID(),
		Organization: groups,
	}
}

@liggitt
Copy link
Contributor

liggitt commented Mar 5, 2018

I don't object to that. if you do that, please reference the go issue and reproducer so we don't lose track of it

@simo5
Copy link
Contributor Author

simo5 commented Mar 5, 2018

@liggitt Yeah that's what I was planning with a big FAT comment on why it is needed

@openshift-ci-robot openshift-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 5, 2018
@openshift-merge-robot openshift-merge-robot removed the lgtm Indicates that a PR is ready to be merged. label Mar 5, 2018
@mrogers950
Copy link
Contributor

golang/go#24254

@simo5 simo5 changed the title Reorder groups in Admin cert Reorder groups in cert Subjects Mar 5, 2018
@simo5
Copy link
Contributor Author

simo5 commented Mar 5, 2018

@LiGgit PTAL and lift hold if you are ok with this

@simo5
Copy link
Contributor Author

simo5 commented Mar 5, 2018

@liggitt [damn fingers stop messing with is name :-)] PTAL

@simo5
Copy link
Contributor Author

simo5 commented Mar 5, 2018

/retest

2 similar comments
@simo5
Copy link
Contributor Author

simo5 commented Mar 5, 2018

/retest

@simo5
Copy link
Contributor Author

simo5 commented Mar 6, 2018

/retest

@simo5
Copy link
Contributor Author

simo5 commented Mar 6, 2018

Flake #16832

// between the encoding of two group RDNs will end up being the encoded
// length which is directly related to the group name's length. So we'll
// sort such that shortest names come first.
groups := u.GetGroups()
Copy link
Contributor

Choose a reason for hiding this comment

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

actually, make a new slice and copy the groups into it, so we don't share memory and introduce the possibility of races.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

This is to workaround Bug openshift#18715, which is caused by Golang Crypto's x509
certificate generation ordering Subjects RDN incorrectly *and* GNUTLS'
bug that "fixes" client certs on read with the correct encoding.

To avoid issues until both are fixed we set the correct ordering on our
own...

Signed-off-by: Simo Sorce <[email protected]>
@liggitt
Copy link
Contributor

liggitt commented Mar 6, 2018

/hold cancel
/lgtm

@openshift-ci-robot openshift-ci-robot added lgtm Indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Mar 6, 2018
@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: liggitt, mrogers950, simo5

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 6, 2018
@simo5
Copy link
Contributor Author

simo5 commented Mar 6, 2018

/retest

2 similar comments
@simo5
Copy link
Contributor Author

simo5 commented Mar 6, 2018

/retest

@simo5
Copy link
Contributor Author

simo5 commented Mar 6, 2018

/retest

@openshift-merge-robot
Copy link
Contributor

Automatic merge from submit-queue (batch tested with PRs 18835, 18857, 18641, 18656, 18837).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3.9 alpha 3/4 regression: Certificate verification fails with GnuTLS
7 participants