Skip to content

fix: use deterministic name for next-private-key Secret to prevent ra… - #8539

Closed
putongyong wants to merge 1 commit into
cert-manager:masterfrom
putongyong:fix/keymanager-deterministic-secret-name
Closed

putongyong wants to merge 1 commit into
cert-manager:masterfrom
putongyong:fix/keymanager-deterministic-secret-name

Conversation

@putongyong

@putongyong putongyong commented Feb 23, 2026 •

Copy link
Copy Markdown
Contributor

When multiple goroutines process the same Certificate concurrently, they could each call GenerateName which always produces a unique random name, resulting in duplicate next-private-key Secrets. The cleanup logic then deletes all of them, including ones already used to generate a CSR, causing InvalidCertificate failures with exponential backoff.

Fix by using a deterministic name derived from the Certificate name so that concurrent Create calls result in AlreadyExists, making the operation idempotent.

Fixes #8514

Pull Request Motivation

Kind

/kind

Release Note

NONE

…ce condition

When multiple goroutines process the same Certificate concurrently, they
could each call GenerateName which always produces a unique random name,
resulting in duplicate next-private-key Secrets. The cleanup logic then
deletes all of them, including ones already used to generate a CSR,
causing InvalidCertificate failures with exponential backoff.

Fix by using a deterministic name derived from the Certificate name so
that concurrent Create calls result in AlreadyExists, making the
operation idempotent.

Fixes cert-manager#8514

Signed-off-by: putongyong <[email protected]>
@cert-manager-prow

Copy link
Copy Markdown
Contributor

@putongyong: The label(s) kind/release, kind/note cannot be applied, because the repository doesn't have them.

Details

In response to this:

…ce condition

When multiple goroutines process the same Certificate concurrently, they could each call GenerateName which always produces a unique random name, resulting in duplicate next-private-key Secrets. The cleanup logic then deletes all of them, including ones already used to generate a CSR, causing InvalidCertificate failures with exponential backoff.

Fix by using a deterministic name derived from the Certificate name so that concurrent Create calls result in AlreadyExists, making the operation idempotent.

Fixes #8514

Pull Request Motivation

Kind

/kind

Release Note

NONE

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.

@cert-manager-prow cert-manager-prow Bot added release-note-none Denotes a PR that doesn't merit a release note. dco-signoff: no Indicates that at least one commit in this pull request is missing the DCO sign-off message. labels Feb 23, 2026
@cert-manager-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign maelvls for approval. For more information see the Code Review Process.

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

Details 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

@cert-manager-prow cert-manager-prow Bot added needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 23, 2026
@cert-manager-prow

Copy link
Copy Markdown
Contributor

Hi @putongyong. Thanks for your PR.

I'm waiting for a cert-manager member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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.

@cert-manager-prow cert-manager-prow Bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Feb 23, 2026
@putongyong
putongyong force-pushed the fix/keymanager-deterministic-secret-name branch from af3a44d to 93c31a9 Compare February 23, 2026 15:14
@cert-manager-prow cert-manager-prow Bot added dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. and removed dco-signoff: no Indicates that at least one commit in this pull request is missing the DCO sign-off message. labels Feb 23, 2026
@ThatsMrTalbot

Copy link
Copy Markdown
Contributor

Hi @putongyong

When multiple goroutines process the same Certificate concurrently

cert-manager, and Kubernetes operators in general, don't operate on the same object concurrently. Even if you increase the concurrency of controllers the workqueue logic ensures a single object is not reconciled by multiple go-routines at the same time.

This being said, we do recognise that that we can get into a state where we create multiple secrets, usually via a subsequent reconcile happening before the informer cache has updated with the latest objects from the APIServer. Instead of changing the behaviour on how we name secrets the fix is probably to address this todo we have in our code.

@putongyong

Copy link
Copy Markdown
Contributor Author

@ThatsMrTalbot Hi, thanks for the comment!

You're right, this is quite an edge case. I believe it only occurs when one key manager instance is already processing a request for a secret, and another request for the same secret gets enqueued and processed before the first one completes.

That solution looks much cleaner — I'll go ahead and update the pull request.

@putongyong

Copy link
Copy Markdown
Contributor Author

@ThatsMrTalbot Reopening with updated solution in #8577

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. release-note-none Denotes a PR that doesn't merit a release note. 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.

v1.19.3: Internal keymanager race condition triggers InvalidCertificate backoff when using external issuers (Google CAS)

2 participants