Skip to content
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

[aws-eks] ec2:DescribeVpcs permission is missing when creating clusters #9027

Closed
eladb opened this issue Jul 12, 2020 · 21 comments · Fixed by #9029 or #13103
Closed

[aws-eks] ec2:DescribeVpcs permission is missing when creating clusters #9027

eladb opened this issue Jul 12, 2020 · 21 comments · Fixed by #9029 or #13103
Assignees
Labels
@aws-cdk/aws-eks Related to Amazon Elastic Kubernetes Service bug This issue is a bug. effort/small Small work item – less than a day of effort investigating This issue is being investigated and/or work is in progress to resolve the issue. p1

Comments

@eladb
Copy link
Contributor

eladb commented Jul 12, 2020

Today I've also gotten the same error but on the ec2:DescribeVpcs permission. This was not the case on Friday because I rolled out an EKS cluster with a CDK build done from the master branch. Adding the DescribeVpcs permission solved the problem, same as the PR in #8859

Seems like AWS is changing stuff on their end that requires more permissions?

Originally posted by @jargelo in #8574 (comment)

@github-actions github-actions bot added the @aws-cdk/aws-eks Related to Amazon Elastic Kubernetes Service label Jul 12, 2020
@eladb eladb added bug This issue is a bug. p1 labels Jul 12, 2020
@mergify mergify bot closed this as completed in #9029 Jul 13, 2020
mergify bot pushed a commit that referenced this issue Jul 13, 2020
…rmission (#9029)

Fixes #9027

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@jargelo
Copy link

jargelo commented Jul 14, 2020

Thanks @eladb , I was about to raise a new issue for this since I wasn't sure you seen my comment.

@iliapolo iliapolo added this to the EKS Dev Preview milestone Aug 10, 2020
curtiseppel pushed a commit to curtiseppel/aws-cdk that referenced this issue Aug 11, 2020
…rmission (aws#9029)

Fixes aws#9027

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@iliapolo iliapolo changed the title [eks] ec2:DescribeVpcs permission is missing when creating clusters [aws-eks] ec2:DescribeVpcs permission is missing when creating clusters Aug 16, 2020
@stefanolczak
Copy link

I've got the issue when deploying CDK app from scratch ( VPC and EKS as seperate stacks ). Deployment of EKS stack failed with the same error. During redeploy it worked fine. I am using CDK 1.60

@iliapolo
Copy link
Contributor

@stefanolczak Can you share the code? Thanks

@stefanolczak
Copy link

stefanolczak commented Aug 24, 2020

#!/usr/bin/env python3

from aws_cdk import (
    core,
    aws_ec2,
    aws_eks
)


class VpcStack(core.Stack):

    def __init__(self, app: core.App) -> None:
        super().__init__(app, 'vpc-stack')

        self.vpc = aws_ec2.Vpc(
            scope=self,
            id='vpc'
        )


class EksStack(core.Stack):
    def __init__(self, app: core.App, vpc: aws_ec2.Vpc) -> None:
        super().__init__(app, 'eks-stack')

        aws_eks.Cluster(
            scope=self,
            id='eks',
            cluster_name='eks-cluster',
            default_capacity=0,
            version=aws_eks.KubernetesVersion.V1_17,
            vpc=vpc,
            endpoint_access=aws_eks.EndpointAccess.PRIVATE
        )


app = core.App()
vpc_stack = VpcStack(app)
EksStack(app, vpc_stack.vpc)

app.synth()

The issue reproduces only on empty AWS account or on AWS account where CDK or EKS wasn't used for a while. I'm investigating it more why it does matter.

@stefanolczak
Copy link

stefanolczak commented Aug 24, 2020

I'm almost sure I have once seen other issue ( also with IAM policy ) related to deploying EKS that was fixed by redeploy so I'm guessing there is some global problem in that matter.

I found the error message from mentioned issue from the past:

Error: Caller does not have permission to perform `iam:listAttachedRolePolicies`

@sandeep-balouria
Copy link

Upgraded to 1.60.0
Tried deploying to fresh aws account and failed with this

Failed to create resource. IAM role's policy must include the ec2:DescribeVpcs action

redeploy goes through fine.

@kossmoboleat
Copy link

kossmoboleat commented Oct 8, 2020

@eladb This issue might have to be reopened. I've had the same issue with CDK 1.66.0 yesterday when trying to deploy a stack from scratch too.

The first try to deploy fails with the mentioned error message but a re-deploy works. Seems the CDK cannot clean up all created stacks/resources and then those are re-used and it succeeds.

I've also checked and the creation role now has the necessary permissions. So I'm speculating the policy is added to late with the changes in the MR when deploying from scratch.

In our stack we're using a shared VPC with another AWS account that we're importing like so:

    this.vpc = Vpc.fromLookup(this, this.vpcName + '-VPC', {
      tags: {
        Name: this.vpcName
      }
    });

And then using it like so to create the EKS cluster (which fails the first time around):

    const clusterAdmin = new Role(this, 'AdminRole', {
      assumedBy: new AccountRootPrincipal()
    });
    const clusterProps: ClusterProps = {
      version: KubernetesVersion.V1_17,
      outputClusterName: true,
      kubectlEnabled: true,
      defaultCapacity: 1,
      defaultCapacityInstance: new InstanceType("t2.small"),
      mastersRole: clusterAdmin,
      vpc: this.vpc
    };

    return new Cluster(this, name, clusterProps);

@iliapolo
Copy link
Contributor

iliapolo commented Oct 8, 2020

Hi @kossmoboleat - Thanks, yeah looks like there is still something here. Re-opening and we'll investigate.

@iliapolo iliapolo reopened this Oct 8, 2020
@iliapolo iliapolo added the investigating This issue is being investigated and/or work is in progress to resolve the issue. label Oct 8, 2020
@iliapolo iliapolo removed this from the [DevPreview] @aws-cdk/aws-eks milestone Oct 8, 2020
@scalasm
Copy link

scalasm commented Oct 11, 2020

I've got the same issue with CDK 1.67.0 . If you need a simple test project, just use this on GitHub.

You can see the file log in aws-cdk-issue-9027.log . I can confirm what @kossmoboleat: if I run 'cdk deploy' just after this error, then the deploy is succesful :|

@PerArneng
Copy link

PerArneng commented Oct 15, 2020

I also ran in to this problem when setting up a test cluster. https://github.com/PerArneng/eks-cdk-test/tree/issue_9027 . I ran it against a blank account and then it worked on the second attempt. I also got an email from AWS saying that i was granted access to AWS resources You recently requested an AWS Service that required additional validation. Your request has now been validated for AWS Europe (Stockholm) region(s)

Edit: In the branch above the instance type should be 't3.nano' because 't2.nano' is not available in that region

@aakrem
Copy link

aakrem commented Dec 6, 2020

Still happening with 1.76.0 and redeploying the stack fixed it

@iliapolo
Copy link
Contributor

iliapolo commented Dec 6, 2020

Managed to reproduce this on a blank account as well, and also got the email that @PerArneng mentioned.

I believe the error is coming from a validation that EKS makes on the cluster role, and not necessarily from an operation that requires this action.

What happens is that the cluster role we pass gets created by default like so:

this.role = props.role || new iam.Role(this, 'Role', {
assumedBy: new iam.ServicePrincipal('eks.amazonaws.com'),
managedPolicies: [
iam.ManagedPolicy.fromAwsManagedPolicyName('AmazonEKSClusterPolicy'),
],
});

This AmazonEKSClusterPolicy does contain the ec2:DescribeVpcs action, but I suspect that on a blank account, granting usage of a managed policy is what requires this additional validation.

I'll do some internal investigation to see what the best path forward here.

@kay-is
Copy link

kay-is commented Dec 16, 2020

I got the same problem.

A deployment takes 30minutes, so re-deploying isn't a viable workaround for me.

Any other solutions?

@iliapolo
Copy link
Contributor

iliapolo commented Jan 3, 2021

We are still investigating the exact set of conditions where this would happen, and how one can avoid it.

@sunny0826
Copy link

I had the same problem with CDK version: 1.80.0 (build 31132ca)

@bhargav18
Copy link

Same issue with CDK 1.86 on blank account.

@fspaniol
Copy link

fspaniol commented Feb 9, 2021

Same issue with 1.87.1. Re-deploy did the trick

@rafaelpereyra
Copy link

Hello,

I was able to reproduce this (several times) using a tool that vends new accounts for training. Manually adding a policy to the synthesized CloudFormation Template to the role created by CDK fixed the issue for me:

  custernameCreationRole942A9DDE:
    Type: AWS::IAM::Role
    Properties:
      Policies: 
        - PolicyName: PatchForEKSIssues
          PolicyDocument:
            Statement:
              - Action: ec2:Describe*
                Effect: Allow
                Resource: "*"
            Version: "2012-10-17"

@iliapolo
Copy link
Contributor

I was able to reproduce this multiple times in a single account by manually deleting the AWSServiceRoleForAmazonEKS SLR before each deployment. In this scenario (which simulates a blank account) - EKS will create the SLR upon first cluster deployment, and use it for all subsequent deployments as well.

However, seems like there might be an issue with this first deployment flow - which I am following up on internally.
In the meantime, I can verify that the patch policy @rafaelpereyra suggested solves the issue, and I've created a PR to include it in the default policy of the creation role.

@mergify mergify bot closed this as completed in #13103 Feb 18, 2021
mergify bot pushed a commit that referenced this issue Feb 18, 2021
…3103)

Give our creation role the necessary `ec2` permissions to allow creating clusters on environments without an existing SLR. 

The specific operations were taken from the managed policies of the SLRs. Comments inline.

See #9027 (comment) for more context.

Fixes #9027.  

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

NovakGu pushed a commit to NovakGu/aws-cdk that referenced this issue Feb 18, 2021
…s#13103)

Give our creation role the necessary `ec2` permissions to allow creating clusters on environments without an existing SLR. 

The specific operations were taken from the managed policies of the SLRs. Comments inline.

See aws#9027 (comment) for more context.

Fixes aws#9027.  

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
eladb pushed a commit that referenced this issue Feb 22, 2021
…3103)

Give our creation role the necessary `ec2` permissions to allow creating clusters on environments without an existing SLR. 

The specific operations were taken from the managed policies of the SLRs. Comments inline.

See #9027 (comment) for more context.

Fixes #9027.  

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
rafaelpereyra pushed a commit to rafaelpereyra/one-observability-demo that referenced this issue Feb 24, 2021
@dennisvang
Copy link

dennisvang commented Aug 14, 2024

Unrelated to the original post, but it may be useful for people ending up here based on the title:

ec2:DescribeVpcs permission errors may also arise if you try to deploy a cdk-pipeline stack that calls Vpc.fromLookup(), without first running cdk synth locally and commiting the resulting cdk.context.json.

Also see context-lookups

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-eks Related to Amazon Elastic Kubernetes Service bug This issue is a bug. effort/small Small work item – less than a day of effort investigating This issue is being investigated and/or work is in progress to resolve the issue. p1
Projects
None yet