Repository navigation
fix(iac/aws): case-insensitive tag match on kms:GetKeyPolicy deploy grant - #1514
Conversation
…rant 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.
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
Important Review skippedNo new commits to review since the last review. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe ChangesKMS tag policy
Estimated code review effort: 1 (Trivial) | ~5 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
What
Adversarial-review follow-up to #1496 and #1512 (OIDC signing-key RSA->ECC replace). Switches
KMSReadTaggedOnlyinpolicy_compute_b.tffrom case-sensitiveStringEquals "CUDly"toStringEqualsIgnoreCase.Why
#1496 discovered that the OIDC signing key is tagged
Project=cudly(lowercase): the tag comes fromlocal.common_tags(Project = var.project_name, default"cudly"), which overrides the providerdefault_tagsvalue"CUDly"for that resource. It fixedKMSMutateTaggedOnly(kms:ScheduleKeyDeletion etc.) toStringEqualsIgnoreCaseaccordingly.KMSReadTaggedOnlygates the deploy role's only grant forkms:GetKeyPolicyon the same tag, but was left as case-sensitiveStringEquals "CUDly", so by the identical reasoning it never matches the signing key. The AWS provider reads the key policy (kms:GetKeyPolicy) on everyaws_kms_keyrefresh, so once both bootstrap policies are applied the deploy role hitsAccessDenied: kms:GetKeyPolicywhen refreshing/replacing the signing key, blocking the exact ECC replace #1496/#1512 exist to enable.This was found by adversarially reviewing both merged PRs: the mutate path was fixed but the read path (
GetKeyPolicy) carries the same latent case mismatch.Confidence
GetKeyPolicygrant are confirmed by inspection (tag chain traced tolocal.common_tags->var.project_name = "cudly";GetKeyPolicyappears only inKMSReadTaggedOnly).GetKeyPolicyduringaws_kms_keyrefresh (standard behaviour); precise fatality is best confirmed against live AWS. The fix is safe and internally consistent regardless.Scope of the review (other probes)
create_before_destroyon the key only (fix(iac/aws): create_before_destroy on OIDC signing key (follow-up to #1480) #1512): sound — the alias and IAM role-policy are updated in place (UpdateAlias / PutRolePolicy), not replaced, so no cycle and no need for CBD on them; new key is created and the alias repointed before the old key is scheduled for deletion.kidviasync.Oncewith no invalidation, so warm Lambda containers can serve a stale JWKS during any signing-key replacement (transient verification mismatch until recycled). Pre-existing app-code behaviour, not introduced by these PRs, out of scope here.Projecttag is lowercasecudly.Test
terraform validatepasses onci-cd-permissions.Closes nothing; filed as a follow-up fix.
Summary by CodeRabbit