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

get-keypairs: Tolerate key set items without certificates #14370

Merged

Conversation

seh
Copy link
Contributor

@seh seh commented Oct 3, 2022

Allow the kops get keypairs command to consume key sets with old key pair items that lack an associated X.509 certificate. When the command is invoked without the --distrusted flag set to true, omit these old items as if they're distrusted. Conversely, when the command is invoked with the --distrusted flag set to true, include these items, but omit their details that would be contingent on the nonexistent certificate.

In order to supply only information that is known to be true, treat the following fields in the output as newly optional:

  • issuer
  • notAfter
  • notBefore
  • subject

With no certificate present, it's not possible to present concrete values for those fields.

Fixes #14174.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 3, 2022
}
sort.Strings(alternateNames)

if includeDistrusted || (item.DistrustTimestamp == nil && item.Certificate != nil) {
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's arguably strange to overload the meaning of "distrusted" here. We could update the documentation to mention this additional consideration, or introduce a separate flag to include these items lacking a certificate. I'm not sure that it's worth it.

Copy link
Member

Choose a reason for hiding this comment

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

I think ToCertificateBytes() and ToPublicKeys() in fi.Keyset need to also have Certificate != nil checks in addition to their current DistrustTimestamp checks, otherwise they could also trigger nil dereferences.

Given the above were done, it would be safe to claim that keypairs without certificates are inherently distrusted.

Similarly, VFSCAStore.StoreKeyset should verify that Certificate != nil for the primary id. promote_keypair.go should refuse to promote a keypair without a certificate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

John, I noticed that (*fi.Keyset).ToCertificateBytes filters items that lack a certificate. It could filter them a little bit earlier, but it looks they already won't make it into the composed CA bundle. Likewise, (*fi.Keyset).ToPublicKeys is guarded in the same way.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, so it seems promote_keypair.go is the only remaining issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did augment (*fi.VFSCAStore).StoreKeyset. I'm now working on the keypair promotion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please take another look, John. Thank you for the advice so far.

@hakman hakman requested review from justinsb and johngmyers and removed request for rdrgmnzs October 7, 2022 15:56
@johngmyers johngmyers requested review from johngmyers and removed request for johngmyers October 7, 2022 16:15
seh added 2 commits October 17, 2022 11:39
Allow the "kops get keypairs" command to consume key sets with old key
pair items that lack an associated X.509 certificate. When the command
is invoked without the "--distrusted" flag set to true, omit these old
items as if they're distrusted. Conversely, when the command is
invoked with the "--distrusted" flag set to true, include these items,
but omit their details that would be contingent on the nonexistent
certificate.

In order to supply only information that is known to be true, treat
the following fields in the output as newly optional:

- issuer
- notAfter
- notBefore
- subject

With no certificate present, it's not possible to present concrete
values for those fields.
Forbid the "kops promote keypair" command from promoting a key pair
item that lacks an associated X.509 certificate.

Along with that prohibition, refuse to store a key set in a VFS whose
primary key pair lacks a certificate. This allows us to continue
storing such key pairs, but we will never allow them to serve as the
primary key pair within the containing key set.
@seh seh force-pushed the ignore-keypairs-without-certificates branch from fec6c44 to 95f9889 Compare October 17, 2022 16:20
for id, item := range keyset.Items {
if item.PrivateKey != nil && item.DistrustTimestamp == nil {
if item.PrivateKey != nil && item.DistrustTimestamp == nil && item.Certificate != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could order the certificate check after the private key check, since those two things seem to go together more closely than the distrusting timestamp.

@@ -162,17 +162,17 @@ func promoteKeypair(out io.Writer, name string, keypairID string, keyStore fi.CA
}

if keypairID == "" {
highestTrustedId := big.NewInt(0)
highestCandidateId := big.NewInt(0)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since we're searching for a private key that's neither distrusted nor lacking a certificate, I figured I'd change the name here to be more general.

Copy link
Member

@johngmyers johngmyers left a comment

Choose a reason for hiding this comment

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

Thanks for doing this!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 17, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: johngmyers

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 17, 2022
@k8s-ci-robot k8s-ci-robot merged commit 6a4c9da into kubernetes:master Oct 17, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.26 milestone Oct 17, 2022
@seh
Copy link
Contributor Author

seh commented Oct 17, 2022

Can we also back-port this to the version 1.25 release line? That's the version of kOps we're using for the time being.

k8s-ci-robot added a commit that referenced this pull request Oct 18, 2022
…-upstream-release-1.25

Automated cherry pick of #14370: get-keypairs: Tolerate items without certificates
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/office-hours lgtm "Looks good to me", 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.

"kops update cluster" panics while creating JWKS for OIDC
4 participants