AWS Builder Center
Kubernetes Authentication and Authorization on Amazon EKS: A Practical Guide to IAM, RBAC, and Access Control

Kubernetes Authentication and Authorization on Amazon EKS: A Practical Guide to IAM, RBAC, and Access Control

Learn how authentication and authorization work in Kubernetes and Amazon EKS. This practical guide covers AWS IAM integration, EKS Access Entries, Kubernetes RBAC, Roles, RoleBindings, ClusterRoles, and essential kubectl commands with real-world examples.

Aspiring DevOps & AWS Cloud Engineer | Docker | Kubernetes | Terraform | CI/CD | Automation
Security is one of the most important aspects of managing Kubernetes clusters in production environments. In Kubernetes, not every developer, administrator, or application should have unrestricted access to cluster resources. For example, developers may need permission to view Pods and Deployments, while cluster administrators require permissions to manage nodes, namespaces, and cluster configurations. To manage these permissions securely, Kubernetes provides two important mechanisms: Authentication Authorization When running Kubernetes on Amazon Elastic Kubernetes Service (Amazon EKS), AWS Identity and Access Management (IAM) can also integrate with Kubernetes access control. In this article, we will understand how authentication and authorization work, explore Kubernetes RBAC, configure access permissions, and perform practical operations using kubectl and AWS CLI commands.
1. What Is Authentication? Authentication is the process of verifying the identity of a user or application requesting access to the Kubernetes API server. In simple terms: Authentication answers: Who are you? For example, when an administrator executes: kubectl get pods The Kubernetes API server needs to verify the identity associated with that request before processing it. Common Kubernetes authentication methods include: X.509 client certificates Bearer tokens Service Account tokens OpenID Connect (OIDC) External authentication integrations In Amazon EKS, IAM identities can authenticate to the Kubernetes API using AWS-supported authentication mechanisms.
2. What Is Authorization? Authorization determines what an authenticated user or application is allowed to do. In simple terms: Authorization answers: What are you allowed to do? For example: Developer A can view Pods. Developer B can create Deployments. Administrator C can manage all cluster resources. Kubernetes uses Role-Based Access Control (RBAC) to manage these permissions. RBAC defines permissions through four main objects: Role ClusterRole RoleBinding ClusterRoleBinding
3. Authentication vs Authorization Authentication Authorization Verifies identity Verifies permissions Who are you? What can you do? Checks credentials Checks access policies IAM authentication in EKS Kubernetes RBAC Happens first Happens after authentication Both mechanisms work together to secure Kubernetes API access.
4. Understanding Kubernetes RBAC RBAC stands for Role-Based Access Control. It allows administrators to assign permissions based on responsibilities rather than granting unrestricted access to everyone. Let's understand its four components. Role A Role defines permissions within a particular namespace. Example: A developer can view Pods in the development namespace but cannot access resources in other namespaces through that Role. ClusterRole A ClusterRole defines permissions at the cluster level. It can provide access to cluster-scoped resources or namespaced resources across multiple namespaces. RoleBinding A RoleBinding connects a Role or ClusterRole to a user, group, or ServiceAccount within a particular namespace. ClusterRoleBinding A ClusterRoleBinding connects a ClusterRole to a user, group, or ServiceAccount across the entire cluster.
5. Practical Implementation: Configure Kubernetes RBAC Let's implement a real-world example. Scenario: We have a Kubernetes cluster with a namespace called development. We want to create a developer account that can: View Pods. List Pods. Watch Pods. View Services. However, the developer should not be able to delete Pods or modify Deployments.
Step 1: Create a namespace kubectl create namespace development Verify: kubectl get namespaces
Step 2: Create a Role Create a file named pod-reader-role.yaml. apiVersion: rbac.authorization.k8s.io/v1 kind: Role
metadata: name: pod-reader namespace: development
rules: - apiGroups: [""] resources: - pods - services verbs: - get - list - watch Apply the configuration: kubectl apply -f pod-reader-role.yaml Verify: kubectl get roles -n development
Step 3: Create a ServiceAccount kubectl create serviceaccount developer -n development Verify: kubectl get serviceaccounts -n development
Step 4: Create a RoleBinding Create pod-reader-binding.yaml. apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding
metadata: name: developer-binding namespace: development
subjects: - kind: ServiceAccount name: developer namespace: development
roleRef: kind: Role name: pod-reader apiGroup: rbac.authorization.k8s.io Apply: kubectl apply -f pod-reader-binding.yaml Verify: kubectl get rolebindings -n development Step 5: Verify permissions Check whether the ServiceAccount can view Pods: kubectl auth can-i list pods \ --as=system:serviceaccount:development:developer \ -n development Expected output: yes Check whether it can delete Pods: kubectl auth can-i delete pods \ --as=system:serviceaccount:development:developer \ -n development Expected output: no This demonstrates how RBAC provides controlled access to Kubernetes resources. Note: The identity running these impersonation checks must have permission to impersonate the ServiceAccount.
6. Authentication and Authorization in Amazon EKS Amazon EKS integrates AWS IAM with Kubernetes authentication. When a user runs kubectl against an EKS cluster, AWS IAM credentials are used to authenticate the request through the EKS authentication mechanism. The general workflow is: A user authenticates using AWS IAM credentials. AWS CLI generates an EKS authentication token. The Kubernetes API server validates the identity. The identity receives its associated Kubernetes username and groups. Authorization determines whether the requested operation is permitted. The API server allows or rejects the request. Amazon EKS provides Access Entries to manage IAM principal access to Kubernetes clusters. Access Entries are the recommended modern approach for managing IAM access.
7. Practical AWS EKS Commands Step 1: Configure AWS CLI aws configure Step 2: Check AWS identity aws sts get-caller-identity
Step 3: List EKS clusters aws eks list-clusters --region ap-south-1
Step 4: Connect kubectl to the EKS cluster aws eks update-kubeconfig \ --region ap-south-1 \ --name my-cluster Replace my-cluster with your actual EKS cluster name.
Step 5: Verify cluster connectivity kubectl get nodes
Step 6: Check authentication mode aws eks describe-cluster \ --name my-cluster \ --region ap-south-1 \ --query "cluster.accessConfig.authenticationMode"
Step 7: List access entries aws eks list-access-entries \ --cluster-name my-cluster \ --region ap-south-1 Step 8: Create an EKS Access Entry aws eks create-access-entry \ --cluster-name my-cluster \ --principal-arn arn:aws:iam::ACCOUNT_ID:role/DeveloperRole \ --type STANDARD \ --region ap-south-1 Replace ACCOUNT_ID and the IAM role ARN with your actual values.
Step 9: Associate a read-only EKS access policy aws eks associate-access-policy \ --cluster-name my-cluster \ --principal-arn arn:aws:iam::ACCOUNT_ID:role/DeveloperRole \ --policy-arn arn:aws:eks::aws:cluster-access-policy/AmazonEKSViewPolicy \ --access-scope type=cluster \ --region ap-south-1 This grants the IAM principal the permissions included in the EKS View policy at cluster scope. Important: EKS Access Entries require the cluster authentication mode to support the EKS API (API or API_AND_CONFIG_MAP). Existing cluster authentication settings should be checked before making changes.
8. Important Kubernetes RBAC Commands Here are some useful commands for daily Kubernetes administration and troubleshooting. View Roles kubectl get roles -A View ClusterRoles kubectl get clusterroles View RoleBindings kubectl get rolebindings -A View ClusterRoleBindings kubectl get clusterrolebindings Describe a Role kubectl describe role pod-reader -n development Describe a RoleBinding kubectl describe rolebinding developer-binding -n development Check user permissions kubectl auth can-i get pods -n development Check all permissions kubectl auth can-i --list -n development Check permissions for another identity kubectl auth can-i list pods --as=developer -n development
9. Common RBAC Troubleshooting Scenarios In production environments, incorrect permissions can cause application deployment failures and operational issues. Here are some common scenarios.
Problem 1: User cannot access the cluster Possible reasons: IAM principal is not configured. Incorrect AWS credentials. Missing EKS Access Entry. Incorrect kubeconfig configuration. Useful commands: aws sts get-caller-identity kubectl config current-context kubectl get nodes
Problem 2: User receives Forbidden errors Example: Error from server (Forbidden): pods is forbidden Possible reasons: Missing RoleBinding. Incorrect Role permissions. Incorrect namespace. Missing permissions in the associated ClusterRole. Troubleshooting: kubectl auth can-i list pods -n development kubectl get roles -n development kubectl get rolebindings -n development Problem 3: Developer can access one namespace but not another This can happen because RoleBindings are namespace-specific. Check: kubectl get rolebindings -A Review the namespace in which the RoleBinding was created.
10. Security Best Practices When managing Kubernetes access in production, follow these recommendations: Follow the Principle of Least Privilege. Avoid granting cluster-admin permissions unnecessarily. Use IAM roles and temporary credentials for human access. Use namespace-specific Roles wherever possible. Review RoleBindings and ClusterRoleBindings regularly. Avoid sharing administrator credentials. Use ServiceAccounts for workloads that require Kubernetes API access. Monitor access and authentication activity. Use EKS Access Entries for modern IAM-to-cluster access management. Regularly audit permissions to identify excessive access. Remember: Giving every developer cluster-admin access is not a secure approach.
Conclusion Authentication and authorization are essential components of Kubernetes security. Authentication verifies the identity of users and applications, while authorization controls what those identities can access and modify. By combining AWS IAM, Amazon EKS Access Entries, and Kubernetes RBAC, organizations can implement secure and controlled access to Kubernetes clusters. Understanding these concepts is valuable for DevOps engineers, Cloud Engineers, Kubernetes Administrators, and Site Reliability Engineers working with production infrastructure. Start with a small RBAC implementation in a development namespace, test permissions using kubectl auth can-i, and gradually apply the same principles to larger environments. Secure access is not about giving everyone more permissions. It is about giving everyone exactly the permissions they need.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article