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-ec2: restrictDefaultSecurityGroup custom resource lambda uses basic lambda execution role, no ability to add perm boundary #31628

Open
1 task
justinwiley opened this issue Oct 2, 2024 · 2 comments
Assignees
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud bug This issue is a bug. closing-soon This issue will automatically close in 4 days unless further comments are made. investigating This issue is being investigated and/or work is in progress to resolve the issue. p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@justinwiley
Copy link

justinwiley commented Oct 2, 2024

Describe the bug

If the restrictDefaultSecurityGroup option is enabled for ec2.Vpc, a new lambda and lambda execution role is created with the AWSLambdaBasicExecutionRole attached, which grants inappropriately broad wildcard log access.

There doesn't seem to be a way to override this, or to add a permissions boundary to the lambda execution role.

There are two issues with this:

  • by default, cdknag complains about wildcard access
  • if you are providing a custom permissions boundary for the cdk bootstrap role, you likely want to have the role require lambdas be deployed with a permissions boundary attached

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

ec2.Vpc should:

  • expose the lambda execution role or allow it to be overwritten
  • or, stop using the basic execution role and provide a perm boundary option

Current Behavior

See above

Reproduction Steps

    const vpc = new ec2.Vpc(this, 'VPC', {
      ipAddresses: ec2.IpAddresses.cidr(`10.0.0.0/16`),
      restrictDefaultSecurityGroup: true,
    })

Possible Solution

see expected behavior

Additional Information/Context

No response

CDK CLI Version

2.160

Framework Version

No response

Node.js Version

20

OS

any

Language

TypeScript

Language Version

No response

Other information

No response

@justinwiley justinwiley added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 2, 2024
@github-actions github-actions bot added the @aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud label Oct 2, 2024
@khushail khushail added needs-reproduction This issue needs reproduction. p2 and removed needs-triage This issue or PR still needs to be triaged. labels Oct 3, 2024
@khushail khushail self-assigned this Oct 7, 2024
@khushail khushail added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-reproduction This issue needs reproduction. labels Oct 7, 2024
@khushail
Copy link
Contributor

khushail commented Oct 8, 2024

Hi @justinwiley , thanks for reaching out.

i tried to repro this with given scenario and here is my observation -

The lambdaBasicExecutionRole is having access to Logs after setting 'restrictDefaultSecurityGroup` to true -

Screenshot 2024-10-07 at 3 34 40 PM Screenshot 2024-10-07 at 6 19 05 PM

However when I try to restrict the role permission by custom boundary,

    //creating custom boundary
    const boundary = new iam.ManagedPolicy(this, 'Boundary2', {
      statements: [
        new iam.PolicyStatement({
          effect: iam.Effect.DENY,
          actions: ['logs:PutLogEvents'],
          resources: ['*'],
        }),
      ],
    });

    iam.PermissionsBoundary.of(this).apply(boundary);

I see Boundary role getting attached to customRole as shown in this template-

  "CustomVpcRestrictDefaultSGCustomResourceProviderRole26592FE0": {
  "Type": "AWS::IAM::Role",
  "Properties": {
   "AssumeRolePolicyDocument": {
    "Version": "2012-10-17",
    "Statement": [
     {
      "Action": "sts:AssumeRole",
      "Effect": "Allow",
      "Principal": {
       "Service": "lambda.amazonaws.com"
      }
     }
    ]
   },
   "ManagedPolicyArns": [
    {
     "Fn::Sub": "arn:${AWS::Partition}:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
    }
   ],
   "Policies": [
    {
     "PolicyName": "Inline",
     "PolicyDocument": {
      "Version": "2012-10-17",
      "Statement": [
       {
        "Effect": "Allow",
        "Action": [
         "ec2:AuthorizeSecurityGroupIngress",
         "ec2:AuthorizeSecurityGroupEgress",
         "ec2:RevokeSecurityGroupIngress",
         "ec2:RevokeSecurityGroupEgress"
        ],
        "Resource": [
         {
          "Fn::Join": [
           "",
           [
            "arn:aws:ec2:us-west-1:123456789012:security-group/",
            {
             "Fn::GetAtt": [
              "VPCB9E5F0B4",
              "DefaultSecurityGroup"
             ]
            }
           ]
          ]
         }
        ]
       }
      ]
     }
    }
   ],
   "PermissionsBoundary": {
    "Ref": "Boundary261F0699E"
   }

is this what you are expecting to do ??
I agree that by changing the boolean value to true, wide permissions are granted but AFAIU, this boundary role is limiting the access permissions. However I am working on the scenario of bootstrap permission boundary though, will share findings soon.
Please feel free to clarify if something is misinterpreted.

@khushail khushail added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Oct 8, 2024
Copy link

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.

@github-actions github-actions bot added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-ec2 Related to Amazon Elastic Compute Cloud bug This issue is a bug. closing-soon This issue will automatically close in 4 days unless further comments are made. investigating This issue is being investigated and/or work is in progress to resolve the issue. p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants