Scenario: You are the DevSecOps Architect. You need to grant a newly hired developer (eks-developer) read-only access strictly to the dev-team namespace in your EKS cluster. They should not be able to view or modify anything in the default or kube-system namespaces.
Prerequisites
- An AWS Account with administrative privileges.
aws-cliinstalled and configured.kubectlinstalled.eksctlinstalled (we will use this to quickly spin up a test cluster).
Step 1: Provision the EKS Lab Cluster
First, let’s spin up a small, single-node cluster. The IAM user/role you use to run this command will automatically become the implicit system:masters administrator.
# Create a basic EKS cluster (This takes about 15 minutes)
eksctl create cluster \
--name eks-auth-lab \
--region us-east-1 \
--nodes 1 \
--node-type t3.mediumVerify your admin access once it finishes:
kubectl get nodesStep 2: Create the “Developer” IAM Identity
We need an external AWS identity to map. For this lab, we will create an IAM User (though in production, you would map an IAM Role assumed via AWS SSO).
# 1. Create the IAM User
aws iam create-user --user-name eks-developer
# 2. Create Access Keys for the user
aws iam create-access-key --user-name eks-developerImportant: Note the AccessKeyId and SecretAccessKey from the JSON output.
Configure a new local AWS profile for this developer:
aws configure --profile eks-developer
# Paste the Access Key ID
# Paste the Secret Access Key
# Default region name: us-east-1
# Default output format: jsonGet your AWS Account ID and note the developer’s full ARN (you will need this in Step 4):
aws sts get-caller-identity --profile eks-developer
# The ARN will look like: arn:aws:iam::111122223333:user/eks-developerStep 3: Create the Kubernetes RBAC (The Locks)
Now, acting as the Cluster Admin (your default AWS profile), create the namespace, the Role, and the RoleBinding inside Kubernetes.
1. Create the Namespace:
kubectl create namespace dev-team2. Create the Role (role.yaml): This defines what actions are allowed.
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: dev-team
name: dev-reader
rules:
- apiGroups: [""]
resources: ["pods", "services"]
verbs: ["get", "watch", "list"]Apply it: kubectl apply -f role.yaml
3. Create the RoleBinding (rolebinding.yaml): This binds the Role to a specific Kubernetes group called dev-team-group.
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: read-pods-binding
namespace: dev-team
subjects:
- kind: Group
name: dev-team-group # This is the badge color we will hand out!
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: dev-reader
apiGroup: rbac.authorization.k8s.ioApply it: kubectl apply -f rolebinding.yaml
Step 4: The Translation (EKS Access Management API)
At this moment, the IAM user exists, and the Kubernetes RBAC exists, but they are completely disconnected. Let’s bridge them using the modern EKS Access API.
We are going to tell EKS: “If anyone authenticates as arn:aws:iam::111122223333:user/eks-developer, hand them the Kubernetes group badge called dev-team-group.”
# Replace <YOUR_ACCOUNT_ID> with your actual AWS Account ID
aws eks create-access-entry \
--cluster-name eks-auth-lab \
--principal-arn arn:aws:iam::<YOUR_ACCOUNT_ID>:user/eks-developer \
--kubernetes-groups dev-team-groupNote: Because we are using the modern API, we do not need to touch the dangerous aws-auth ConfigMap!
Step 5: Test and Verify the Flow
Now, put on your “Developer” hat. You will attempt to access the cluster using the eks-developer AWS profile.
1. Update the local kubeconfig as the developer:
aws eks update-kubeconfig \
--name eks-auth-lab \
--region us-east-1 \
--profile eks-developer2. Test 1: Authorized Access (Success)
Attempt to list pods in the assigned namespace.
kubectl get pods -n dev-teamResult: No resources found in dev-team namespace. (Success! You authenticated, and RBAC authorized you to look, even if nothing is there yet).
3. Test 2: Unauthorized Namespace (403 Forbidden)
Attempt to look at the default namespace.
kubectl get pods -n defaultResult: Error from server (Forbidden): pods is forbidden: User "..." cannot list resource "pods" in API group "" in the namespace "default" (Success! Authentication passed, but Kubernetes RBAC successfully blocked you).
4. Test 3: Unauthorized Action (403 Forbidden)
Attempt to delete a pod in the allowed namespace.
kubectl delete pod fake-pod -n dev-teamResult:Error from server (Forbidden): pods "fake-pod" is forbidden: User "..." cannot delete resource "pods" in API group "" in the namespace "dev-team"(Success! RBAC proves that read-only means read-only).
Step 6: Lab Cleanup
To avoid AWS charges, destroy the resources you created. Switch back to your administrator terminal/profile to run these.
# Delete the cluster (Takes ~10 minutes)
eksctl delete cluster --name eks-auth-lab --region us-east-1
# Delete the IAM Developer User and Keys
aws iam delete-access-key --access-key-id <YOUR_ACCESS_KEY> --user-name eks-developer
aws iam delete-user --user-name eks-developerThis lab perfectly complements your theoretical article by allowing your readers to experience the “Airport Border Control vs. Conference Room Locks” analogy in a real terminal.