# ABAC: tag-based access control policy example

IAM policy examples · Updated 17 November 2026

**Short answer:** ABAC compares a tag on the caller (aws:PrincipalTag/project) with a tag on the resource (aws:ResourceTag/project). Allow actions when they match, require the tag on create with aws:RequestTag, and stop people changing the tag. One policy then covers every project; new projects need tags, not new policies.

## The policy

```
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "UseOwnProjectSecrets",
      "Effect": "Allow",
      "Action": [
        "secretsmanager:GetSecretValue",
        "secretsmanager:DescribeSecret",
        "secretsmanager:PutSecretValue",
        "secretsmanager:UpdateSecret"
      ],
      "Resource": "*",
      "Condition": {
        "StringEquals": {
          "aws:ResourceTag/project": "${aws:PrincipalTag/project}"
        }
      }
    },
    {
      "Sid": "CreateOnlyTaggedForOwnProject",
      "Effect": "Allow",
      "Action": [
        "secretsmanager:CreateSecret",
        "secretsmanager:TagResource"
      ],
      "Resource": "*",
      "Condition": {
        "StringEquals": {
          "aws:RequestTag/project": "${aws:PrincipalTag/project}"
        },
        "ForAllValues:StringEquals": {
          "aws:TagKeys": [
            "project",
            "owner"
          ]
        }
      }
    },
    {
      "Sid": "NeverRemoveProjectTag",
      "Effect": "Deny",
      "Action": "secretsmanager:UntagResource",
      "Resource": "*",
      "Condition": {
        "ForAnyValue:StringEquals": {
          "aws:TagKeys": [
            "project"
          ]
        }
      }
    }
  ]
}
```

## The three tag keys

| Key | Refers to | Used for |
|---|---|---|
| `aws:PrincipalTag/project` | Tag on the calling role, user or session | Who is asking |
| `aws:ResourceTag/project` | Tag already on the resource | Acting on existing resources |
| `aws:RequestTag/project` | Tag being set in this request | Creating or tagging |
| `aws:TagKeys` | All tag keys in the request | Limiting which keys may be set |

**UseOwnProjectSecrets** lets a role tagged `project=payments` read and update secrets tagged `project=payments`. **CreateOnlyTaggedForOwnProject** means new secrets must carry the caller's project tag and may only use the `project` and `owner` keys. **NeverRemoveProjectTag** stops anyone untagging a secret to get it out of a project's control.

## Where principal tags come from

- **IAM roles and users**: tag them directly.
- **IAM Identity Center**: turn on *attributes for access control* and map a user attribute (such as department) to a session tag.
- **SAML or OIDC federation**: the identity provider passes session tags; the role's trust policy must allow `sts:TagSession`.

```
aws iam tag-role --role-name payments-dev --tags Key=project,Value=payments
aws iam put-role-policy --role-name payments-dev \
  --policy-name abac-secrets --policy-document file://abac.json
```

## Caveats

- **Not every action supports tag conditions.** Check the "Condition keys" column for each action in the Service Authorization Reference. List actions (like `ListSecrets`) generally don't, and need a separate statement on `"*"`.
- **Whoever can change tags controls access.** Restrict `iam:TagRole` and `iam:UntagRole` as tightly as you would restrict attaching policies.
- **Missing tags**: a principal without a `project` tag makes the variable unresolvable, so the allow doesn't match. That fails safe.

## Test it before rolling out

Create two roles tagged with different projects and one secret per project. Each role should be able to read its own secret and get AccessDenied on the other. Then try creating a secret without a tag, and with the other project's tag; both should fail.

```
aws iam simulate-principal-policy \
  --policy-source-arn arn:aws:iam::123456789012:role/payments-dev \
  --action-names secretsmanager:GetSecretValue \
  --resource-arns arn:aws:secretsmanager:eu-west-2:123456789012:secret:orders/api-key-AbC123 \
  --context-entries ContextKeyName=aws:ResourceTag/project,ContextKeyValues=orders,ContextKeyType=string
```

The simulator doesn't read real tags, so pass the resource tag as a context entry; expect `implicitDeny`.

## Common mistakes

- **Using `aws:ResourceTag` on create**: the resource has no tags yet. Use `aws:RequestTag`.
- **Using `ForAnyValue` where you meant `ForAllValues`** on `aws:TagKeys`, which lets extra keys through.
- **Tag values with different case** (`Payments` vs `payments`): `StringEquals` is case-sensitive for values.

## Questions

### What is the difference between ABAC and RBAC in AWS?

RBAC grants permissions per role, so each new project needs new policies. ABAC grants by matching tags on callers and resources, so one policy covers new projects automatically.

### Which AWS services support ABAC?

Many, but not every action. The Service Authorization Reference lists aws:ResourceTag and aws:RequestTag support per action; check it for each action you rely on.

## When this happens away from your desk

Tags that drive permissions also make resources easier to find. Filtering by project tag on a phone is a quick way to see what a team owns when something of theirs alerts.

[About the CloudConsole app](https://cloudconsole.dev/aws-console-app) · [Download on the App Store](https://apps.apple.com/app/cloudconsole-for-aws/id6835419710)

## Sources

- [Define permissions based on attributes with ABAC authorization](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction_attribute-based-access-control.html)
- [AWS global condition context keys](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html)

## Related

- [IAM policy: start and stop EC2 instances by tag](https://cloudconsole.dev/iam/ec2-start-stop-by-tag)
- [IAM policy: read one secret from Secrets Manager](https://cloudconsole.dev/iam/secrets-manager-read-one-secret)
- [IAM permissions boundary: let developers create roles safely](https://cloudconsole.dev/iam/permissions-boundary)
- [How to set up IAM Identity Center](https://cloudconsole.dev/how-to/set-up-iam-identity-center)
- [IAM policy: read and write one DynamoDB table](https://cloudconsole.dev/iam/dynamodb-one-table)
- [IAM role trust policy: examples and how it works](https://cloudconsole.dev/iam/assume-role-trust-policy)

---

Source: https://cloudconsole.dev/iam/abac-tags

CloudConsole is an independent iPhone and Android app for Amazon Web Services by Cloudconcur Ltd. It is not affiliated with Amazon Web Services.
