Sub topic 6
Who Can Talk to the Cluster
This chapter assumes you know what an IAM role and an ARN are. It also assumes you can read a Kubernetes Role and RoleBinding, and that you have a running cluster named demo from the earlier chapter. Replace the account ID 111122223333 with your own.
Two separate checks
Every request to the Kubernetes API server on EKS passes two checks.
- Authentication answers "who are you?" On EKS, the answer is always an AWS IAM principal, meaning an IAM role or IAM user.
- Authorization answers "what may you do?" This is decided either by Kubernetes RBAC (role-based access control) or by an EKS access policy, which is a managed set of RBAC-like permissions.
IAM permissions such as eks:DescribeCluster control who can manage the cluster through the AWS API. They do not control what someone can do inside the cluster. A principal with AdministratorAccess in IAM still gets Unauthorized from kubectl until the cluster knows about it.
When you run kubectl, the kubeconfig written by aws eks update-kubeconfig calls aws eks get-token. That command produces a short-lived token, which is a pre-signed STS GetCallerIdentity request. EKS validates the token with IAM and gets the caller's ARN. It then looks that ARN up in the cluster's access configuration.
Authentication modes
A cluster has one of three authentication modes.
| Mode | Where the IAM-to-Kubernetes mapping lives |
|---|---|
| `CONFIG_MAP` | Only the `aws-auth` ConfigMap in `kube-system` (legacy) |
| `API_AND_CONFIG_MAP` | Access entries and `aws-auth`. Access entries win if both match |
| `API` | Only access entries, managed through the EKS API |
You can move forward through the modes but not back. Once you switch to API, you cannot return to API_AND_CONFIG_MAP. A cluster you create with a current eksctl or console default normally starts in API_AND_CONFIG_MAP or API. To migrate an older cluster:
aws eks update-cluster-config \
--name demo \
--access-config authenticationMode=API_AND_CONFIG_MAP
aws eks describe-cluster --name demo \
--query 'cluster.accessConfig'Before you move to API, create an access entry for every principal listed in aws-auth. Do this first, because anything missing loses access when the ConfigMap stops being read.
Access entries
An access entry links one IAM principal to the cluster. It can carry two kinds of authorization data: access policies and Kubernetes groups. List what already exists:
aws eks list-access-entries --cluster-name demoOn a cluster created by a current tool, you will see an entry for the creator and one for the node role. The creator entry exists only if bootstrapClusterCreatorAdminPermissions was true at creation. Before access entries existed, the creator got a hidden system:masters binding that appeared in no configuration. Today that permission is a visible entry that you can remove.
The entry for the node IAM role has type EC2_LINUX. It lets kubelets register nodes. Do not delete it, or new nodes will fail to join. Entries for people or CI systems use the default type STANDARD.
Create an entry for a platform team role:
aws eks create-access-entry \
--cluster-name demo \
--principal-arn arn:aws:iam::111122223333:role/platform-admins \
--type STANDARDUse the role ARN, not the ARN of an assumed-role session. Prefer roles over IAM users. Roles give you temporary credentials and work with federation and IAM Identity Center.
Access policies
An access policy is an EKS-managed permission set that you attach to an entry. It has an access scope: the whole cluster, or a list of namespaces. The main policies are:
| Policy | Permissions |
|---|---|
| `AmazonEKSClusterAdminPolicy` | Full control of all resources, like `cluster-admin` |
| `AmazonEKSAdminPolicy` | Most resources within namespaces, including RBAC objects in them |
| `AmazonEKSEditPolicy` | Read and write most namespaced resources |
| `AmazonEKSViewPolicy` | Read-only on most namespaced resources |
Give the platform role cluster-wide admin rights:
aws eks associate-access-policy \
--cluster-name demo \
--principal-arn arn:aws:iam::111122223333:role/platform-admins \
--policy-arn arn:aws:eks::aws:cluster-access-policy/AmazonEKSClusterAdminPolicy \
--access-scope type=clusterGive a developer role read-only access in one namespace:
aws eks create-access-entry \
--cluster-name demo \
--principal-arn arn:aws:iam::111122223333:role/developers
aws eks associate-access-policy \
--cluster-name demo \
--principal-arn arn:aws:iam::111122223333:role/developers \
--policy-arn arn:aws:eks::aws:cluster-access-policy/AmazonEKSViewPolicy \
--access-scope type=namespace,namespaces=defaultYou can declare the same thing in your eksctl config, which keeps access under version control:
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig
metadata:
name: demo
region: us-east-1
accessConfig:
authenticationMode: API_AND_CONFIG_MAP
accessEntries:
- principalARN: arn:aws:iam::111122223333:role/developers
accessPolicies:
- policyARN: arn:aws:eks::aws:cluster-access-policy/AmazonEKSViewPolicy
accessScope:
type: namespace
namespaces:
- defaultCustom permissions with Kubernetes groups
The managed policies are coarse. For finer control, such as "read pods and logs in dev but nothing else," put the principal in a Kubernetes group and write normal RBAC against that group.
aws eks create-access-entry \
--cluster-name demo \
--principal-arn arn:aws:iam::111122223333:role/qa-team \
--kubernetes-groups qa-readersThen bind the group inside the cluster:
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: pod-reader
namespace: dev
rules:
- apiGroups: [""]
resources: ["pods", "pods/log"]
verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: qa-pod-reader
namespace: dev
subjects:
- kind: Group
name: qa-readers
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: pod-reader
apiGroup: rbac.authorization.k8s.ioGroup names must not start with system:. EKS reserves that prefix. The group has no meaning until a binding references it, so a typo in the name silently grants nothing.
Verifying access
Switch to the principal's credentials, then check who you are and what you can do:
aws sts get-caller-identity
aws eks update-kubeconfig --name demo --region us-east-1
kubectl auth can-i list pods --namespace dev
kubectl auth can-i delete deployments --namespace devkubectl auth can-i prints yes or no. Admins can add --as impersonation, but impersonation tests RBAC rules only. It does not test the IAM and access entry path.
The legacy aws-auth ConfigMap
Older clusters map principals in the aws-auth ConfigMap, under mapRoles and mapUsers. It has three weaknesses that access entries fix:
- A syntax error in the YAML can lock everyone out, including administrators.
- Role ARNs must be written without their path, so an SSO role needs the
aws-reserved/sso.amazonaws.com/segment removed. This is a common mistake. - Changes need Kubernetes access. If you lose it, you cannot repair the mapping. Access entries are managed through the AWS API, so any IAM principal with
eks:CreateAccessEntrycan restore access.
Diagnosing failures
| Symptom | Likely cause | Fix |
|---|---|---|
| `You must be logged in to the server (Unauthorized)` | No access entry or `aws-auth` match for this ARN, or wrong AWS profile | Run `aws sts get-caller-identity`, then create an entry for that role ARN |
| `Error from server (Forbidden)` | Authenticated, but no policy or RBAC rule allows the verb | Associate a policy or fix the group binding |
| `Unable to connect to the server: dial tcp` or timeout | Endpoint access setting or network path, not identity | Check the cluster endpoint's public or private access and CIDR allow list |
| Access works for one namespace only | Policy scope is `namespace` | Widen the scope or add another policy |
Exercise
A developer assumes the developers role and runs kubectl get pods -n dev. The role has an access entry with AmazonEKSViewPolicy scoped to the default namespace. Which error do they get, 401 Unauthorized or 403 Forbidden, and what is the smallest change that fixes it?
Show answer
They get 403 Forbidden. The request authenticates, because the access entry exists, but the policy scope does not include dev. The smallest fix is to associate the view policy again with --access-scope type=namespace,namespaces=default,dev, or to add a second association scoped to dev.
Exercise
Why might you give an access entry a Kubernetes group instead of an access policy, and what must you create inside the cluster for it to take effect?
Show answer
A group lets you write exact RBAC rules, such as read-only access to pods and logs in one namespace, which the managed policies cannot express. The group grants nothing until you create a Role or ClusterRole and a RoleBinding or ClusterRoleBinding that names the group as a subject.