AWS eks: Document IAM namespace scoping for EKS access policies
Summary
Adds a new "Restrict namespace scope with IAM policies" section explaining that the eks:namespaces IAM condition key is evaluated as a literal string while the cluster treats the value as a wildcard pattern, so a Deny for kube-system does not block kube-*, *, or cluster access scopes. Includes allowlist-based Allow policy examples (ForAllValues:StringLike plus Null=false) and Deny-based examples (ForAnyValue:StringNotLike plus Null=true) for principals with broader permissions, plus a warning to use only the * wildcard.
Security assessment
The added text documents a concrete authorization weakness: a denylist on eks:namespaces can be bypassed because IAM compares the literal string (e.g. kube-*) while the cluster expands it as a wildcard to reach kube-system, and a cluster access scope omits the key entirely so the condition never matches. The guidance prescribes allowlist policies with ForAllValues:StringLike and Null=false, and Deny statements with ForAnyValue:StringNotLike and Null=true to prevent principals from widening their namespace scope, which is IAM permission-boundary style hardening for EKS access entries.
Evidence
* If you restrict namespaces with the `eks:namespaces` IAM condition key, then use an allowlist instead of a denylist. IAM evaluates the namespace value in your request as a literal string. As a result, a `Deny` for `kube-system` doesn’t block `kube-*`, `\*`, or a `cluster` access scope. For more information, see Restrict namespace scope with IAM policies.
Diff
diff --git a/eks/latest/userguide/access-policies.md b/eks/latest/userguide/access-policies.md index 1207889..6b7e567 100644 --- a//eks/latest/userguide/access-policies.md +++ b//eks/latest/userguide/access-policies.md @@ -7 +7 @@ -AWS Management ConsoleAWS CLI +AWS Management ConsoleAWS CLIRestrict namespace scope with IAM policies @@ -29,0 +30,2 @@ Before associating access policies with access entries, consider the following r + * If you restrict namespaces with the `eks:namespaces` IAM condition key, then use an allowlist instead of a denylist. IAM evaluates the namespace value in your request as a literal string. As a result, a `Deny` for `kube-system` doesn’t block `kube-*`, `\*`, or a `cluster` access scope. For more information, see Restrict namespace scope with IAM policies. + @@ -158,0 +161,90 @@ To list available access policies, see [Review access policy permissions](./acce +## Restrict namespace scope with IAM policies + +Before you begin, make sure that you understand how the `eks:namespaces` condition key is evaluated, and identify the namespaces that each IAM principal needs. + +When you request an access scope, IAM evaluates each namespace value in your request as a literal string, but your cluster treats that same value as a wildcard pattern. As a result, a `Deny` for a single namespace doesn’t block the wildcards that match it, as shown in the following table. + +Namespace value in your request | Blocked by a `Deny` for `kube-system`? | Reason +---|---|--- +`kube-system` | Yes | The value in your request exactly matches the value in the policy. +`kube-\*` | No | IAM compares the literal string `kube-*`, which doesn’t equal `kube-system`. Your cluster then expands `kube-\*` to include `kube-system`. +`\*` | No | IAM compares the literal string `*`, which doesn’t equal `kube-system`. Your cluster then expands `\*` to all namespaces. +None, for a `cluster` access scope | No | Your request includes no namespaces, so the `eks:namespaces` key is absent and the condition doesn’t match. + +Don’t use a denylist. Instead, allow only the values that you want the principal to use. In the following IAM policy example, replace `team-a` and `team-a-\*` with the namespaces that you want to allow: + + + { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Allow", + "Action": "eks:AssociateAccessPolicy", + "Resource": "*", + "Condition": { + "ForAllValues:StringLike": { + "eks:namespaces": ["team-a", "team-a-*"] + }, + "Null": { + "eks:namespaces": "false" + } + } + } + ] + } + +The preceding policy uses the following elements: + + * Namespace values – Replace `team-a` and `team-a-*` with the namespaces that you want to allow. Use `StringLike` instead of `StringEquals` so that `team-a-\*` matches every namespace that begins with `team-a-`, such as `team-a-dev`. If you use `StringEquals`, IAM matches only the literal value `team-a-\*`. + + * `ForAllValues:StringLike` – Requires every namespace in your request to match one of the values in the policy. If your request includes even one other namespace, IAM denies it. + + * `Null` condition set to `false` – Requires your request to include at least one namespace. This blocks `cluster` access scope requests, which include no namespaces. + + + + +Because IAM evaluates the value in your request literally, a principal can’t widen its scope by requesting a broader wildcard. A value such as `*` or `k\*` doesn’t match the pattern `team-a-\*`. Any value that does match must begin with `team-a-`, so your cluster can only expand it to namespaces under that prefix. + +Important + +Use only the `*` wildcard character in your policy values. A policy value of `team-?` also allows a request for `team-\*`, which your cluster expands to `team-a`, `team-b`, `team-a-dev`, and `team-b-prod`. + +If the principal has broader permissions, such as `eks:*`, then use `Deny` statements so that other policies can’t override the restriction. The following IAM policy example denies any request that includes a namespace outside of `team-a` and `team-a-\*`, and denies `cluster` access scope requests: + + + { + "Version": "2012-10-17", + "Statement": [ + { + "Effect": "Deny", + "Action": "eks:AssociateAccessPolicy", + "Resource": "*", + "Condition": { + "ForAnyValue:StringNotLike": { + "eks:namespaces": ["team-a", "team-a-*"] + } + } + }, + { + "Effect": "Deny", + "Action": "eks:AssociateAccessPolicy", + "Resource": "*", + "Condition": { + "Null": { + "eks:namespaces": "true" + } + } + } + ] + } + +The preceding policy uses the following elements: + + * `ForAnyValue:StringNotLike` – Denies your request if any namespace in it doesn’t match one of the values in the policy. + + * `Null` condition set to `true` – Denies your request if it includes no namespaces. You need a second statement for this condition, because the first statement doesn’t apply when the `eks:namespaces` key is absent from your request. + + + +