Sub topic 8
Assigning a group and a permission set to an account
This chapter assumes you know what a permission set is and how groups exist in your identity source. You should also be comfortable running aws sso-admin commands from the management account or a delegated administrator account.
The assignment triple
An account assignment connects three things:
- A principal, which is a user or a group.
- A permission set.
- A target, which is one AWS account.
Identity Center stores each triple as one assignment. When a member of the group signs in, they see that account and permission set in the access portal. Assigning groups rather than individual users keeps the number of assignments small and makes offboarding a directory change.
Creating one assignment
Look up the identifiers first. The API takes IDs and ARNs, not names.
INSTANCE_ARN=$(aws sso-admin list-instances --query 'Instances[0].InstanceArn' --output text)
IDENTITY_STORE_ID=$(aws sso-admin list-instances --query 'Instances[0].IdentityStoreId' --output text)
# Replace with the ARN returned when you created the permission set
PS_ARN="arn:aws:sso:::permissionSet/ssoins-EXAMPLE/ps-EXAMPLE"
GROUP_ID=$(aws identitystore get-group-id \
--identity-store-id "$IDENTITY_STORE_ID" \
--alternate-identifier '{"UniqueAttribute":{"AttributePath":"DisplayName","AttributeValue":"Auditors"}}' \
--query 'GroupId' --output text)
aws sso-admin create-account-assignment \
--instance-arn "$INSTANCE_ARN" \
--target-id 111122223333 \
--target-type AWS_ACCOUNT \
--permission-set-arn "$PS_ARN" \
--principal-type GROUP \
--principal-id "$GROUP_ID"The call is asynchronous. It returns a status object with a RequestId and a status of IN_PROGRESS. Pass that ID to describe-account-assignment-creation-status and wait for SUCCEEDED or FAILED. A FailureReason field explains failures.
Assigning to an OU
You cannot assign to an OU. The --target-type value is always AWS_ACCOUNT. To cover an OU, list its accounts and loop over them.
for ACCOUNT_ID in $(aws organizations list-accounts-for-parent \
--parent-id ou-xxxx-xxxxxxxx \
--query 'Accounts[?Status==`ACTIVE`].Id' --output text); do
aws sso-admin create-account-assignment \
--instance-arn "$INSTANCE_ARN" \
--target-id "$ACCOUNT_ID" \
--target-type AWS_ACCOUNT \
--permission-set-arn "$PS_ARN" \
--principal-type GROUP \
--principal-id "$GROUP_ID"
doneTwo limits apply. list-accounts-for-parent returns only accounts directly under that OU, not accounts in child OUs. A new account created later gets nothing until you run the loop again or automate it.
What the assignment does in the account
The first assignment of a permission set to an account provisions a role there. Its name starts with AWSReservedSSO_ followed by the permission set name and a generated suffix. The role's trust policy lets Identity Center assume it for users who hold the assignment. Later chapters cover the role in detail.
Checking and removing assignments
To see who has a permission set in an account, run this:
aws sso-admin list-account-assignments \
--instance-arn "$INSTANCE_ARN" \
--account-id 111122223333 \
--permission-set-arn "$PS_ARN"delete-account-assignment takes the same arguments as the create call. Removing the last assignment of a permission set from an account also removes its role there.
Common errors
| Symptom | Likely cause |
|---|---|
| `AccessDeniedException` | You are not in the management or delegated administrator account. |
| Status `FAILED` | The permission set, group ID, or account ID is wrong, or the account is suspended. |
| Group members see no account | The assignment is still `IN_PROGRESS`, or the user is not in the group. |
Exercise
A teammate runs create-account-assignment with --target-id set to an OU ID and gets an error. Why, and how do you give the Auditors group access to every account in that OU?
Show answer
Assignments target accounts only, so --target-type must be AWS_ACCOUNT and the target must be an account ID. List the active accounts directly under the OU with aws organizations list-accounts-for-parent and create one assignment per account. Accounts in child OUs need their own listing.