Sub topic 15
Cross-account access and multi-Region replication
This chapter assumes you know IAM roles and policies, KMS key policies, and the secret and parameter commands from earlier chapters. It covers how to let another AWS account read a value, and how to make a value available in a second Region.
Cross-account access
An identity policy in one account cannot grant access to a resource in another account on its own. Both sides must agree: the resource owner allows the outside principal, and the caller's account allows its own principal to make the request.
| Service | How the owner shares | Caller needs |
|---|---|---|
| Secrets Manager | Resource-based policy on the secret | Identity policy plus the secret's full ARN |
| Parameter Store | Share an advanced-tier parameter with AWS Resource Access Manager (RAM) | Identity policy plus the parameter's full ARN |
Standard-tier parameters cannot be shared. If you need to share a parameter, move it to the advanced tier first.
Sharing a secret
Account 111122223333 owns the secret. This policy lets a role in account 444455556666 read it:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {"AWS": "arn:aws:iam::444455556666:role/reporting-app"},
"Action": "secretsmanager:GetSecretValue",
"Resource": "*"
}
]
}In a resource policy, "Resource": "*" means the secret the policy is attached to. Attach it from the owner account:
aws secretsmanager put-resource-policy \
--secret-id myapp/prod/db \
--resource-policy file://policy.jsonThe caller must then pass the full ARN as SecretId. A bare name resolves in the caller's own account and fails.
The KMS requirement
The AWS managed key aws/secretsmanager cannot be shared across accounts. Encrypt the secret with a customer managed key instead. Then do two things:
- Add the other account's role to the key policy with
kms:Decrypt. - Give that role
kms:Decrypton the key in its own identity policy.
The same rule applies to a shared SecureString parameter. Without it, the call fails with an AccessDeniedException that mentions KMS.
Multi-Region replication
Secrets Manager can keep read-only copies of a secret in other Regions. This supports disaster recovery and lets applications read locally with low latency. You choose a KMS key for each replica Region, because keys do not cross Regions.
aws secretsmanager replicate-secret-to-regions \
--secret-id myapp/prod/db \
--add-replica-regions Region=us-west-2,KmsKeyId=alias/myapp-usw2The replica keeps the same name, but its ARN contains the replica Region. Updates and rotations on the primary copy flow to the replicas automatically. If the primary Region becomes unavailable, you can promote a replica to a standalone secret that accepts writes.
Parameter Store has no built-in replication. To keep two Regions in step, subscribe to parameter change events in EventBridge and run a function that writes the new value to the other Region.
Exercise
A role in account B calls GetSecretValue with the secret's name. The secret in account A has a correct resource policy and uses the aws/secretsmanager key. List the two problems.
Show answer
First, the caller must use the secret's full ARN, because a name resolves in the caller's own account. Second, the AWS managed key aws/secretsmanager cannot be shared, so the secret must be re-encrypted with a customer managed key that allows the role to decrypt.