Skip to content

Fix changed behavior: set critical flag of SANs extension based on subject #6724

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

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

inteon
Copy link
Member

@inteon inteon commented Feb 7, 2024

In #6404, we introduced a new SAN (OtherName).
This SAN is not directly supported by the golang x509 library.
That is why we had to create our custom parsing logic to still be able to add this SAN.
However, the behavior of the x509 CSR -> x509 Cert conversion logic was also accidentally changed.
The following lines blindly copy the SAN extension from the CSR:

// The SANs fields in the Certificate resource are not enough to
// represent the full set of SANs that can be encoded in a CSR.
// Therefore, we need to copy the SANs from the CSR into the
// ExtraExtensions field of the certificate template.
if val.Id.Equal(oidExtensionSubjectAltName) {
template.ExtraExtensions = append(template.ExtraExtensions, val)
}

We do however not re-evaluate if the critical flag should be set on the extension.
Before #6404, we did re-create the SANs and re-determined if the critical flag has to be set at that point in time.

This PR fixes this issue by adding a new "fix" step that fixes the SAN extensions based on the provided subject.

Long term, I think we should move this x509 logic into a seperate library with a much reduced public API.

Kind

/kind bug

Release Note

BUGFIX: cert-manager issuers incorrectly copied the critical flag from the CSR instead of re-calculating that field themselves.

@jetstack-bot jetstack-bot added kind/bug Categorizes issue or PR as related to a bug. release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 7, 2024
@@ -321,11 +321,7 @@ func GenerateCSR(crt *v1.Certificate, optFuncs ...GenerateCSROption) (*x509.Cert
var extraExtensions []pkix.Extension

if !sans.Empty() {
// emptyASN1Subject is the ASN.1 DER encoding of an empty Subject, which is
Copy link
Member Author

Choose a reason for hiding this comment

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

I moved this logic to the new IsASN1SubjectEmpty function.

…bject

Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
@inteon inteon force-pushed the fix_sans_critical branch from 23bc695 to 0acde5b Compare February 7, 2024 10:01
@inteon
Copy link
Member Author

inteon commented Feb 7, 2024

/cherrypick release-1.14

@jetstack-bot
Copy link
Contributor

@inteon: once the present PR merges, I will cherry-pick it on top of release-1.14 in a new PR and assign it to you.

In response to this:

/cherrypick release-1.14

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@inteon inteon added this to the 1.14 milestone Feb 7, 2024
Copy link
Member

@SgtCoDFish SgtCoDFish left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

Thanks for fixing this so quickly! 🚀

@jetstack-bot jetstack-bot added the lgtm Indicates that a PR is ready to be merged. label Feb 7, 2024
@jetstack-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: SgtCoDFish

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

@jetstack-bot jetstack-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 7, 2024
@jetstack-bot jetstack-bot merged commit 968ad2f into cert-manager:master Feb 7, 2024
@jetstack-bot
Copy link
Contributor

@inteon: new pull request created: #6727

In response to this:

/cherrypick release-1.14

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@wallrj
Copy link
Member

wallrj commented Feb 7, 2024

@@ -261,6 +261,26 @@ func CertificateTemplateFromCSR(csr *x509.CertificateRequest, validatorMutators
}
}

// Finally, we fix up the certificate template to ensure that it is valid
{
// If the certificate has an empty Subject, we set any SAN extensions to be critical
Copy link
Member

Choose a reason for hiding this comment

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

A comment explaining why would have been helpful, with a link to the RFC.

https://github.com/golang/go/blob/7020beeffda464a91f8275c3e89487bafad98428/src/crypto/x509/x509.go#L1180-L1182

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, should be added and I should've required it in review. Sorry!

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. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants