-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add defaulting to Certificate - CertificateRequest comparison #8160
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
Conversation
…ting mismatches when upgrading Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a bug where cert-manager 1.19.x incorrectly renewed certificates during upgrades when the issuerRef's kind or group fields were omitted in the original Certificate. The fix replaces a simple reflect.DeepEqual comparison with custom logic that handles default values for issuerRef fields.
- Replaces reflect.DeepEqual with explicit field-by-field comparison for IssuerRef
- Adds helper functions to handle default values for issuer kind and group fields
- Removes unused reflect import
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
We plan on merging this fix before releasing v1.19.1, and backport it to v1.18.3. @wallrj proposed to work on this. |
f523072 to
fba189f
Compare
fba189f to
3682691
Compare
|
I've pushed the following changes to Tim's branch:
|
- Add TestRequestMatchesSpecIssuerRef covering name, kind, and group - Include cases for defaulted Kind/Group vs empty fields in CRs - Treat empty Kind/Group in CertificateRequest as 'Issuer' and - 'cert-manager.io' to avoid re-issuing certificates after 1.19 Signed-off-by: Richard Wall <richard.wall@cyberark.com>
3682691 to
bae74d1
Compare
This PR alone doesn't fix the problem. We think the original problem occurs when user upgrade to the 1.19 CRDs before upgrading the cert-manager controller causing the still running 1.18 controller to re-establish API watches and end up with inconsistent caches, where the cache contains Certificates that have the new API defaults, but CertificateRequests which have not yet been refreshed and do not have the new defaults. |
I agree, but this PR will allow us to reintroduce the API defaults in a future release - if we want. I have created a PR to revert the problematic API defaults, #8173, and think we should merge both PRs and cherry-pick them to the 1.19 release branch. This PR can even be cherry-picked to the 1.18 release branch, as I think it also fixes a bug unrelated to the API defaulting problem. |
| }) | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cherry picked these new tests on top of #8173 and ran them to demonstrate the problem. Here's the output:
-*- mode: compilation; default-directory: "~/projects/cert-manager/cert-manager/pkg/util/pki/" -*-
Compilation started at Wed Oct 15 09:47:25
go test -run='TestRequestMatchesSpecIssuerRef$'
--- FAIL: TestRequestMatchesSpecIssuerRef (0.69s)
--- FAIL: TestRequestMatchesSpecIssuerRef/should_not_report_any_violation_if_Certificate_issuerRef_Kind_and_Group_are_defaulted_and_CertificateRequest's_are_empty (0.00s)
match_test.go:477:
Error Trace: /home/richard/projects/cert-manager/cert-manager/pkg/util/pki/match_test.go:477
Error: Not equal:
expected: []string(nil)
actual : []string{"spec.issuerRef"}
Diff:
--- Expected
+++ Actual
@@ -1,2 +1,4 @@
-([]string) <nil>
+([]string) (len=1) {
+ (string) (len=14) "spec.issuerRef"
+}
Test: TestRequestMatchesSpecIssuerRef/should_not_report_any_violation_if_Certificate_issuerRef_Kind_and_Group_are_defaulted_and_CertificateRequest's_are_empty
--- FAIL: TestRequestMatchesSpecIssuerRef/should_not_report_any_violation_if_Certificate_issuerRef_Kind_and_Group_are_defaulted_and_CertificateRequest_issuerRef_Group_is_empty (0.00s)
match_test.go:477:
Error Trace: /home/richard/projects/cert-manager/cert-manager/pkg/util/pki/match_test.go:477
Error: Not equal:
expected: []string(nil)
actual : []string{"spec.issuerRef"}
Diff:
--- Expected
+++ Actual
@@ -1,2 +1,4 @@
-([]string) <nil>
+([]string) (len=1) {
+ (string) (len=14) "spec.issuerRef"
+}
Test: TestRequestMatchesSpecIssuerRef/should_not_report_any_violation_if_Certificate_issuerRef_Kind_and_Group_are_defaulted_and_CertificateRequest_issuerRef_Group_is_empty
--- FAIL: TestRequestMatchesSpecIssuerRef/should_not_report_any_violation_if_Certificate_issuerRef_Kind_and_Group_are_defaulted_and_CertificateRequest_issuerRef_Kind_is_empty (0.00s)
match_test.go:477:
Error Trace: /home/richard/projects/cert-manager/cert-manager/pkg/util/pki/match_test.go:477
Error: Not equal:
expected: []string(nil)
actual : []string{"spec.issuerRef"}
Diff:
--- Expected
+++ Actual
@@ -1,2 +1,4 @@
-([]string) <nil>
+([]string) (len=1) {
+ (string) (len=14) "spec.issuerRef"
+}
Test: TestRequestMatchesSpecIssuerRef/should_not_report_any_violation_if_Certificate_issuerRef_Kind_and_Group_are_defaulted_and_CertificateRequest_issuerRef_Kind_is_empty
FAIL
exit status 1
FAIL github.com/cert-manager/cert-manager/pkg/util/pki 0.745s
Compilation exited abnormally with code 1 at Wed Oct 15 09:47:27, duration 2.48 s
bae74d1 to
e44951b
Compare
pkg/util/pki/match.go
Outdated
| // These defaults are also applied at runtime by the cert-manager | ||
| // CertificateRequest controller. | ||
| // | ||
| // TODO(wallrj): Move this runtime defaulting to `internal/apis/certmanager/v1/defaults.go` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@erikgb Removed TODO comment as agreed during standup. I made my point. And we hope that in future the API defaults will be used. Not runtime defaults.
| // | ||
| // ... to the API struct. | ||
| // | ||
| // TODO(wallrj): Set the issuerRef defaults here too. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed TODO comment as agreed during standup. I made my point. And we hope that in future the API defaults will be used. Not runtime defaults.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
…esSpec - Explain that IssuerRef comparisons ignore default group and kind - Describe upgrades where CRD defaults can cause transient mismatches - Document issuerKindsEqual and issuerGroupsEqual behavior - Update test comment to describe the equivalence rationale Signed-off-by: Richard Wall <richard.wall@cyberark.com>
e44951b to
04a06e6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: erikgb 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 |
|
Thanks @erikgb /unhold |
|
@wallrj-cyberark: once the present PR merges, I will cherry-pick it on top of In response to this:
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-sigs/prow repository. |
|
@wallrj-cyberark: new pull request created: #8174 In response to this:
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-sigs/prow repository. |
|
@wallrj-cyberark: new pull request created: #8175 In response to this:
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-sigs/prow repository. |
This should prevent the unexpected renewals after upgrading to 1.19.x (see #8158).
How to test:
Kind
/kind bug
Release Note
CyberArk tracker: VC-46054