Sub topic 6
Attaching policies: managed, inline, and permissions boundaries
This chapter assumes you know IAM policy JSON, the difference between an identity policy and a boundary, and how to run AWS CLI commands. It also assumes you have created a permission set before. Here you will learn which kinds of policy a permission set can carry, how they combine, and what to check after you change them.
The three policy slots
A permission set is a template. When you assign it to an account, IAM Identity Center creates an IAM role in that account and copies the template's policies onto the role. A permission set has three places to put policies:
| Slot | What it holds | Where the policy lives | How many |
|---|---|---|---|
| AWS managed policies | Policies that AWS maintains, such as `ReadOnlyAccess` or job function policies | AWS | Several, up to the IAM managed policies per role quota |
| Customer managed policy references | A name and path that point to a policy in each target account | Each target account | Counted in the same limit as AWS managed policies |
| Inline policy | One JSON document stored in the permission set | The permission set itself | One |
| Permissions boundary | One managed policy, either AWS managed or a customer managed reference | AWS or each target account | One |
The first two slots and the inline policy grant permissions. The boundary grants nothing. It only limits what the other policies can allow.
How the policies combine
The role's effective permissions follow normal IAM evaluation:
- An explicit
Denyin any policy wins. - Otherwise, the request must be allowed by at least one identity policy (managed or inline).
- If a boundary is set, the request must also be allowed by the boundary.
Service control policies (SCPs) from AWS Organizations apply on top of this. A request needs an allow from the identity policies, the boundary (if any), and the SCPs.
Managed policies
Attaching an AWS managed policy is the cheapest option. AWS updates these policies, so a permission set that uses ReadOnlyAccess picks up new services without any work from you. The same applies to the policies' content in every account where the permission set is provisioned.
The trade-off is control. You cannot edit an AWS managed policy. If PowerUserAccess is slightly too broad, you add a Deny in the inline policy or set a boundary.
Job function policies such as job-function/NetworkAdministrator use a path in the ARN. Pass the full ARN, including the path, or the call fails.
INSTANCE_ARN=$(aws sso-admin list-instances --query 'Instances[0].InstanceArn' --output text)
PS_ARN=$(aws sso-admin create-permission-set \
--instance-arn "$INSTANCE_ARN" \
--name DeveloperAccess \
--description "Developer access with guardrails" \
--session-duration PT8H \
--query 'PermissionSet.PermissionSetArn' --output text)
aws sso-admin attach-managed-policy-to-permission-set \
--instance-arn "$INSTANCE_ARN" \
--permission-set-arn "$PS_ARN" \
--managed-policy-arn arn:aws:iam::aws:policy/PowerUserAccessThe inline policy
A permission set holds one inline policy. It is a good place for small, specific rules: a few extra allowed actions, or a guardrail Deny. Because it is stored in the permission set, Identity Center writes the same document into every account. You never maintain per-account copies.
This example denies all actions outside two Regions, except for global services:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "DenyOutsideApprovedRegions",
"Effect": "Deny",
"NotAction": ["iam:*", "organizations:*", "sts:*", "support:*"],
"Resource": "*",
"Condition": {
"StringNotEquals": {
"aws:RequestedRegion": ["us-east-1", "eu-west-1"]
}
}
}
]
}Save it as region-guardrail.json, then attach it:
aws sso-admin put-inline-policy-to-permission-set \
--instance-arn "$INSTANCE_ARN" \
--permission-set-arn "$PS_ARN" \
--inline-policy file://region-guardrail.jsonput-inline-policy-to-permission-set replaces the whole document. It does not merge. To change one statement, edit the file and put it again.
Permissions boundaries
A boundary sets a ceiling. Set one on a permission set when the people using it can attach broad policies themselves, or when you want a hard limit that does not depend on what other policies are added later.
You can use either kind of managed policy as the boundary:
# An AWS managed policy as the boundary
aws sso-admin put-permissions-boundary-to-permission-set \
--instance-arn "$INSTANCE_ARN" \
--permission-set-arn "$PS_ARN" \
--permissions-boundary '{"ManagedPolicyArn":"arn:aws:iam::aws:policy/PowerUserAccess"}'
# Or a customer managed policy that must exist in every target account
aws sso-admin put-permissions-boundary-to-permission-set \
--instance-arn "$INSTANCE_ARN" \
--permission-set-arn "$PS_ARN" \
--permissions-boundary '{"CustomerManagedPolicyReference":{"Name":"DeveloperBoundary","Path":"/"}}'A permission set has at most one boundary. A second call replaces the first.
A common mistake is to set a boundary and expect it to grant access. If you attach only a boundary, the role can do nothing. Another is to forget that the boundary also limits the inline policy. If your inline policy allows iam:CreateRole but the boundary does not, the call is denied.
Applying changes
Editing a permission set does not change roles that already exist. After you attach, detach, or replace any policy on a permission set that is already assigned, provision it again:
aws sso-admin provision-permission-set \
--instance-arn "$INSTANCE_ARN" \
--permission-set-arn "$PS_ARN" \
--target-type ALL_PROVISIONED_ACCOUNTSThe call is asynchronous. It returns a request ID, and you can check progress with describe-permission-set-provisioning-status. The console shows an "out of sync" notice on the permission set until you re-provision.
Verifying what landed in an account
Identity Center creates the role in each account under the path /aws-reserved/sso.amazonaws.com/, with a name that begins AWSReservedSSO_ followed by the permission set name and a suffix. Sign in to a target account and inspect it:
ROLE_NAME=$(aws iam list-roles \
--path-prefix /aws-reserved/sso.amazonaws.com/ \
--query "Roles[?starts_with(RoleName, 'AWSReservedSSO_DeveloperAccess_')].RoleName | [0]" \
--output text)
aws iam list-attached-role-policies --role-name "$ROLE_NAME"
aws iam list-role-policies --role-name "$ROLE_NAME"
aws iam get-role --role-name "$ROLE_NAME" --query 'Role.PermissionsBoundary'You should see the managed policies and any customer managed policy from the first command. The inline policy appears by name in the second command, and the boundary appears in the third. If any of them is missing, the role is out of date and needs provisioning.
Choosing a slot
- Use an AWS managed policy when one matches the job and you want AWS to keep it current.
- Use a customer managed reference when the policy is long, shared between permission sets, or needs its own review process.
- Use the inline policy for a small rule that belongs only to this permission set, especially a guardrail
Deny. - Use a boundary when you need a ceiling that other policy changes cannot raise.
Exercise
A permission set has AdministratorAccess attached and a permissions boundary that allows only Amazon S3 actions. A user signs in with it and tries to launch an EC2 instance. What happens, and what would you check if the user also reports that an S3 change you made to the inline policy does not work?
Show answer
The EC2 call is denied. AdministratorAccess allows it, but the boundary does not, and a request must be allowed by both. For the inline policy problem, check whether the permission set was provisioned again after the edit, since existing roles are not updated until you run provision-permission-set. Then use aws iam list-role-policies in the target account to confirm the inline policy on the AWSReservedSSO_ role matches your change.