fix: add KMS IAM policy to the aurora-postgres-server permissions role - #6
Merged
Conversation
Release 0.0.2 moved Aurora storage encryption to a customer managed key (5f71cc7, AVD-AWS-0079): deployment/main.tf creates aws_kms_key.aurora and aws_kms_alias.aurora and feeds the key ARN into aws_rds_cluster.main. The AssumeRole permissions role was never updated to match, so the agent's KMS calls are denied: the service cannot finish its first apply, and a destroy leaves the key and its alias behind. Adds <prefix>-rds-kms-policy plus its role attachment, gated by the same local.iam_create flag as the rest of the policies in the module: - KmsCreateAndList: CreateKey, TagResource, ListKeys and ListAliases on "*", since there is no key ARN to scope to before CreateKey returns. - KmsManageKey: describe, key policy, rotation, tags and lifecycle, scoped to keys in the current account. - KmsCreateGrantForRds: CreateGrant, ListGrants and RevokeGrant gated on kms:GrantIsForAWSResource, which RDS requires to attach the key to the cluster. - KmsManageAlias: alias create, update and delete on alias/nullplatform-aurora-* plus the target key, since the alias APIs authorize against both. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
timossileandro
force-pushed
the
feat/kms-iam-policies
branch
from
August 24, 2026 19:52
de84fb1 to
44e5a7e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a
<prefix>-rds-kms-policyIAM policy — and its role attachment — to theaurora-postgres-serverAssumeRole permissions role inspecs/requirements/aws/main.tf.Why
0.0.2moved Aurora storage encryption to a customer managed key(5f71cc7, AVD-AWS-0079):
deployment/main.tfnow createsaws_kms_key.aurora+aws_kms_alias.auroraand feeds the key ARN intoaws_rds_cluster.main. Thepermissions role that the agent assumes was never updated to match, so the KMS
calls in the deployment plan are denied — the service can't complete its first
apply, and a destroy leaves the key and alias behind.
What the policy grants
kms:CreateKey,TagResource,ListKeys,ListAliases. Resource*because there is no key ARN to scope to beforeCreateKeyreturns.(including
ScheduleKeyDeletionandCancelKeyDeletion), scoped to keys inthe current account via
data.aws_caller_identity.current.account_id.CreateGrant/ListGrants/RevokeGrant,gated on
kms:GrantIsForAWSResource = true. RDS creates a grant on the CMKwhen it attaches the key to the cluster; without this, cluster creation fails
with a KMS access error even though the key already exists.
CreateAlias/UpdateAlias/DeleteAliasonalias/nullplatform-aurora-*(the alias patterndeployment/main.tfuses)plus the key resource, since the alias APIs authorize against both the alias
and its target key.
Every resource is behind
count = local.iam_create ? 1 : 0, in line with theother policies in the module, so accounts that bring their own role are
unaffected.
Scope and impact
aurora-postgres-server/specs/requirements/aws/main.tf.No changes to
deployment/, workflows, or specs;aurora-postgres-dbisuntouched.
specs/requirements/awsto pick up thenew policy and attachment. The role name and trust policy are unchanged, so
nothing needs to be re-registered on the nullplatform side
(
identity-access-controlprovider and selector stay the same).RDS, security group and Secrets Manager policies in this module.
Verification
tofu fmt -checkandtofu validateinaurora-postgres-server/specs/requirements/aws.tofu planon a test account: the plan adds oneaws_iam_policyand oneaws_iam_role_policy_attachment, with no changes to the existing role orpolicies.
aurora-postgres-serverservice on an account whoserole comes from this module and confirm the cluster comes up with the CMK,
then delete it and confirm the key is scheduled for deletion and the alias is
removed.