-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(eks): missing access to Kubernetes objects on EKS cluster creation #18843
Comments
I was able to get past this by setting the |
I'm not too sure what the context is here, was this working before and isn't working anymore? Which constructs are you using? |
Sorry for being too vague with my original post @peterwoodworth (i've added few more screenshots). ASFAIK I don't think this has ever worked. I'm using |
@mvs5465 Thanks. I'll give it a try. |
@mvs5465 What does the default behavior then mean? Will the master role be created by default? If it is... how do we get it? |
@robertd Are you using assumed credentials in the CLI and |
@pmkuny Sweet. Looking forward to 2.13.0 release. |
|
@pmkuny I just tried 2.13.0 release and I'm still getting RBAC permission issues with my cluster. const stack = new Stack(mockApp, 'testingKarpenterFargateEphemeralStack', {
env,
synthesizer: new CliCredentialsStackSynthesizer(),
}); |
@robertd - Sorry to hear that. I think leaving this issue open then is appropriate. Can I ask why you're trying to do administer the EKS cluster with SSO credentials instead of using the vended role that CDK creates during cluster creation (assumable by the account principals)? After some more research, it seems that this behavior of creating a separate role to administer the cluster (and additionally, potentially scoping down the separate role that CDK creates for EKS administration) is a better practice. Just trying to understand what your use case is and how I can help. |
Hi @pmkuny. I am using cdk to create an EKS cluster after assuming the proper roles, and by default I'm seeing this message...
Our gitlab runners have pre-created IAM roles that allow CDK to create EKS clusters for us. Unfortunately, we are not able to use CDK pipelines yet (not sure if EKS creation using EKS clusters would pick proper roles).
Would you mind providing a cdk example on how to do this? |
Hey @robertd, After looking through the comments I am having a hard time pinning down what is going on here. Out of consideration that this may be a problem with our EKS implementation I am going to treat it as a bug for now. Could you provide an explicit sample of the code that is causing this error? Just a snippet of the resources responsible for this would be sufficient. Then I can dig a little deeper |
Someone from the CDK team correct please, if I'm wrong here. Hi @robertd -
That means that the CloudFormation execution role is the one getting administrator permissions to the cluster, not your SSO-vended credentials, which is why you're seeing that error message in the AWS Console saying that you don't have access to the cluster. To get around this, CDK also creates a role by default(see
Recommendation Finally, the fact that the new |
Thanks @pmkuny for the detailed overview. 🙌 |
@NGL321 I'm not doing really anything fancy.... Just creating an EKS cluster with a custom nodegroup. ...
const cluster = new Cluster(stack, 'eks', {
vpc,
version: KubernetesVersion.V1_21,
defaultCapacity: 0,
vpcSubnets: [{
subnetType: SubnetType.PRIVATE_WITH_NAT,
}],
tags,
});
const nodegroup = new Nodegroup(stack, 'NodeGroup', {
cluster,
minSize: 0,
desiredSize: 1,
instanceTypes: [
InstanceType.of(InstanceClass.M5, InstanceSize.LARGE),
],
}); |
When we deploy the EKS cluster like this: const cluster = new eks.Cluster(this, 'EksCluster', {
vpc,
version: eks.KubernetesVersion.V1_26,
kubectlLayer: new KubectlLayer(this, 'KubectlLayer'),
defaultCapacity: 0,
}); A cluster mastersRole will be created which maps to When you see the error in the console: This means your current viewing IAM principal was not defined in the We have some solutions here: Option 1: If you are viewing the console with an assumed role, add this role into the cluster.awsAuth.addMastersRole(your_assumed_role) Make sure that the Consider to write a helper function like this: function attachConsoleReadOnlyPolicies(scope: Construct, role: iam.Role) {
// see - https://docs.aws.amazon.com/eks/latest/userguide/view-kubernetes-resources.html#view-kubernetes-resources-permissions
role.addToPolicy(new iam.PolicyStatement({
actions: [
"eks:ListFargateProfiles",
"eks:DescribeNodegroup",
"eks:ListNodegroups",
"eks:ListUpdates",
"eks:AccessKubernetesApi",
"eks:ListAddons",
"eks:DescribeCluster",
"eks:DescribeAddonVersions",
"eks:ListClusters",
"eks:ListIdentityProviderConfigs",
"iam:ListRoles"
],
resources: [ '*' ],
}));
role.addToPolicy(new iam.PolicyStatement({
actions: [
"ssm:GetParameter"
],
resources: [ Stack.of(scope).formatArn({
service: 'ssm',
resource: 'parameter',
arnFormat: ArnFormat.SLASH_RESOURCE_NAME,
resourceName: '*',
}) ],
}));
} Attach required policies to your current role. attachConsoleReadOnlyPolicies(this, your_assumed_role) Option 2: Create your custom const mastersRole = new iam.Role(this, 'MastersRole', {
assumedBy: new iam.AccountRootPrincipal,
});
const cluster = new eks.Cluster(this, 'EksCluster', {
vpc: getOrCreateVpc(this),
version: eks.KubernetesVersion.V1_26,
placeClusterHandlerInVpc: false,
kubectlLayer: new KubectlLayer(this, 'KubectlLayer'),
defaultCapacity: 0,
mastersRole,
outputMastersRoleArn: true,
});
attachConsoleReadOnlyPolicies(this, mastersRole) Now in your EKS console top right corner, click the Make sure to switch back to your original identity when you leave the EKS console. Option 3: Create a dedicated role only for console browsing that allows all account root principal to assume: const cluster = new eks.Cluster(this, 'EksCluster', {
vpc,
version: eks.KubernetesVersion.V1_26,
kubectlLayer: new KubectlLayer(this, 'KubectlLayer'),
});
// create a 2nd readonly master role
const consoleAdminRole = new iam.Role(this, 'ConsoleReadOnlyRole', {
assumedBy: new iam.AccountRootPrincipal,
});
attachConsoleReadOnlyPolicies(this, mastersRole)
// add this role to system:masters RBAC group
cluster.awsAuth.addMastersRole(consoleAdminRole)
new CfnOutput(this, 'ConsoleReadOnlyReole', { value: consoleAdminRole.roleName }) Switch to this role in the console as described in Option 2. |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
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*
Improve the EKS doc in terms of the console access. Closes aws#18843 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
General Issue
Missing access to Kubernetes objects on EKS cluster creation
The Question
We're missing access to Kubernetes objects on EKS cluster creation.
CDK CLI Version
2.0.0 (build 4b6ce31)
Framework Version
No response
Node.js Version
No response
OS
No response
Language
Typescript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: