Skip to content
IAM Policy Generator

IAM policy example: trust one EKS service account, with a least privilege rewrite

Lets one Kubernetes service account in an EKS cluster assume a role through the cluster's OIDC provider. The original matches every service account in every namespace with a wildcard. The rewrite pins the namespace and account name and checks the audience.

Open the workbench ยท All examples

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AnyServiceAccount",
      "Effect": "Allow",
      "Principal": {
        "Federated": "arn:aws:iam::111122223333:oidc-provider/oidc.eks.us-west-2.amazonaws.com/id/EXAMPLED539D4633E53DE1B71EXAMPLE"
      },
      "Action": "sts:AssumeRoleWithWebIdentity",
      "Condition": {
        "StringLike": {
          "oidc.eks.us-west-2.amazonaws.com/id/EXAMPLED539D4633E53DE1B71EXAMPLE:sub": "system:serviceaccount:*:*"
        }
      }
    }
  ]
}

What it allows

  • Allows any service account in any namespace of the cluster to assume the role.

What it allows

  1. Allow Federated arn:aws:iam::111122223333:oidc-provider/oidc.eks.us-west-2.amazonaws.com/id/EXAMPLED539D4633E53DE1B71EXAMPLE to sts:AssumeRoleWithWebIdentity when oidc.eks.us-west-2.amazonaws.com/id/EXAMPLED539D4633E53DE1B71EXAMPLE:sub StringLike system:serviceaccount:*:*.

    Action or patternActionsAccess levels
    sts:AssumeRoleWithWebIdentity1Write 1

Checks

No flags from the six checks.

Any pod in the cluster can obtain this role by running under a service account in any namespace.

Least privilege rewrite

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "OneServiceAccount",
      "Effect": "Allow",
      "Principal": {
        "Federated": "arn:aws:iam::111122223333:oidc-provider/oidc.eks.us-west-2.amazonaws.com/id/EXAMPLED539D4633E53DE1B71EXAMPLE"
      },
      "Action": "sts:AssumeRoleWithWebIdentity",
      "Condition": {
        "StringEquals": {
          "oidc.eks.us-west-2.amazonaws.com/id/EXAMPLED539D4633E53DE1B71EXAMPLE:sub": "system:serviceaccount:default:my-service-account",
          "oidc.eks.us-west-2.amazonaws.com/id/EXAMPLED539D4633E53DE1B71EXAMPLE:aud": "sts.amazonaws.com"
        }
      }
    }
  ]
}

The rewrite uses an exact subject for one namespace and service account and adds the audience check. Other pods cannot assume the role.

What it allows

  1. Allow Federated arn:aws:iam::111122223333:oidc-provider/oidc.eks.us-west-2.amazonaws.com/id/EXAMPLED539D4633E53DE1B71EXAMPLE to sts:AssumeRoleWithWebIdentity when oidc.eks.us-west-2.amazonaws.com/id/EXAMPLED539D4633E53DE1B71EXAMPLE:sub StringEquals system:serviceaccount:default:my-service-account and oidc.eks.us-west-2.amazonaws.com/id/EXAMPLED539D4633E53DE1B71EXAMPLE:aud StringEquals sts.amazonaws.com.

    Action or patternActionsAccess levels
    sts:AssumeRoleWithWebIdentity1Write 1

Checks

No flags from the six checks.

Sources

  1. Amazon EKS User Guide: IAM roles for service accounts, read 16 Nov 2026
  2. IAM User Guide: create a role for OpenID Connect federation, read 16 Nov 2026
  3. AWS Service Authorization Reference, programmatic access (fetched 16 Nov 2026), read 16 Nov 2026

Last reviewed 16 Nov 2026.