-
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
feat(iam): apply permissions boundary to a Stage
#22913
Conversation
This PR should be not be merged until #22792 which adds support for creating a default permissions boundary as part of CDK bootstrap. Once that is merged we will be creating a default permissions boundary managed policy with a standard naming convention. That allows us to easily attach this default permissions boundary to applications at either the `Stage` or `Stack` level. For the implementation, there are two components to "applying" the permissions boundary. The first is "applying" the permissions boundary to a construct scope. For this I've used context since context has built in resolution up the tree. For example, you could theoretically do something like the below. ```ts // apply at the app scope const app = new App({ context: { [PERMISSIONS_BOUNDARY_CONTEXT_KEY]: { name: 'app-level-pb', }, }, }); // apply different value at this stage const prodStage = new Stage(app, 'Stage', { permissionsBoundary: PermissionsBoundary.default(), }); const stack = new Stack(prodStage, 'Stack', { permissionsBoundary: PermissionsBoundary.fromName('stack-level-pb'), }); class MyConstruct extends Construct { constructor(scope: Construct, id: string) { super(scope, id); const pb = PermissionsBoundary.fromName('construct-level-pb'); pb.bind(this); } } ``` While the above is possible, the most likely scenario is that you would apply a permission boundary at the `Stage` or `Stack` level. Stages/Stacks correspond to AWS environments (account + region) and so they would most likely also map to bootstrap environments. Because of this I've added parameters a new `permissionsBoundary` property to both the `Stage` & `Stack` props to make it easier to configure. The second aspect to "applying" the boundary is actually attaching the permissions boundary to each IAM Role & User that is created. For this I add an Aspect by default to every `Stack`. This aspect will look for the `context` that was applied earlier for whether or not it should attach a permissions boundary to the Role or User. closes #22745
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
✅ Updated pull request passes all PRLinter validations. Dissmissing previous PRLinter review.
packages/@aws-cdk/aws-iam/README.md
Outdated
This will apply the default permissions boundary created as part of CDK | ||
bootstrap to all IAM Roles that are created within this `Stage`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[note, not feedback] I've seen a lot of confusion stemming from dev experience to pipeline/ prod expectation. Should we have a bigger paragraph here or full docs on how to do development vs how to deploy?
Or it gets to be informational excess?
(arn.includes('${Qualifier}') | ||
|| arn.includes('${AWS::AccountId}') | ||
|| arn.includes('${AWS::Region}') | ||
|| arn.includes('${AWS::Partition}'))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[neither here nor there] Easier to check than for ^\$\{[a-zA-Z0-9]+\}
?
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
#22744 Users can now specify in the CDK CLI a [(permissions boundary) policy](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html) to be applied on the Execution Role and all subsequent IAM users and roles of their app. If you want to try out the feature, a good starting point is having the`--example-permissions-boundary`(or `--epb`) parameter for the `cdk botstrap`: ``` cdk boostrap --epb ``` This achieves a couple of things: a new policy will be created (if not already present) in the account being bootstrapped (`cdk-${qualifier}-permissions-boundary`) and it will be referenced in the bootstrap template. In order for the bootstrap to be successful, the credentials use must include `iam:getPolicy` and `iam:createPolicy` permissions. This works pairs with #22913, as permissions boundary needs propagation. You can inspect the policy via the console, retrieve it via aws cli or sdk and you can copy the structure to use on your own from `packages/aws-cdk/lib/api/bootstrap/bootstrap-template.yaml`: Resources.CdkBoostrapPermissionsBoundaryPolicy At this point you can edit the policy, add restrictions and see what scope would match your requirements. For non-dev work, the suggestion is to use `--custom-permissions-boundary` (or `--cpb`): ``` cdk bootstrap --cpb "custom-policy-name" ``` The policy must be created and accessible for the credentials used to perform the bootstrap. ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
For the implementation, there are two components to "applying" the permissions boundary.
The first is "applying" the permissions boundary to a construct scope. For this I've used context since context has built in resolution up the tree. For example, you could theoretically do something like the below.
While the above is possible, the most likely scenario is that you would apply a permission boundary at the
App
,Stage
orStack
level. Stages/Stacks correspond to AWS environments (account + region) and so they would most likely also map to bootstrap environments. Because of this I've added parameters a newpermissionsBoundary
property to both theStage
&Stack
props to make it easier to configure.The second aspect to "applying" the boundary is actually attaching the permissions boundary to each IAM Role & User that is created. For this I add an Aspect to every
Stack
that has the permissions boundary context. This aspect will attach the permissions boundary to the Role or User.closes #22745
All Submissions:
Adding new Unconventional Dependencies:
New Features
yarn integ
to deploy the infrastructure and generate the snapshot (i.e.yarn integ
without--dry-run
)?By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license