Skip to content

Reload certificate and key from disk on each step ca renew --daemon cycle - #1746

Open
Jimmyman1465 wants to merge 1 commit into
smallstep:masterfrom
Jimmyman1465:fix/1632-renew-daemon-reload-keypair
Open

Jimmyman1465 wants to merge 1 commit into
smallstep:masterfrom
Jimmyman1465:fix/1632-renew-daemon-reload-keypair

Conversation

@Jimmyman1465

Copy link
Copy Markdown

Name of feature:

Reload certificate and private key from disk on each step ca renew --daemon cycle.

Pain or issue this feature alleviates:

Fixes #1632. Previously step ca renew --daemon loaded the certificate and private key once at startup and reused them indefinitely. When an external process (e.g., configuration management or rekeying) replaced the certificate and key on disk, the daemon kept renewing the old certificate and wrote it back over the new file, causing a certificate/private-key mismatch.

Why is this important to the project (if not answered above):

  • Added an optional reloadCert func() (tls.Certificate, error) hook on renewer (keeping newRenewer and Daemon signatures unchanged so rekey --daemon is unaffected), wired in renewCertificateAction for file-backed --daemon runs (kmsURI == "").
  • Reloads from disk at the start of RenewAndPrepareNext, validates that the loaded certificate's public key matches the private key (publicKeysEqual), skips the cycle with an error instead of overwriting disk if they are mismatched, supports outFile != certFile fallback to certFile on external replacement, updates r.cert / r.key / r.transport.TLSClientConfig.Certificates, and calls r.transport.CloseIdleConnections() when the leaf certificate changed.
  • Added unit tests in command/ca/renew_test.go covering mTLS keep-alive reload, token-based reload, mismatched on-disk keypair protection, and separate outFile external replacement.

Local verification:

  • go test -v -count=3 ./command/ca/... PASS (3/3)
  • go vet ./command/ca/... clean
  • gofmt -l command/ca/renew.go command/ca/renew_test.go clean
  • go build ./cmd/step OK

Is there documentation on how to use this feature? If so, where?

No new flags or configuration changes; existing step ca renew --daemon documentation applies.

In what environments or workflows is this feature supported?

File-backed step ca renew --daemon workflows (both mTLS and token renewal, with or without --out).

In what environments or workflows is this feature explicitly NOT supported (if any)?

KMS-backed keys (--kms), which retain existing behavior.

Supporting links/other PRs/issues:

Fixes #1632

… cycle

When `step ca renew --daemon` is initialized with file-based credentials,
it previously cached `cert`, `key`, and `transport.TLSClientConfig.Certificates`
at startup. If the certificate and private key on disk were rotated
externally, subsequent daemon cycles kept renewing with the startup keypair
(and idle mTLS connections) and wrote certificates bound to the stale
public key over disk.

Reload the on-disk keypair before each `RenewAndPrepareNext` cycle for
file-backed daemons, validate that the private key matches the certificate's
public key (skipping the cycle cleanly if mismatched), update the client
transport certificate, and close idle keep-alive connections when the
certificate bytes change.

Fixes smallstep#1632
@CLAassistant

CLAassistant commented Dec 3, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: step ca renew --daemon caches keypair at startup; produces cert/key mismatch after external key replacement

2 participants