-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(cdk greenfield support): Changes to support greenfield account …
…restrictions present in higher environments (#700) * add support for iam path and permissions boundary, required in higher greenfield accounts * update test... wow this is verbose * Add type guards to prevent casting
- Loading branch information
Showing
10 changed files
with
101 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { IAspect } from "aws-cdk-lib"; | ||
import { IConstruct } from "constructs"; | ||
import * as iam from "aws-cdk-lib/aws-iam"; | ||
import { isCfnRole, isCfnUser, isCfnGroup } from "shared-utils"; | ||
|
||
export class IamPathAspect implements IAspect { | ||
private readonly iamPath: string; | ||
|
||
constructor(iamPath: string) { | ||
this.iamPath = iamPath; | ||
} | ||
|
||
public visit(node: IConstruct): void { | ||
if (node instanceof iam.Role && isCfnRole(node.node.defaultChild)) { | ||
node.node.defaultChild?.addPropertyOverride("Path", this.iamPath); | ||
} | ||
|
||
if (node instanceof iam.User && isCfnUser(node.node.defaultChild)) { | ||
node.node.defaultChild.addPropertyOverride("Path", this.iamPath); | ||
} | ||
|
||
if (node instanceof iam.Group && isCfnGroup(node.node.defaultChild)) { | ||
node.node.defaultChild.addPropertyOverride("Path", this.iamPath); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { IAspect } from "aws-cdk-lib"; | ||
import { IConstruct } from "constructs"; | ||
import * as iam from "aws-cdk-lib/aws-iam"; | ||
import { isCfnRole } from "shared-utils"; | ||
|
||
export class IamPermissionsBoundaryAspect implements IAspect { | ||
private readonly permissionsBoundaryArn: string; | ||
|
||
constructor(permissionBoundaryArn: string) { | ||
this.permissionsBoundaryArn = permissionBoundaryArn; | ||
} | ||
|
||
public visit(node: IConstruct): void { | ||
if (node instanceof iam.Role && isCfnRole(node.node.defaultChild)) { | ||
node.node.defaultChild.addPropertyOverride( | ||
"PermissionsBoundary", | ||
this.permissionsBoundaryArn, | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from "./iam-permissions-boundary"; | ||
export * from "./iam-path"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as iam from "aws-cdk-lib/aws-iam"; | ||
|
||
export function isCfnRole(child: any): child is iam.CfnRole { | ||
return child instanceof iam.CfnRole; | ||
} | ||
|
||
export function isCfnUser(child: any): child is iam.CfnUser { | ||
return child instanceof iam.CfnUser; | ||
} | ||
|
||
export function isCfnGroup(child: any): child is iam.CfnGroup { | ||
return child instanceof iam.CfnGroup; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,8 @@ describe("DeploymentConfig", () => { | |
vpcName: "vpcName", | ||
emailFromIdentity: "[email protected]", | ||
emailIdentityDomain: "cms.hhs.gov", | ||
iamPath: "/my/path/", | ||
iamPermissionsBoundary: "arn:aws:iam::1234578910:policy/foo/bar-policy", | ||
}); | ||
|
||
const stageSecret = JSON.stringify({ | ||
|
@@ -101,6 +103,8 @@ describe("DeploymentConfig", () => { | |
terminationProtection: false, | ||
emailFromIdentity: "[email protected]", | ||
emailIdentityDomain: "cms.hhs.gov", | ||
iamPath: "/my/path/", | ||
iamPermissionsBoundary: "arn:aws:iam::1234578910:policy/foo/bar-policy", | ||
}; | ||
|
||
expect(deploymentConfig.config).toEqual(expectedConfig); | ||
|
@@ -167,6 +171,8 @@ describe("DeploymentConfig", () => { | |
terminationProtection: false, | ||
emailFromIdentity: "[email protected]", | ||
emailIdentityDomain: "cms.hhs.gov", | ||
iamPath: "/my/path/", | ||
iamPermissionsBoundary: "arn:aws:iam::1234578910:policy/foo/bar-policy", | ||
}; | ||
|
||
expect(deploymentConfig.config).toEqual(expectedConfig); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters