This document outlines Role-Based Access Control (RBAC) implementation in Amazon Elastic Kubernetes Service (EKS), focusing on the configuration example provided and its practical use cases.
Prerequisites
- AWS CLI installed and configured
- kubectl installed
- EKS cluster created and kubeconfig configured
- IAM user/role with appropriate EKS permissions
Configuration Example Analysis
1. Namespace-scoped Role (pod-reader)
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: rbac-test
name: pod-reader
rules:
- apiGroups: [""] # Core API group (Pods, Services, etc.)
resources: ["pods"]
verbs: ["list","get","watch"]
- apiGroups: ["extensions","apps"]
resources: ["deployments"]
verbs: ["get", "list", "watch"]Key Points:
- Namespace:
rbac-test - Grants read-only access to pods and deployments
- Supports both legacy (
extensions) and current (apps) API groups
2. RoleBinding (read-pods)
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: read-pods
namespace: rbac-test
subjects:
- kind: User
name: dev-user
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: pod-reader
apiGroup: rbac.authorization.k8s.ioKey Points:
- Binds the
pod-readerrole to userdev-user - Effective only in
rbac-testnamespace
3. AWS Auth ConfigMap
apiVersion: v1
kind: ConfigMap
metadata:
name: aws-auth
namespace: kube-system
data:
mapUsers: |
- userarn: arn:aws:iam::158311564815:user/dev-user
username: dev-userKey Points:
- Maps AWS IAM user to Kubernetes user
- Stored in
kube-systemnamespace - Required for EKS IAM integration
Implementation Steps
Step 1: Create Namespace
kubectl create namespace rbac-testStep 2: Apply RBAC Configuration
- Create Role and RoleBinding:
kubectl apply -f rbac-config.yaml -n rbac-test- Verify Role creation:
kubectl get role -n rbac-test
kubectl describe role pod-reader -n rbac-test- Verify RoleBinding:
kubectl get rolebinding -n rbac-test
kubectl describe rolebinding read-pods -n rbac-testStep 3: Configure AWS Authentication
- Update aws-auth ConfigMap:
kubectl apply -f aws-auth-configmap.yaml -n kube-system- Alternatively, edit existing ConfigMap:
kubectl edit configmap aws-auth -n kube-systemStep 4: Test Access
- As dev-user, test pod access:
# This assumes you've configured AWS credentials for dev-user
kubectl get pods -n rbac-test- Test deployment access:
kubectl get deployments -n rbac-test- Verify restricted access (should fail):
kubectl get pods -n default # Should fail - no access to default namespace
kubectl delete pod <pod-name> -n rbac-test # Should fail - no delete permissionCommon Use Cases
Use Case 1: Development Team Access
Scenario: Development team needs read-only access to their namespace for debugging and monitoring.
Configuration:
# dev-team-role.yaml
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: dev-team-namespace
name: dev-team-viewer
rules:
- apiGroups: ["", "apps", "batch"]
resources: ["pods", "deployments", "services", "jobs", "configmaps"]
verbs: ["get", "list", "watch"]Use Case 2: CI/CD Pipeline Service Account
Scenario: Jenkins/GitLab Runner needs deployment permissions in specific namespaces.
Configuration:
# cicd-role.yaml
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: staging
name: cicd-deployer
rules:
- apiGroups: ["apps"]
resources: ["deployments"]
verbs: ["get", "list", "watch", "create", "update", "patch"]
- apiGroups: [""]
resources: ["pods", "pods/log"]
verbs: ["get", "list", "watch"]Use Case 3: Cross-Namespace Admin
Scenario: Team lead needs admin access across multiple project namespaces.
Configuration:
# team-lead-clusterrole.yaml
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: project-admin
rules:
- apiGroups: ["*"]
resources: ["*"]
verbs: ["*"]
# ClusterRoleBinding for specific namespaces
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: team-lead-admin
namespace: project-a
subjects:
- kind: User
name: team-lead-user
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: project-admin
apiGroup: rbac.authorization.k8s.ioUse Case 4: Read-Only Auditor Role
Scenario: Security team needs read access across all namespaces for compliance auditing.
Configuration:
# auditor-clusterrole.yaml
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: cluster-auditor
rules:
- apiGroups: ["*"]
resources: ["*"]
verbs: ["get", "list", "watch"]
- nonResourceURLs: ["*"]
verbs: ["get", "list"]
# Cluster-wide binding
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: security-auditors
subjects:
- kind: Group
name: security-team
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: cluster-auditor
apiGroup: rbac.authorization.k8s.ioBest Practices
1. Principle of Least Privilege
- Grant only necessary permissions
- Use specific verbs instead of
["*"] - Scope to specific namespaces when possible
2. Use ServiceAccounts for Applications
# Instead of IAM user for applications
apiVersion: v1
kind: ServiceAccount
metadata:
name: app-service-account
namespace: app-namespace3. Regular Auditing
# Check what a user can do
kubectl auth can-i --list --as=dev-user -n rbac-test
# Check specific permissions
kubectl auth can-i create deployments --as=dev-user -n rbac-test4. Organize with Groups
# AWS ConfigMap with groups
mapUsers: |
- userarn: arn:aws:iam::123456789012:user/dev1
username: dev1
groups:
- developers
- userarn: arn:aws:iam::123456789012:user/dev2
username: dev2
groups:
- developers
# Then bind to groups
subjects:
- kind: Group
name: developers
apiGroup: rbac.authorization.k8s.io5. Separate IAM Roles for Different Environments
mapRoles: |
- rolearn: arn:aws:iam::123456789012:role/EKS-DevAdmin
username: dev-admin
groups:
- system:masters
- rolearn: arn:aws:iam::123456789012:role/EKS-DevView
username: dev-view
groups:
- developersTroubleshooting
Common Issues and Solutions:
-
“Error from server (Forbidden)“
# Check permissions kubectl auth can-i <verb> <resource> --as=<user> -n <namespace> # Check role bindings kubectl get rolebinding,clusterrolebinding -A | grep <user> -
AWS IAM User Not Recognized
# Verify aws-auth ConfigMap kubectl get configmap aws-auth -n kube-system -o yaml # Check IAM user ARN format # Correct: arn:aws:iam::<account-id>:user/<username> -
Permissions Not Working Across Namespaces
- Use ClusterRole and ClusterRoleBinding for cross-namespace access
- Verify namespace specification in Role/RoleBinding