Sub topic 15
Cross-account access and multi-Region replication
This chapter assumes you have read the earlier chapters on IAM least-privilege access and KMS encryption. You should know the difference between an identity policy and a resource-based policy, and how a KMS key policy works.
Real systems rarely stay in one account or one Region. A shared-services account may own a database credential that several workload accounts need. A disaster-recovery plan may require the same secret to exist in a second Region. Each service handles these needs differently:
- Secrets Manager shares secrets through resource policies and replicates them natively.
- Parameter Store shares only Advanced-tier parameters, through AWS Resource Access Manager (RAM).
- Parameter Store has no built-in replication.
How cross-account access is evaluated
Within one account, an identity policy or a resource policy alone is enough to allow an action. Across accounts, AWS requires both sides to allow it:
- The owning account must grant access to the caller.
- The caller's account must allow its own role to make the call.
- For encrypted values, the KMS key policy must also allow the caller to decrypt.
If any of the three is missing, the request fails with AccessDeniedException.
Sharing a Secrets Manager secret
The secret must be encrypted with a customer managed KMS key. The default aws/secretsmanager key is an AWS managed key, and its policy cannot be edited, so no other account can use it. If an existing secret uses the default key, update it to a customer managed key before you share it.
Step 1: attach a resource policy to the secret
Run these commands in the owner account (111122223333). Save this as policy.json:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::444455556666:role/app-role"
},
"Action": "secretsmanager:GetSecretValue",
"Resource": "*"
}
]
}In a secret's resource policy, "Resource": "*" means the secret the policy is attached to. Apply it:
aws secretsmanager put-resource-policy \
--secret-id myapp/prod/db \
--resource-policy file://policy.json \
--block-public-policy--block-public-policy makes Secrets Manager reject the policy if it would grant broad public access. It validates the policy before saving it, so it is a useful safety check.
Step 2: allow the principal in the KMS key policy
Add a statement like this to the key policy in the owner account:
{
"Sid": "AllowConsumerRoleToDecrypt",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::444455556666:role/app-role"
},
"Action": ["kms:Decrypt", "kms:DescribeKey"],
"Resource": "*"
}Step 3: allow the call in the consumer account
The consumer role's identity policy must name the owner account's secret and key by ARN:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "secretsmanager:GetSecretValue",
"Resource": "arn:aws:secretsmanager:us-east-1:111122223333:secret:myapp/prod/db-AbCdEf"
},
{
"Effect": "Allow",
"Action": "kms:Decrypt",
"Resource": "arn:aws:kms:us-east-1:111122223333:key/EXAMPLE-KEY-ID"
}
]
}Step 4: call with the full ARN
A secret's friendly name is only unique inside its own account. For that reason a cross-account caller must pass the complete ARN, including the six-character suffix that Secrets Manager adds. A name alone resolves in the caller's own account and fails.
import json
import boto3
secrets = boto3.client("secretsmanager", region_name="us-east-1")
secret_arn = (
"arn:aws:secretsmanager:us-east-1:111122223333:"
"secret:myapp/prod/db-AbCdEf"
)
response = secrets.get_secret_value(SecretId=secret_arn)
creds = json.loads(response["SecretString"])
print(creds["username"])Pass the ARN to the application through configuration, such as an environment variable, so the code does not need to know the account ID.
Sharing Parameter Store parameters
Parameter Store does not use resource policies on parameters. To share across accounts, use AWS RAM:
- Only Advanced-tier parameters can be shared. If a Standard parameter needs sharing, change its tier to Advanced. You cannot change an Advanced parameter back to Standard.
- A SecureString parameter must use a customer managed KMS key. The key policy must allow the consumer account, in the same way as for secrets.
- The consumer reads the parameter by its full ARN, not by its path name.
The sharing flow has these steps:
- In the owner account, create a resource share in RAM that contains the parameter ARN and names the consumer account or organization.
- In the consumer account, accept the share. Accepting is automatic if both accounts are in the same AWS Organization and sharing is enabled for it.
- The consumer's role needs an identity policy allowing
ssm:GetParameteron the parameter's ARN. For a SecureString it also needskms:Decrypton the owner's key.
A consumer call looks like this:
aws ssm get-parameter \
--name arn:aws:ssm:us-east-1:111122223333:parameter/shared/prod/api-endpoint \
--with-decryptionReplicating secrets across Regions
Secrets Manager can replicate a secret to other Regions. This supports disaster recovery and lets applications in several Regions read locally with low latency. Each replica has these properties:
- It has the same name as the primary secret, but a different ARN, because the Region is part of the ARN.
- It is read-only. Changes, including rotation, happen on the primary, and Secrets Manager copies the new versions and staging labels to the replicas.
- It is encrypted with a KMS key in its own Region. If you do not choose one, Secrets Manager uses
aws/secretsmanagerin that Region.
Add replicas when you create the secret, or later:
aws secretsmanager replicate-secret-to-regions \
--secret-id myapp/prod/db \
--add-replica-regions Region=us-west-2,KmsKeyId=alias/myapp-westAn application in us-west-2 can then call get_secret_value(SecretId="myapp/prod/db") against its local endpoint. No cross-Region call is needed.
To fail over, promote the replica to an independent secret:
aws secretsmanager stop-replication-to-replica \
--secret-id myapp/prod/db \
--region us-west-2After promotion, the secret is writable and no longer follows the old primary. You can then configure its own rotation. Promotion does not reverse itself, so re-create replication deliberately after the original Region recovers.
Parameter Store has no replication
Parameter Store parameters live in one Region. To keep copies in other Regions, use one of these approaches:
- Deploy the same parameters to each Region from one CloudFormation template or pipeline. This is the simplest option, and it keeps your source of truth in version control.
- Subscribe an EventBridge rule to
Parameter Store Changeevents (sourceaws.ssm). It can invoke a Lambda function that copies the new value to the other Region. This copies SecureString values through your own code, so the function needskms:Decryptandkms:Encrypton the keys involved.
Choosing an approach
| Need | Secrets Manager | Parameter Store |
|---|---|---|
| Share with another account | Resource policy plus KMS key policy | RAM share, Advanced tier only |
| Caller identifies value by | Full ARN | Full ARN |
| Key requirement | Customer managed key | Customer managed key for SecureString |
| Multi-Region copies | Built-in replicas | Your own automation |
| Failover | Promote replica | Write to the local copy |
Common mistakes
- Passing the secret name instead of the ARN. The call resolves in the caller's account and returns
ResourceNotFoundException. - Granting only one side. A resource policy without a matching identity policy, or the reverse, still denies the request.
- Forgetting the replica's key. The consumer in the second Region needs
kms:Decrypton the replica's key, not the primary's key. - Assuming a replica can be edited. Writes to a replica fail. Always update the primary.
Replicas are billed as separate secrets, and each Region's GetSecretValue calls are billed in that Region. Include replica counts when you estimate cost.
Exercise
A role in account 444455556666 calls getsecretvalue with SecretId="myapp/prod/db" for a secret owned by account 111122223333. The secret has a correct resource policy and uses a customer managed key whose policy allows the role. The call still fails. What is the likely cause and the fix?
Show answer
The caller used the secret's name, which resolves only in the caller's own account. Pass the full secret ARN (arn:aws:secretsmanager:us-east-1:111122223333:secret:myapp/prod/db-AbCdEf). Also confirm the role's own identity policy allows GetSecretValue on that ARN and kms:Decrypt on the key.
Exercise
Your team keeps a Standard-tier SecureString parameter encrypted with alias/aws/ssm and wants to share it with another account through RAM. List the changes needed.
Show answer
Change the parameter to the Advanced tier, because only Advanced parameters can be shared. Re-encrypt it with a customer managed KMS key, because an AWS managed key cannot be shared. Allow the consumer account in that key's policy. Create the RAM share and accept it in the consumer account. The consumer role then reads the parameter by ARN, with an identity policy allowing ssm:GetParameter and kms:Decrypt.
Exercise
A secret is replicated from us-east-1 to us-west-2. You change its value in us-west-2 and get an error. Why, and what do you do?
Show answer
A replica is read-only, so changes must be made on the primary secret in us-east-1, and Secrets Manager copies them to the replica. If the primary Region is lost and you need a writable copy, promote the replica with stop-replication-to-replica.