-
Notifications
You must be signed in to change notification settings - Fork 40k
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
certificate_manager: Check that template differs from current cert before rotation #69991
Conversation
/cc @caesarxuchao |
/ok-to-test |
there's a gofmt error that needs fixing to make the bot happy:
|
glog.V(2).Infof("Current certificate CN (%s) does not match requested CN (%s), rotating now", m.cert.Leaf.Subject.CommonName, template.Subject.CommonName) | ||
return time.Now() | ||
glog.V(2).Infof("Current certificate CN (%s) does not match requested CN (%s)", m.cert.Leaf.Subject.CommonName, template.Subject.CommonName) | ||
return false | ||
} |
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.
also check sets.NewString(m.cert.Leaf.Subject.Organizations...).HasAll(template.Subject.Organizations...)
/test pull-kubernetes-e2e-gke |
thanks for the PR, just a couple comments. exercising the logic in a unit test would be good as well |
return time.Now() | ||
} | ||
|
||
m.certAccessLock.RLock() |
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.
certSatisfiesTemplate
already locks the mutex, this will deadlock.
Recommend splitting certSatisfiesTemplate
into two functions: unlocked one and a locking wrapper. Call the unlocked one here and the locked one in manager.Start
0b5c749
to
c58b569
Compare
Thanks everyone for the comments! I've updated this PR to address them. Changes:
|
c58b569
to
c11f21e
Compare
Fixed the lint issue reported by |
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.
Two small nits, LGTM otherwise
} | ||
|
||
if m.certSatisfiesTemplate() != tc.shouldSatisfy { | ||
if tc.shouldSatisfy { |
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.
Don't wrap errors, store certSatisfiesTemplate
result in a var and do a simpler error print:
t.Errorf("cert: %+v, template: %+v, certSatisfiesTemplate returned %v, want %v", m.cert, tc.template, got, tc.shouldSatisfy)
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.
Thanks, I'll fix that.
m := manager{ | ||
cert: tlsCert, | ||
getTemplate: func() *x509.CertificateRequest { return tc.template }, | ||
usages: []certificates.KeyUsage{}, |
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.
Is this needed?
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.
Nope, I'll remove it.
…fore rotation With the current behavior, when kubelet starts, a `templateChanged` event is always fired off because it only checks if `getLastRequest` matches `getTemplate`. The last request only exists in memory and thus is initially `nil` and can't ever match the current template during startup. This causes kubelet to request the signing of a new CSR every time it's restarted. This commit changes the behavior so that `templateChanged` is only fired off if the currently template doesn't match both the current certificate and the last template. Fixes kubernetes#69471 Signed-off-by: Andrew Gunnerson <andrew.gunnerson@us.ibm.com>
c11f21e
to
b9ab65d
Compare
The latest commit should address @awly's comments above. |
/lgtm |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: agunnerson-ibm, liggitt 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 for putting this together |
/retest Review the full test history for this PR. Silence the bot with an |
What type of PR is this?
/kind bug
What this PR does / why we need it:
With the current behavior, when kubelet starts, a
templateChanged
event is always fired off because it only checks if
getLastRequest
matches
getTemplate
. The last request only exists in memory and thusis initially
nil
and can't ever match the current template duringstartup.
This causes kubelet to request the signing of a new CSR every time it's
restarted. This commit changes the behavior so that
templateChanged
isonly fired off if the currently template doesn't match both the current
certificate and the last template.
Which issue(s) this PR fixes:
Fixes #69471
Release note: