Skip to content

Commit 3baffd8

Browse files
authored
chore(eks): improve eks doc for console access (#25606)
Improve the EKS doc in terms of the console access. Closes #18843 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 7fa74c4 commit 3baffd8

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

packages/aws-cdk-lib/aws-eks/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,74 @@ declare const role: iam.Role;
928928
cluster.awsAuth.addMastersRole(role);
929929
```
930930

931+
To access the Kubernetes resources from the console, make sure your viewing principal is defined
932+
in the `aws-auth` ConfigMap. Some options to consider:
933+
934+
```ts
935+
import { KubectlV27Layer } from '@aws-cdk/lambda-layer-kubectl-v27';
936+
declare const cluster: eks.Cluster;
937+
declare const your_current_role: iam.Role;
938+
declare const vpc: ec2.Vpc;
939+
940+
// Option 1: Add your current assumed IAM role to system:masters. Make sure to add relevant policies.
941+
cluster.awsAuth.addMastersRole(your_current_role);
942+
943+
your_current_role.addToPolicy(new iam.PolicyStatement({
944+
actions: [
945+
'eks:AccessKubernetesApi',
946+
'eks:Describe*',
947+
'eks:List*',
948+
],
949+
resources: [ cluster.clusterArn ],
950+
}));
951+
```
952+
953+
```ts
954+
// Option 2: create your custom mastersRole with scoped assumeBy arn as the Cluster prop. Switch to this role from the AWS console.
955+
import { KubectlV27Layer } from '@aws-cdk/lambda-layer-kubectl-v27';
956+
declare const vpc: ec2.Vpc;
957+
958+
const mastersRole = new iam.Role(this, 'MastersRole', {
959+
assumedBy: new iam.ArnPrincipal('arn_for_trusted_principal'),
960+
});
961+
962+
const cluster = new eks.Cluster(this, 'EksCluster', {
963+
vpc,
964+
version: eks.KubernetesVersion.V1_27,
965+
kubectlLayer: new KubectlV27Layer(this, 'KubectlLayer'),
966+
mastersRole,
967+
});
968+
969+
mastersRole.addToPolicy(new iam.PolicyStatement({
970+
actions: [
971+
'eks:AccessKubernetesApi',
972+
'eks:Describe*',
973+
'eks:List*',
974+
],
975+
resources: [ cluster.clusterArn ],
976+
}));
977+
```
978+
979+
```ts
980+
// Option 3: Create a new role that allows the account root principal to assume. Add this role in the `system:masters` and witch to this role from the AWS console.
981+
declare const cluster: eks.Cluster;
982+
983+
const consoleReadOnlyRole = new iam.Role(this, 'ConsoleReadOnlyRole', {
984+
assumedBy: new iam.ArnPrincipal('arn_for_trusted_principal'),
985+
});
986+
consoleReadOnlyRole.addToPolicy(new iam.PolicyStatement({
987+
actions: [
988+
'eks:AccessKubernetesApi',
989+
'eks:Describe*',
990+
'eks:List*',
991+
],
992+
resources: [ cluster.clusterArn ],
993+
}));
994+
995+
// Add this role to system:masters RBAC group
996+
cluster.awsAuth.addMastersRole(consoleReadOnlyRole)
997+
```
998+
931999
### Cluster Security Group
9321000

9331001
When you create an Amazon EKS cluster, a [cluster security group](https://docs.aws.amazon.com/eks/latest/userguide/sec-group-reqs.html)

0 commit comments

Comments
 (0)