Sub topic 15
Attribute-based access control with session tags
This chapter assumes you can read IAM policy JSON, know that IAM tags exist, and have already created a permission set and assigned it to a group. ABAC (attribute-based access control) lets one permission set cover many teams. The permission set matches a user's attribute against a resource's tag, so you don't need a separate permission set per team.
How the pieces connect
Identity Center reads attributes such as Department from your identity source. When a user signs in to an account, Identity Center passes the attributes you selected as session tags. IAM exposes them in policies as aws:PrincipalTag/<key>.
Step 1: Enable attributes for access control
Mapping is configured once per Identity Center instance. It applies to every permission set, not to one. This command maps the Department key to the directory's enterprise.department field:
INSTANCE_ARN=$(aws sso-admin list-instances --query 'Instances[0].InstanceArn' --output text)
aws sso-admin create-instance-access-control-attribute-configuration \
--instance-arn "$INSTANCE_ARN" \
--instance-access-control-attribute-configuration '{
"AccessControlAttributes": [
{"Key": "Department", "Value": {"Source": ["${path:enterprise.department}"]}}
]
}'The Key is the tag name your policies will use. The Source is the attribute path in your identity source. With an external identity provider, the source can be an attribute that the provider sends through SCIM sync or SAML assertions.
Step 2: Write the policy
Add this inline policy to the permission set. It lets a user start and stop only the EC2 instances whose Department tag equals the user's own department.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": ["ec2:StartInstances", "ec2:StopInstances"],
"Resource": "*",
"Condition": {
"StringEquals": {
"ec2:ResourceTag/Department": "${aws:PrincipalTag/Department}"
}
}
}
]
}Because the match uses tags and not account IDs or ARNs, the same permission set works in every account that is assigned it.
Step 3: Re-provision
After you edit a permission set that is already assigned, push the change to the roles in each account:
aws sso-admin provision-permission-set \
--instance-arn "$INSTANCE_ARN" \
--permission-set-arn "$PS_ARN" \
--target-type ALL_PROVISIONED_ACCOUNTSCommon errors
- Tag values never match. Tag keys are case-insensitive in
PrincipalTag, but values are compared case-sensitively withStringEquals.Financeandfinancedo not match. - The attribute is empty. If the user has no value for the source attribute, the session has no tag. The condition then fails and access is denied. Check the user's profile in the identity source.
- Old sessions keep old tags. Tags are fixed when the session starts. After you change a user's attribute, the user must sign in again.
- Resources are untagged. The policy only matches resources that carry the tag. Enforce tagging with tag policies or service control policies.
- Some actions ignore resource tags. Not every action supports
ec2:ResourceTag. For example,ec2:RunInstancesneedsaws:RequestTagconditions. Check the service's authorization reference before relying on a condition.
Exercise
A user moves from Finance to Marketing, and the identity source is updated. The user is still working in a session started yesterday and can still stop Finance-tagged instances. Why, and what fixes it?
Show answer
Session tags are fixed when the session starts, so the existing session still carries Department=Finance. The user must sign out and sign in again to get a session with Department=Marketing.