Sub topic 10
Customer managed policy references and per-account consistency
This chapter assumes you know how a permission set, a group, and an account combine into an assignment, and that you have run provision-permission-set before. It also assumes you can read IAM policy JSON and CloudFormation. Here you will learn how a permission set can point at an IAM policy that you manage yourself, and what you must do to keep that policy consistent in every account.
What a customer managed policy reference is
A permission set can contain three kinds of policies: AWS managed, inline, and customer managed. An inline policy is stored inside the permission set, so Identity Center copies it to every account. A customer managed policy works differently. The permission set stores only a reference, which is a name and an optional path. Identity Center does not create the policy and never copies its contents.
When Identity Center provisions the permission set into an account, it creates the role there. It then looks for an IAM policy in that same account with the referenced name and path, and attaches it to the role. The policy document is whatever exists in that account at that moment.
This design has two consequences:
- The policy must already exist in every target account before provisioning. This includes the management account if you assign to it.
- Identity Center does not check that the policy content matches across accounts. Consistency is your job.
| Policy type | Stored in | Content identical in all accounts? |
|---|---|---|
| AWS managed | AWS | Yes, AWS maintains it |
| Inline | The permission set | Yes, copied on provisioning |
| Customer managed reference | Each target account's IAM | Only if you make it so |
Why use references instead of inline policies
Inline policies are limited in size (the aggregate of inline policy text in a permission set is capped), and any edit must be re-provisioned everywhere. A reference lets the same permission set grant slightly different access per account, such as a policy that names account-specific bucket ARNs. It also lets teams that own an account's IAM content manage their own policy without touching the permission set.
The trade-off is drift. Inline policies cannot differ between accounts. Referenced policies can, and nothing warns you when they do.
Naming rules
The reference matches on two fields:
Nameis case-sensitive and must match the IAM policy name exactly.Pathdefaults to/. If the policy was created under/team-a/, the reference must say/team-a/. A wrong path counts as a missing policy.
Identity Center also lets you use a customer managed policy as the permissions boundary of a permission set. The same rules apply: the boundary policy must exist by name and path in each target account.
Step 1: create the policy in every account
The most reliable way to put the same policy in many accounts is CloudFormation StackSets with service-managed permissions, targeted at OUs. New accounts that join the OU get the stack automatically, so the policy exists before anyone is assigned.
AWSTemplateFormatVersion: '2010-09-09'
Description: Policy referenced by the ReadOnlyAuditor permission set
Resources:
AuditorsExtraAccess:
Type: AWS::IAM::ManagedPolicy
Properties:
ManagedPolicyName: AuditorsExtraAccess
Path: /
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- s3:GetObject
- s3:ListBucket
Resource: '*'Service-managed StackSets do not deploy to the management account. If you assign the permission set there, create the policy in that account separately, for example with a regular stack.
Step 2: reference the policy from the permission set
Use the CLI to attach the reference. Note that you pass a name and path, not an ARN.
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=AuditorsExtraAccess,Path=/To use a customer managed policy as the boundary instead, call the boundary command:
aws sso-admin put-permissions-boundary-to-permission-set \
--instance-arn "$INSTANCE_ARN" \
--permission-set-arn "$PS_ARN" \
--permissions-boundary 'CustomerManagedPolicyReference={Name=AuditorsBoundary,Path=/}'A permission set has at most one permissions boundary. It can be either an AWS managed policy or a customer managed reference, not both.
Verify what the permission set holds:
aws sso-admin list-customer-managed-policy-references-in-permission-set \
--instance-arn "$INSTANCE_ARN" \
--permission-set-arn "$PS_ARN"The same configuration in CloudFormation uses the CustomerManagedPolicyReferences property:
Resources:
ReadOnlyAuditor:
Type: AWS::SSO::PermissionSet
Properties:
InstanceArn: !Ref InstanceArn
Name: ReadOnlyAuditor
SessionDuration: PT4H
ManagedPolicies:
- arn:aws:iam::aws:policy/ReadOnlyAccess
CustomerManagedPolicyReferences:
- Name: AuditorsExtraAccess
Path: /Step 3: provision and check
Attaching a reference to a permission set that is already assigned does not change the roles. Re-provision, then read the status of the request:
REQUEST_ID=$(aws sso-admin provision-permission-set \
--instance-arn "$INSTANCE_ARN" \
--permission-set-arn "$PS_ARN" \
--target-type ALL_PROVISIONED_ACCOUNTS \
--query 'PermissionSetProvisioningStatus.RequestId' --output text)
aws sso-admin describe-permission-set-provisioning-status \
--instance-arn "$INSTANCE_ARN" \
--provisioning-request-id "$REQUEST_ID" \
--query 'PermissionSetProvisioningStatus.[Status,FailureReason]'The status is IN_PROGRESS, SUCCEEDED, or FAILED. A failure with a reason such as a policy not being found usually means one account lacks the policy, or its name or path differs.
Keeping policies consistent
A referenced policy can be edited in one account by someone with IAM rights, and the role in that account then changes without any Identity Center event. The permission set still looks identical in the console. Three habits reduce the risk:
- Deploy the policy only through the StackSet and restrict
iam:CreatePolicyVersionon it, using a service control policy that exempts the StackSet execution role. - Run drift detection on the StackSet on a schedule.
- Compare policy versions across accounts when investigating a "works in account A, denied in account B" report.
Changing the policy through the StackSet takes effect on the next API call, because the role points at the policy and not at a copy. You do not need to re-provision the permission set after editing the policy document. You do need to re-provision after changing which policies the permission set references.
Common errors
- The policy exists, but under a different path. Check the
Pathof both the policy and the reference. - The management account was assigned but was skipped by the StackSet, so provisioning fails only there.
- A new account in the OU was assigned before its stack finished creating.
- The attached-policy count for a role is over its limit once AWS managed and customer managed references are combined. Check the permission set and IAM quotas in your Region before adding more references.
- A reference was changed but not re-provisioned, so roles still hold the old attachment.
Exercise
A permission set references the customer managed policy AuditorsExtraAccess with path /. Provisioning succeeds in 40 accounts and fails in one new account. Give the two most likely causes and the single check that tells you which one applies.
Show answer
Either the policy does not exist in that account yet (for example the StackSet had not reached the new account), or it exists under a different name or path. Run aws iam get-policy --policy-arn arn:aws:iam::<account-id>:policy/AuditorsExtraAccess in that account. A NoSuchEntity error means the policy is missing or has a different path or name. If it returns, compare the name and path with the reference, then re-run provision-permission-set after fixing it.
Exercise
You edit the policy document of AuditorsExtraAccess in a StackSet. Do you need to call provision-permission-set for the change to reach users?
Show answer
No. Roles reference the policy in each account, so the new document applies as soon as the StackSet update completes. You only re-provision when you change which policies the permission set references.