Skip to content

fix(iac/aws): create_before_destroy on OIDC signing key (follow-up to #1480) - #1512

Merged
cristim merged 1 commit into
mainfrom
fix/1480-signing-key-create-before-destroy
Jul 27, 2026
Merged

cristim merged 1 commit into
mainfrom
fix/1480-signing-key-create-before-destroy

Conversation

@cristim

@cristim cristim commented Jul 27, 2026 •

Copy link
Copy Markdown
Member

Follow-up to #1480

#1480 migrated aws_kms_key.signing (OIDC issuer signing key) from RSA_2048 to ECC_NIST_P256 (ES256). KMS cannot change a key spec in place, so Terraform must replace the key.

Terraform's default destroy-before-create would ScheduleKeyDeletion on the live signing key (immediately unusable for kms:Sign) before the new EC key exists — briefly breaking OIDC client-assertion JWT minting (Azure AD federation) on deploy.

Change

Adds lifecycle { create_before_destroy = true } to aws_kms_key.signing so the new key is created and the alias cut over before the old key is scheduled for deletion. The alias updates in place (no replace), so it needs no change.

Scoped to AWS only: GCP crypto keys are versioned (algorithm change adds a version, no gap) and Azure Key Vault soft-delete keeps the old key recoverable.

terraform fmt + validate clean.

Refs #1480, #1496.

Summary by CodeRabbit

  • Bug Fixes
    • Improved signing-key replacement behavior to help prevent temporary interruptions when keys are migrated.
    • Reduced the risk of failures in OIDC client-assertion JWT generation during signing-key updates.

@cristim cristim added triaged Item has been triaged priority/p2 Backlog-worthy severity/medium Moderate harm urgency/this-sprint Within the current sprint impact/internal Team-internal only effort/xs Trivial / one-liner type/chore Maintenance / non-user-visible labels Jul 27, 2026
@cristim

cristim commented Jul 27, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 33 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 55b328ff-42f3-4567-bf7a-d844b3d36af6

📥 Commits

Reviewing files that changed from the base of the PR and between 2fb8e80 and b01b9d6.

📒 Files selected for processing (1)
  • terraform/modules/compute/aws/lambda/signing-key.tf
📝 Walkthrough

Walkthrough

Terraform now creates a replacement signing KMS key before destroying the existing key by enabling create_before_destroy on aws_kms_key.signing.

Changes

KMS Signing Key Replacement

Layer / File(s) Summary
Configure signing key replacement
terraform/modules/compute/aws/lambda/signing-key.tf
The signing KMS key resource now uses a lifecycle rule with create_before_destroy = true.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • LeanerCloud/CUDly#1496: Updates deploy-role permissions for KMS key lifecycle and tagging operations associated with signing key replacement.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly reflects the main change: enabling create_before_destroy on the OIDC signing key in AWS.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/1480-signing-key-create-before-destroy

Comment @coderabbitai help to get the list of available commands.

…1480)

#1480 migrated aws_kms_key.signing from RSA_2048 to ECC_NIST_P256, which forces
a KMS key replacement. Terraform's default destroy-before-create schedules the
live signing key for deletion (immediately unusable for kms:Sign) before the new
EC key exists, briefly breaking OIDC client-assertion JWT minting on deploy.

Add lifecycle { create_before_destroy = true } so the new key is created and the
alias cut over before the old key is scheduled for deletion. GCP crypto keys are
versioned (no gap) and Azure Key Vault soft-delete keeps the old key recoverable,
so only the AWS KMS key needs this.
@cristim
cristim force-pushed the fix/1480-signing-key-create-before-destroy branch from 2fb8e80 to b01b9d6 Compare July 27, 2026 10:33
@cristim

cristim commented Jul 27, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cristim

cristim commented Jul 27, 2026

Copy link
Copy Markdown
Member Author

✅ Ready for human merge.

Held for your merge (infra / security-adjacent).

@cristim
cristim merged commit b83c5d1 into main Jul 27, 2026
19 checks passed
@cristim
cristim deleted the fix/1480-signing-key-create-before-destroy branch July 27, 2026 11:09
cristim added a commit that referenced this pull request Jul 27, 2026
…rant (#1514)

Follow-up to #1496. That PR fixed KMSMutateTaggedOnly in policy_compute.tf
to use StringEqualsIgnoreCase after discovering the OIDC signing key is
tagged Project=cudly (lowercase, from local.common_tags / var.project_name),
which overrides the provider default_tags value CUDly and never matched a
case-sensitive StringEquals "CUDly".

KMSReadTaggedOnly in policy_compute_b.tf gates the deploy role's only grant
for kms:GetKeyPolicy on the same tag with case-sensitive StringEquals, so it
does not match the signing key either. The AWS provider reads the key policy
on every aws_kms_key refresh, so the deploy role hits AccessDenied on
kms:GetKeyPolicy when refreshing or replacing the signing key, blocking the
RSA to ECC replace that #1496/#1512 exist to support.

Switch KMSReadTaggedOnly to StringEqualsIgnoreCase for consistency with
KMSMutateTaggedOnly. terraform validate passes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/xs Trivial / one-liner impact/internal Team-internal only priority/p2 Backlog-worthy severity/medium Moderate harm triaged Item has been triaged type/chore Maintenance / non-user-visible urgency/this-sprint Within the current sprint

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant