
Simplified Amazon EKS Cluster Access Management using EKS APIs and AWS Console
Amazon EKS Team have added a new feature of assigning IAM principals access to the EKS cluster and Kubernetes Objects directly using the Amazon EKS API, we shall additionally explore the same via AWS Console.
- An EKS Cluster (v1.27) provisioned with the latest platform version.
- kubectl (v1.29.0), aws-cli (2.15.7) installed
- Required IAM permissions to call EKS API using aws-cli
- Access Entry - "An access entry is a cluster identity—directly linked to an AWS IAM principal user or role—that is used to authenticate to an Amazon EKS cluster."
- Access Policies - "An Amazon EKS access policy authorizes an access entry to perform specific cluster actions."
aws eks list-access-policies
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
"accessPolicies": [
{
"name": "AmazonEKSAdminPolicy",
"arn": "arn:aws:eks::aws:cluster-access-policy/AmazonEKSAdminPolicy"
},
{
"name": "AmazonEKSClusterAdminPolicy",
"arn": "arn:aws:eks::aws:cluster-access-policy/AmazonEKSClusterAdminPolicy"
},
{
"name": "AmazonEKSEditPolicy",
"arn": "arn:aws:eks::aws:cluster-access-policy/AmazonEKSEditPolicy"
},
{
"name": "AmazonEKSViewPolicy",
"arn": "arn:aws:eks::aws:cluster-access-policy/AmazonEKSViewPolicy"
}
]
}
- CONFIG_MAP - Uses aws-auth configmap authentication exclusively.
- API_AND_CONFIG_MAP - Uses both aws-auth configmap and Amazon EKS Access Entry API's to source authentication with precedence to the latter.
- API - Only considers Amazon EKS Access Entry API's to source authentication.
aws eks update-cluster-config --name eks-demo-cluster --access-config authenticationMode=API_AND_CONFIG_MAP
aws eks create-access-entry --cluster-name eks-demo-cluster --principal-arn "arn:aws:iam::<ACCOUNTID>:user/k8s-admin"
aws eks associate-access-policy --cluster-name eks-demo-cluster --principal-arn "arn:aws:iam::<ACCOUNTID>:user/k8s-admin" --policy-arn arn:aws:eks::aws:cluster-access-policy/AmazonEKSClusterAdminPolicy --access-scope type=cluster
aws eks update-cluster-config --name eks-demo-cluster --access-config authenticationMode=API
AWS_PROFILE=k8s-admin-demo aws eks update-kubeconfig --name eks-demo-cluster --region ap-south-1
kubectl auth can-i
1
2
3
4
5
6
7
8
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: pod-viewer
rules:
- apiGroups: [""]
resources: ["pods", "pods/log"]
verbs: ["list", "get", "watch"]
kubectl create clusterrolebinding pod-viewer --clusterrole=pod-viewer --group=developer
aws eks create-access-entry --cluster-name eks-demo-cluster --principal-arn "arn:aws:iam::<ACCOUNTID>:user/k8s-dev" --kubernetes-group developer
aws eks delete-access-entry --cluster-name eks-demo-cluster --principal-arn "arn:aws:iam::<ACCOUNTID>:user/k8s-dev"