Skip to content

Commit e7608d5

Browse files
author
ranjeet-pivotchain
committed
diff-iam-user
1 parent f28487f commit e7608d5

File tree

1 file changed

+154
-0
lines changed

1 file changed

+154
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
Read only access: -->
2+
3+
To access EKS cluster from diff IAM user first create IAM USER name called developers,
4+
create secret key and access key of it.
5+
configure it on your machine.
6+
aws configure --profile developers
7+
aws configure list-profiles
8+
export AWS_PROFILE=developers
9+
10+
Create one IAM GROUP name called junior-dev.
11+
12+
Create one role named view-eks-cluster and attache below policy to it.
13+
14+
{
15+
"Version": "2012-10-17",
16+
"Statement": [
17+
{
18+
"Effect": "Allow",
19+
"Action": [
20+
"eks:DescribeNodegroup",
21+
"eks:ListNodegroups",
22+
"eks:DescribeCluster",
23+
"eks:ListClusters",
24+
"eks:AccessKubernetesApi",
25+
"ssm:GetParameter",
26+
"eks:ListUpdates",
27+
"eks:ListFargateProfiles"
28+
],
29+
"Resource": "*"
30+
}
31+
]
32+
}
33+
34+
35+
Attach above role to junior-dev group and add developers user to this group.
36+
37+
By using main user create below cluster role and cluster role binding to give access to developer user.
38+
39+
40+
------------------------------------------------------------------------
41+
cat read-groups.yaml
42+
---
43+
apiVersion: rbac.authorization.k8s.io/v1
44+
kind: ClusterRole
45+
metadata:
46+
name: developer-read
47+
rules:
48+
- apiGroups: ["*"]
49+
resources: ["deployments", "configmaps", "pods", "secrets", "services"]
50+
verbs: ["get", "list", "watch"]
51+
---
52+
apiVersion: rbac.authorization.k8s.io/v1
53+
kind: ClusterRoleBinding
54+
metadata:
55+
name: developer-read
56+
subjects:
57+
- kind: Group
58+
name: developer-read
59+
apiGroup: rbac.authorization.k8s.io
60+
roleRef:
61+
kind: ClusterRole
62+
name: developer-read
63+
apiGroup: rbac.authorization.k8s.io
64+
65+
------------------------------------------------------------------------
66+
67+
Now edit the aws-auth configmap using the main user by using below command:
68+
69+
kubectl edit -n kube-system configmap/aws-auth
70+
71+
add below paragraph into this configmap
72+
73+
mapUsers: |
74+
- userarn: arn:aws:iam::804872348047:user/developers
75+
username: developers
76+
groups:
77+
- developer-read
78+
79+
Save above changes.
80+
Now switch to developer user using below command:
81+
aws eks update-kubeconfig --region us-east-2 --name CLUSTER-NAME --profile developers
82+
83+
Now check that you will get read only access to k8s cluster:
84+
85+
kubectl get pods
86+
kubectl get svc
87+
kubectl auth can-i delete deployment
88+
kubectl auth can-i create deployment
89+
90+
You don't have permission to read the node resources.
91+
kubectl get nodes
92+
93+
=========================================================================
94+
Full access --->
95+
96+
To give full access to k8s cluster create eks user from IAM side and give full admin access to it.
97+
create secret and access key of it.
98+
configure it on your machine.
99+
100+
aws configure --profile admin
101+
aws configure list-profiles
102+
export AWS_PROFILE=admin
103+
104+
By using main user create below cluster role and cluster role binding to give access to developer user.
105+
106+
-----------------------------------------------------------------------------------------------------
107+
cat access-cluster.yaml
108+
---
109+
apiVersion: rbac.authorization.k8s.io/v1
110+
kind: ClusterRole
111+
metadata:
112+
name: full-access
113+
rules:
114+
- apiGroups: ["*"]
115+
resources: ["*"]
116+
verbs: ["*"]
117+
---
118+
apiVersion: rbac.authorization.k8s.io/v1
119+
kind: ClusterRoleBinding
120+
metadata:
121+
name: full-access
122+
subjects:
123+
- kind: Group
124+
name: full-access
125+
apiGroup: rbac.authorization.k8s.io
126+
roleRef:
127+
kind: ClusterRole
128+
name: full-access
129+
apiGroup: rbac.authorization.k8s.io
130+
131+
132+
-----------------------------------------------------------------------------------------------------
133+
134+
Now edit the aws-auth configmap using the main user by using below command:
135+
136+
kubectl edit -n kube-system configmap/aws-auth
137+
138+
add below paragraph into this configmap
139+
140+
mapUsers: |
141+
- userarn: arn:aws:iam::804872348047:user/eks
142+
username: eks
143+
groups:
144+
- full-access
145+
146+
Save above changes.
147+
Now switch to eks user using below command:
148+
aws eks update-kubeconfig --region us-east-2 --name CLUSTER-NAME --profile admin
149+
150+
Now check that you will get full access to k8s cluster:
151+
kubectl get nodes
152+
kubectl get pods
153+
kubectl auth can-i delete deployment
154+
kubectl auth can-i create deployment

0 commit comments

Comments
 (0)