Skip to content

[kms]: Do not schedule rotation without a vault - #126

Merged
pseudomuto merged 1 commit into
mainfrom
kms_skip_rotation_without_vault
Aug 10, 2026
Merged

[kms]: Do not schedule rotation without a vault#126
pseudomuto merged 1 commit into
mainfrom
kms_skip_rotation_without_vault

Conversation

@pseudomuto

Copy link
Copy Markdown
Collaborator

The vault is built from key presence while rotation was scheduled from Encryption.Enabled, so enabling encryption with no configured key produced a nil vault and a rotation goroutine that dereferences it.

The full app never hit this because whole-config validation rejects that combination, but validation lives in a module wired after this one, so the protection was ordering, not logic. Guard the hook and cover the case.

The vault is built from key presence while rotation was scheduled from
Encryption.Enabled, so enabling encryption with no configured key produced a
nil vault and a rotation goroutine that dereferences it.

The full app never hit this because whole-config validation rejects that
combination, but validation lives in a module wired after this one, so the
protection was ordering, not logic. Guard the hook and cover the case.
@pseudomuto
pseudomuto requested a lite review from Copilot August 10, 2026 15:40
@pseudomuto
pseudomuto requested a review from a team as a code owner August 10, 2026 15:40
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a startup-time panic in the KMS fx module by ensuring the key-rotation lifecycle hook is only scheduled when a vault actually exists (i.e., keys are configured), even if Encryption.Enabled is true. This aligns rotation scheduling with how the vault is constructed (from key presence) and removes reliance on module ordering for safety.

Changes:

  • Guard rotation scheduling in internal/kms so it no-ops when the injected vault is nil.
  • Add an fx test covering the “encryption enabled but no keys configured” case to ensure start/stop runs cleanly.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/kms/fx.go Adds a v == nil guard to prevent scheduling rotation against a nil vault.
internal/kms/fx_test.go Adds a test that starts/stops an app with encryption enabled but no keys, asserting no vault and no crash.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread internal/kms/fx_test.go
@pseudomuto
pseudomuto merged commit 5d7d1bb into main Aug 10, 2026
7 checks passed
@pseudomuto
pseudomuto deleted the kms_skip_rotation_without_vault branch August 10, 2026 15:47
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.

3 participants