Sub topic 10
Customer managed policy references and per-account consistency
This chapter assumes you know how permission sets attach policies and how account assignments provision roles. It covers what changes when a permission set points at a policy that lives inside each account.
What a reference is
An AWS managed policy has the same ARN everywhere. An inline policy is stored in the permission set itself. A customer managed policy reference is different. It stores only a name and a path, not an ARN and not the policy document.
When Identity Center provisions the permission set into an account, it creates the role there. It then attaches the IAM policy in that account that matches the name and path. The document can therefore differ per account, for example a different S3 bucket list in each one.
Creating and attaching a reference
First create the policy in the target account. The name and path must match exactly.
aws iam create-policy \
--policy-name TeamBucketAccess \
--path / \
--policy-document '{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":"s3:GetObject","Resource":"arn:aws:s3:::example-team-bucket/*"}]}'Then, from the management or delegated administrator account, attach the reference and re-provision:
aws sso-admin attach-customer-managed-policy-reference-to-permission-set \
--instance-arn "$INSTANCE_ARN" \
--permission-set-arn "$PS_ARN" \
--customer-managed-policy-reference Name=TeamBucketAccess,Path=/
aws sso-admin provision-permission-set \
--instance-arn "$INSTANCE_ARN" \
--permission-set-arn "$PS_ARN" \
--target-type ALL_PROVISIONED_ACCOUNTSKeeping accounts consistent
Identity Center does not create, copy, or check these policies for you. Consistency is your job.
- Deploy the policy to every target account with CloudFormation StackSets or another pipeline, before you create the assignment.
- Include the management account if the permission set is assigned there.
- Treat the name and path as a contract. Renaming a policy in one account breaks the reference in that account only.
- Use the same pipeline to change policy documents. Accounts can then drift in content only when you intend it.
Common errors
| Symptom | Likely cause |
|---|---|
| Assignment or provisioning fails in one account | The policy with that name and path does not exist there |
| Works in most accounts, fails in a few | The policy was never deployed to the newer accounts |
| Policy exists but is not found | The path differs, for example `/team/` instead of `/` |
| Users in one account have more access than expected | The policy document in that account differs from the others |
Exercise
A permission set references a customer managed policy named AuditExtras with path /. Provisioning succeeds in 40 accounts and fails in 2 newly created accounts. What is the most likely cause, and what is the fix?
Show answer
The two new accounts have no IAM policy named AuditExtras at path /. Create it there, for example by adding the accounts to the StackSet that deploys it, and then run provision-permission-set again.