Skip to content

CSR not signed by referenced private key #6331

Closed

Description

@marcingy

We are randomly experiencing cases where we get an error that is hit is "CSR not signed by referenced private key", which indicates that the secret got changed from the start of the reconcile process. We enabled StableCertificateRequestName=true
to see if it would help with the issue but it hasn't.

This seems to indicate 2 self sign cert requests for the same cert are inflight at the same time.

The second CR request fails and the certificate is not being renewed ever again.

The occurrence of the this issue is random with the cert process working happily across multiple clusters 99% of the time.

Activity

  1. inteon commented on Sep 12, 2023

    @inteon
    Member

    Where are you seeing that error & what cert-manager version are you using?

  2. marcingy commented on Sep 12, 2023

    @marcingy
    Author

    We are on the latest released version so 1.12.x and we see it randomly when self sign certs are being created.

  3. jetstack-bot commented on Dec 11, 2023

    @jetstack-bot
    Contributor

    Issues go stale after 90d of inactivity.
    Mark the issue as fresh with /remove-lifecycle stale.
    Stale issues rot after an additional 30d of inactivity and eventually close.
    If this issue is safe to close now please do so with /close.
    Send feedback to jetstack.
    /lifecycle stale

  4. added
    lifecycle/stale
    on Dec 11, 2023
  5. jetstack-bot commented on Jan 10, 2024

    @jetstack-bot
    Contributor

    Stale issues rot after 30d of inactivity.
    Mark the issue as fresh with /remove-lifecycle rotten.
    Rotten issues close after an additional 30d of inactivity.
    If this issue is safe to close now please do so with /close.
    Send feedback to jetstack.
    /lifecycle rotten
    /remove-lifecycle stale

  6. added
    lifecycle/rotten
    and removed
    lifecycle/stale
    on Jan 10, 2024
  7. dkoshkin commented on Jan 24, 2024

    @dkoshkin

    We just saw this too creating a CAPZ Deployment

    I0124 05:35:49.533487       1 controller.go:162] "cert-manager/certificates-key-manager: re-queuing item due to optimistic locking on resource" key="capz-system/capz-serving-cert" error="Operation cannot be fulfilled on certificates.cert-manager.io \"capz-serving-cert\": the object has been modified; please apply your changes to the latest version and try again"
    I0124 05:35:49.576483       1 conditions.go:192] Found status change for Certificate "capg-serving-cert" condition "Ready": "False" -> "True"; setting lastTransitionTime to 2024-01-24 05:35:49.576470051 +0000 UTC m=+32.890554247
    I0124 05:35:49.715365       1 controller.go:162] "cert-manager/certificates-readiness: re-queuing item due to optimistic locking on resource" key="capg-system/capg-serving-cert" error="Operation cannot be fulfilled on certificates.cert-manager.io \"capg-serving-cert\": the object has been modified; please apply your changes to the latest version and try again"
    I0124 05:35:49.835850       1 conditions.go:192] Found status change for Certificate "capg-serving-cert" condition "Ready": "False" -> "True"; setting lastTransitionTime to 2024-01-24 05:35:49.835826172 +0000 UTC m=+33.149910379
    I0124 05:35:49.932008       1 conditions.go:263] Setting lastTransitionTime for CertificateRequest "capvcd-serving-cert-1" condition "Approved" to 2024-01-24 05:35:49.93199695 +0000 UTC m=+33.246081153
    I0124 05:35:50.129423       1 controller.go:162] "cert-manager/certificates-readiness: re-queuing item due to optimistic locking on resource" key="capg-system/capg-serving-cert" error="Operation cannot be fulfilled on certificates.cert-manager.io \"capg-serving-cert\": the object has been modified; please apply your changes to the latest version and try again"
    I0124 05:35:50.131927       1 conditions.go:192] Found status change for Certificate "capg-serving-cert" condition "Ready": "False" -> "True"; setting lastTransitionTime to 2024-01-24 05:35:50.131917255 +0000 UTC m=+33.446001460
    I0124 05:35:50.139891       1 conditions.go:263] Setting lastTransitionTime for CertificateRequest "capvcd-serving-cert-1" condition "Ready" to 2024-01-24 05:35:50.139882652 +0000 UTC m=+33.453966852
    I0124 05:35:50.404292       1 conditions.go:192] Found status change for Certificate "capvcd-serving-cert" condition "Ready": "False" -> "True"; setting lastTransitionTime to 2024-01-24 05:35:50.404281844 +0000 UTC m=+33.718366044
    I0124 05:35:50.658932       1 controller.go:162] "cert-manager/certificates-issuing: re-queuing item due to optimistic locking on resource" key="capvcd-system/capvcd-serving-cert" error="Operation cannot be fulfilled on certificates.cert-manager.io \"capvcd-serving-cert\": the object has been modified; please apply your changes to the latest version and try again"
    I0124 05:35:52.054534       1 controller.go:162] "cert-manager/certificates-key-manager: re-queuing item due to optimistic locking on resource" key="capvcd-system/capvcd-serving-cert" error="Operation cannot be fulfilled on certificates.cert-manager.io \"capvcd-serving-cert\": the object has been modified; please apply your changes to the latest version and try again"
    I0124 05:35:52.239774       1 controller.go:162] "cert-manager/certificates-key-manager: re-queuing item due to optimistic locking on resource" key="capv-system/capv-serving-cert" error="Operation cannot be fulfilled on certificates.cert-manager.io \"capv-serving-cert\": the object has been modified; please apply your changes to the latest version and try again"
    I0124 05:35:52.484646       1 conditions.go:263] Setting lastTransitionTime for CertificateRequest "capv-serving-cert-1" condition "Approved" to 2024-01-24 05:35:52.484635647 +0000 UTC m=+35.798719850
    I0124 05:35:52.564830       1 conditions.go:263] Setting lastTransitionTime for CertificateRequest "capz-serving-cert-1" condition "Approved" to 2024-01-24 05:35:52.564817605 +0000 UTC m=+35.878901797
    I0124 05:35:52.672141       1 conditions.go:263] Setting lastTransitionTime for CertificateRequest "capz-serving-cert-1" condition "Ready" to 2024-01-24 05:35:52.67213201 +0000 UTC m=+35.986216208
    E0124 05:35:52.672192       1 selfsigned.go:194] "cert-manager/certificaterequests-issuer-selfsigned/sign: Error generating certificate template" err="CSR not signed by referenced private key" resource_name="capz-serving-cert-1" resource_namespace="capz-system" resource_kind="CertificateRequest" resource_version="v1"
    I0124 05:35:52.676554       1 conditions.go:263] Setting lastTransitionTime for CertificateRequest "capv-serving-cert-1" condition "Ready" to 2024-01-24 05:35:52.676544375 +0000 UTC m=+35.990628570
    I0124 05:35:52.808312       1 conditions.go:192] Found status change for Certificate "capz-serving-cert" condition "Issuing": "True" -> "False"; setting lastTransitionTime to 2024-01-24 05:35:52.808301152 +0000 UTC m=+36.122385362
    I0124 05:35:53.069030       1 conditions.go:263] Setting lastTransitionTime for CertificateRequest "capz-serving-cert-1" condition "Approved" to 2024-01-24 05:35:53.069018391 +0000 UTC m=+36.383102594
    I0124 05:35:53.090294       1 trigger_controller.go:173] "cert-manager/certificates-trigger: Backing off from issuance due to previously failed issuance(s). Issuance will next be attempted at 2024-01-24 06:35:52.000000906 +0000 UTC m=+3635.314085103" key="capz-system/capz-serving-cert"
    I0124 05:35:53.091451       1 conditions.go:192] Found status change for Certificate "capv-serving-cert" condition "Ready": "False" -> "True"; setting lastTransitionTime to 2024-01-24 05:35:53.091442578 +0000 UTC m=+36.405526782
    I0124 05:35:53.287844       1 trigger_controller.go:173] "cert-manager/certificates-trigger: Backing off from issuance due to previously failed issuance(s). Issuance will next be attempted at 2024-01-24 06:35:52.000000962 +0000 UTC m=+3635.314085147" key="capz-system/capz-serving-cert"
    I0124 05:35:53.332885       1 controller.go:162] "cert-manager/certificates-issuing: re-queuing item due to optimistic locking on resource" key="capv-system/capv-serving-cert" error="Operation cannot be fulfilled on certificates.cert-manager.io \"capv-serving-cert\": the object has been modified; please apply your changes to the latest version and try again"
    I0124 05:35:53.360598       1 conditions.go:263] Setting lastTransitionTime for CertificateRequest "capz-serving-cert-1" condition "Ready" to 2024-01-24 05:35:53.36058677 +0000 UTC m=+36.674670973
    I0124 05:35:53.395395       1 trigger_controller.go:173] "cert-manager/certificates-trigger: Backing off from issuance due to previously failed issuance(s). Issuance will next be attempted at 2024-01-24 06:35:52.000000945 +0000 UTC m=+3635.314085139" key="capz-system/capz-serving-cert"
    I0124 05:35:53.479670       1 trigger_controller.go:173] "cert-manager/certificates-trigger: Backing off from issuance due to previously failed issuance(s). Issuance will next be attempted at 2024-01-24 06:35:52.000001345 +0000 UTC m=+3635.314085539" key="capz-system/capz-serving-cert"
    I0124 06:35:52.003178       1 trigger_controller.go:194] "cert-manager/certificates-trigger: Certificate must be re-issued" key="capz-system/capz-serving-cert" reason="DoesNotExist" message="Issuing certificate as Secret does not exist"
    I0124 06:35:52.003209       1 conditions.go:192] Found status change for Certificate "capz-serving-cert" condition "Issuing": "False" -> "True"; setting lastTransitionTime to 2024-01-24 06:35:52.003203682 +0000 UTC m=+3635.317287888
    I0124 06:35:52.285601       1 issuing_controller.go:324] "cert-manager/certificates-issuing: next private key does not match CSR public key, waiting for requestmanager controller" key="capz-system/capz-serving-cert" resource_name="capz-serving-cert" resource_namespace="capz-system" resource_kind="Certificate" resource_version="v1" resource_name="capz-serving-cert-1" resource_namespace="capz-system" resource_kind="CertificateRequest" resource_version="v1" resource_name="capz-serving-cert-nln5j" resource_namespace="capz-system" resource_kind="Secret" resource_version="v1"
    I0124 06:35:52.298983       1 controller.go:162] "cert-manager/certificates-key-manager: re-queuing item due to optimistic locking on resource" key="capz-system/capz-serving-cert" error="Operation cannot be fulfilled on certificates.cert-manager.io \"capz-serving-cert\": the object has been modified; please apply your changes to the latest version and try again"
    I0124 06:35:52.309034       1 conditions.go:263] Setting lastTransitionTime for CertificateRequest "capz-serving-cert-1" condition "Approved" to 2024-01-24 06:35:52.309027317 +0000 UTC m=+3635.623111520
    I0124 06:35:52.335004       1 conditions.go:263] Setting lastTransitionTime for CertificateRequest "capz-serving-cert-1" condition "Ready" to 2024-01-24 06:35:52.334996744 +0000 UTC m=+3635.649080930
    I0124 06:35:52.366787       1 conditions.go:192] Found status change for Certificate "capz-serving-cert" condition "Ready": "False" -> "True"; setting lastTransitionTime to 2024-01-24 06:35:52.366778511 +0000 UTC m=+3635.680862718
    I0124 06:35:52.440098       1 controller.go:162] "cert-manager/certificates-readiness: re-queuing item due to optimistic locking on resource" key="capz-system/capz-serving-cert" error="Operation cannot be fulfilled on certificates.cert-manager.io \"capz-serving-cert\": the object has been modified; please apply your changes to the latest version and try again"
    I0124 06:35:52.445914       1 conditions.go:192] Found status change for Certificate "capz-serving-cert" condition "Ready": "False" -> "True"; setting lastTransitionTime to 2024-01-24 06:35:52.44590579 +0000 UTC m=+3635.759989996
    I0124 06:35:52.502773       1 controller.go:162] "cert-manager/certificates-issuing: re-queuing item due to optimistic locking on resource" key="capz-system/capz-serving-cert" error="Operation cannot be fulfilled on certificates.cert-manager.io \"capz-serving-cert\": the object has been modified; please apply your changes to the latest version and try again"
    I0124 06:35:52.503208       1 controller.go:162] "cert-manager/certificates-key-manager: re-queuing item due to optimistic locking on resource" key="capz-system/capz-serving-cert" error="Operation cannot be fulfilled on certificates.cert-manager.io \"capz-serving-cert\": the object has been modified; please apply your changes to the latest version and try again"
    

    It did eventually create the Secret at 06:35

    kind: Secret
    metadata:
      annotations:
        cert-manager.io/alt-names: capz-webhook-service.capz-system.svc,capz-webhook-service.capz-system.svc.cluster.local
        cert-manager.io/certificate-name: capz-serving-cert
        cert-manager.io/common-name: ""
        cert-manager.io/ip-sans: ""
        cert-manager.io/issuer-group: ""
        cert-manager.io/issuer-kind: Issuer
        cert-manager.io/issuer-name: capz-selfsigned-issuer
        cert-manager.io/uri-sans: ""
      creationTimestamp: "2024-01-24T06:35:52Z"
      labels:
        controller.cert-manager.io/fao: "true"
      name: capz-webhook-service-cert
      namespace: capz-system
      resourceVersion: "18339"
      uid: 4264faad-c0fa-468f-b7e5-6482934c9ba1
    type: kubernetes.io/tls
    
  8. jetstack-bot commented on Feb 24, 2024

    @jetstack-bot
    Contributor

    Rotten issues close after 30d of inactivity.
    Reopen the issue with /reopen.
    Mark the issue as fresh with /remove-lifecycle rotten.
    /close

  9. jetstack-bot commented on Feb 24, 2024

    @jetstack-bot
    Contributor

    @jetstack-bot: Closing this issue.

    Details

    In response to this:

    Rotten issues close after 30d of inactivity.
    Reopen the issue with /reopen.
    Mark the issue as fresh with /remove-lifecycle rotten.
    /close

    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.

  10. inteon commented on Feb 24, 2024

    @inteon
    Member

    /reopen

  11. jetstack-bot commented on Feb 24, 2024

    @jetstack-bot
    Contributor

    @inteon: Reopened this issue.

    Details

    In response to this:

    /reopen

    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.

  12. inteon commented on Feb 24, 2024

    @inteon
    Member

    /remove-lifecycle rotten

  13. 25 remaining items

  14. s-rodriguez commented on Mar 10, 2025

    @s-rodriguez

    /remove-lifecycle stale

  15. removed
    lifecycle/stale
    on Mar 10, 2025
  16. cert-manager-bot commented on Jun 8, 2025

    @cert-manager-bot
    Contributor

    Issues go stale after 90d of inactivity.
    Mark the issue as fresh with /remove-lifecycle stale.
    Stale issues rot after an additional 30d of inactivity and eventually close.
    If this issue is safe to close now please do so with /close.
    /lifecycle stale

  17. added
    lifecycle/stale
    on Jun 8, 2025
  18. s-rodriguez commented on Jun 9, 2025

    @s-rodriguez

    /remove-lifecycle stale

  19. removed
    lifecycle/stale
    on Jun 9, 2025
  20. cert-manager-bot commented on Dec 8, 2025

    @cert-manager-bot
    Contributor

    Issues go stale after 6 months of inactivity.
    Mark the issue as fresh with /remove-lifecycle stale.
    Stale issues remain open for an additional 3 months of inactivity and then close.
    If this issue is safe to close now please do so with /close.
    /lifecycle stale

  21. added
    lifecycle/stale
    on Dec 8, 2025
  22. added
    lifecycle/frozen
    and removed
    lifecycle/stale
    on Dec 10, 2025
  23. wallrj commented on Aug 10, 2026

    @wallrj
    Member

    Diagnosis, for anyone landing here.

    The trigger is a next-private-key rotation while a CertificateRequest built from the old key is still in flight: the self-signed issuer signs against the new key, finds the CSR was built with the old one, and fails the request with ErrorKeyMatch ("CSR not signed by referenced private key"). The requestmanager then deletes that stale request and rebuilds it against the new key, so the failure is spurious.

    The bug is that the issuing controller acted on the Failed verdict before checking whether the request was merely stale, so it counted a spurious failure as a real one and imposed a failed-issuance backoff (default 1h, exponential to a 32h cap, but always retrying).

    On the "not being renewed ever again" reports: the only concrete logs on this issue — @dkoshkin's v1.13 CAPZ dump above — actually show recovery. The request fails at 05:35:52, the trigger controller backs off to 06:35:52, and at 06:35:52 it re-issues (reason="DoesNotExist", i.e. the stale request was deleted and rebuilt) and the Secret is created. So self-healing was working; the certificate was stuck behind the backoff, not permanently broken. "Never renews again" is that 1h–32h delay read as permanent.

    #9116 removes the delay: the issuing controller now settles the staleness question first and waits for the rebuild instead of failing. One narrow residual window remains — if the issuing controller's own secret informer still holds the old key when it reconciles the failed request, the check passes and it fails as before — so if anyone can still reproduce a genuinely permanent stall, please reopen with logs.

    Full archaeology of how the check ended up on the wrong side of the failure handling: https://gist.github.com/wallrj/0d5b62deb7646e8ecaaa1e7604d6c665

    with claude fable-5

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/buglifecycle/frozenpriority/important-soon

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions