Skip to content

Commit

Permalink
fix(iam): permissions boundary aspect doesn't always recognize roles (#…
Browse files Browse the repository at this point in the history
…16154)

Using `instanceof` does not seem to work in all scenarios. Instead, use the `CfnResource.isCfnResource` method to find the L1 constructs.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
polothy authored Sep 7, 2021
1 parent 492d33b commit c8bfcf6
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions packages/@aws-cdk/aws-iam/lib/permissions-boundary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ export class PermissionsBoundary {
public apply(boundaryPolicy: IManagedPolicy) {
Node.of(this.scope).applyAspect({
visit(node: IConstruct) {
if (node instanceof CfnRole || node instanceof CfnUser) {
node.permissionsBoundary = boundaryPolicy.managedPolicyArn;
} else if (
node instanceof CfnResource &&
if (
CfnResource.isCfnResource(node) &&
(node.cfnResourceType == CfnRole.CFN_RESOURCE_TYPE_NAME || node.cfnResourceType == CfnUser.CFN_RESOURCE_TYPE_NAME)
) {
node.addPropertyOverride('PermissionsBoundary', boundaryPolicy.managedPolicyArn);
Expand All @@ -51,10 +49,8 @@ export class PermissionsBoundary {
public clear() {
Node.of(this.scope).applyAspect({
visit(node: IConstruct) {
if (node instanceof CfnRole || node instanceof CfnUser) {
node.permissionsBoundary = undefined;
} else if (
node instanceof CfnResource &&
if (
CfnResource.isCfnResource(node) &&
(node.cfnResourceType == CfnRole.CFN_RESOURCE_TYPE_NAME || node.cfnResourceType == CfnUser.CFN_RESOURCE_TYPE_NAME)
) {
node.addPropertyDeletionOverride('PermissionsBoundary');
Expand Down

0 comments on commit c8bfcf6

Please sign in to comment.