Repository navigation
Closed
Description
Problem
Every agentcore deploy creates a new KMS key and calls SetTokenVaultCMKCommand to re-configure the account-level token-vault, even if a key already exists from a previous deploy. The old key is never deleted, disabled, or reused.
This means:
- Each deploy accumulates an orphaned KMS key (~$1/month per key)
remove all+deploy(teardown) destroys the CloudFormation stack but does not delete the KMS key- The
identityKmsKeyArnstored indeployed-state.jsonis lost when the target entry is cleaned up during teardown - Concurrent deploys to the same account race on
SetTokenVaultCMKCommand, causing"conflicting request during InitializeMutation"errors
Root Cause
setupTokenVaultKms in src/cli/operations/deploy/pre-deploy-identity.ts:91-121 unconditionally creates a new KMS key via CreateKeyCommand and sets it on the token-vault. It does not:
- Check if a KMS key already exists in deployed state and reuse it
- Clean up old keys when creating a new one
The teardown flow in src/cli/operations/deploy/teardown.ts does not call ScheduleKeyDeletion or DisableKey for the stored identityKmsKeyArn.
Suggested Fix
- Reuse existing key: Before creating a new KMS key, check
deployed-state.jsonfor an existingidentityKmsKeyArn. If present and the key is still valid (enabled), reuse it instead of creating a new one. - Cleanup on teardown: When performing a teardown deploy, schedule deletion of the KMS key stored in
identityKmsKeyArnusingScheduleKeyDeletionCommand. - Handle concurrent deploys: The
SetTokenVaultCMKCommandcall should retry with backoff when it receives a mutation-in-progress error.
Impact
- Every user accumulates ~$1/month in orphaned KMS keys per deploy
- CI/CD pipelines and e2e test suites that deploy frequently create many orphaned keys
- Concurrent deploys fail due to KMS mutation race condition
Relevant Files
src/cli/operations/deploy/pre-deploy-identity.ts—setupTokenVaultKms()src/cli/operations/identity/api-key-credential-provider.ts—setTokenVaultKmsKey()src/cli/operations/deploy/teardown.ts—performStackTeardown()src/schema/schemas/deployed-state.ts—identityKmsKeyArnfield
Metadata
Metadata
Assignees
Labels
No labels
Activity
mostman1043 commentedon Jun 5, 2026
This regressed in
0.17.0— requesting reopen.The reuse path from this issue's fix appears to be gone again:
agentcore deployis back to minting a fresh"AgentCore Identity encryption key for <project>"on every run and callingSetTokenVaultCMK, instead of reusing the existing token-vault key fromdeployed-state.json.Version boundary (reproduced):
0.13.0–0.16.00.17.0(2026-06-02)Confirmed via CloudTrail:
CreateKeyby the deploy principal occurs only on0.17.0runs — every0.16.0-and-earlier deploy over the prior month created zero keys. The0.17.0release notes list no intended KMS/credentials change, so this looks unintended.Secondary failure for least-privilege CI roles: when the deploy role is scoped without
kms:CreateGrant(it never needed it pre-0.17.0), the key is created and orphaned, then the configure step hard-fails the whole deploy:So on
0.17.0a scoped role can't deploy at all, and a broadly-scoped one silently leaks a key per deploy.Workaround: pin
@aws/[email protected].