aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

cdk synth fails to apply permission boundaries when using constructs from npm artifact

Open matsaune opened this issue 4 years ago • 4 comments

What is the problem?

The problem is that from aws-cdk-lib 2.2.0 and onwards (ok on 2.0.0) cdk synth/deploy fails to apply permission boundary when construct is imported from npm repo. If I copy the common construct to local cdk folder it works as expected.

So the "problem" lies in how cdk synthesises template file considering Permission boundaries on roles somehow, when construct is imported from npm lib.

This is not applied:

    const boundary = iam.ManagedPolicy.fromManagedPolicyName(this, 'Boundary', 'PermissionBoundaryPolicyName');
    iam.PermissionsBoundary.of(this).apply(boundary);

Reproduction Steps

This is the imported construct:

import {App} from 'aws-cdk-lib';
import {GsFargateServiceStack,PriorityConstants,InfraNamesConstants} from "@gsf/common-infra-aws";
//import {GsFargateServiceStack} from "./gs-fargate-service-stack";

const app = new App();
new GsFargateServiceStack(app,"APP_NAME",{
    env: {account: process.env.CDK_DEFAULT_ACCOUNT,region: process.env.CDK_DEFAULT_REGION },
    description: "The GroupService application APP_NAME packaged as a Fargate service",
    infrastructureStackName: "INFRASTRUCTURE_STACK_NAME",
    clusterName: "ECS_CLUSTER",
    path: "/PATH*",
    port: 8080,
    healthCheckUrl: "/PATH/HEALTHCHECK",
    priority: PriorityConstants.PRIORITY,//Just a number
    serviceName: "ondemand-api"
});

I have attached the GsFargateServiceStack file along with the fargate service wrapper example.zip

What did you expect to happen?

I expect the permission boundary to be attached to generated template regardless if the construct is imported from lib or not.

What actually happened?

On aws-cdk-lib 2.2.0 and up the permissionBoundary is not attached to roles defined in stack and deploy fails. On 2.0.0 this works as expected.

CDK CLI Version

2.2.0 (build 4f5c27c)

Framework Version

No response

Node.js Version

v16.4.2

OS

macOS 12.1 (21C52)

Language

Typescript

Language Version

~3.9.7

Other information

Hi, first a little background. In my company we are using a "lift and shift" paradigm where we pack existing web apps in docker containers, and deploy them on fargate services. Due to company policy all roles must be bound by a PermissionBoundary defined by a managed policy.

We have created a "shared-infra-stack" containing shared resources such as api-gateway, nbl, alb and similar that is referenced from each application stack.

For the application stacks we have created a Fargate service wrapper construct utilising Fargate and shared infra defined in stack. This we publish to a private npm repo and each application does an import of this and uses the provided construct.

matsaune avatar Jan 25 '22 08:01 matsaune

This is really not enough information for me to go on, so I'm going to have to guess. I'm going to guess that the package.json of your @gsf/common-infra-aws package looks like this:

{
  "dependencies": {
    "aws-cdk-lib": "2.0.0"
  }
}

If so, change it into the following:

{
  "devDependencies": {
    "aws-cdk-lib": "2.0.0"
  },
  "peerDependencies": {
    "aws-cdk-lib": "^2.0.0"
  }
}

rix0rrr avatar Jan 31 '22 13:01 rix0rrr

@rix0rrr Thx, will give this a go and let you the result

matsaune avatar Feb 03 '22 09:02 matsaune

Since you didn't come back I'm going to assume this can be closed.

rix0rrr avatar Feb 08 '22 13:02 rix0rrr

⚠️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.

github-actions[bot] avatar Feb 08 '22 13:02 github-actions[bot]