Skip to content

Ability to pass a Permission boundary name via the context on the command line #31

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bin/vpc-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { Stack } from "aws-cdk-lib"
const cdkApp = stackBuilder.stackMapper.app;

const configFile = cdkApp.node.tryGetContext("config");
const permissionsBoundary = cdkApp.node.tryGetContext("permissions_boundary");
// If a configuration file is provided we will use it to build our stacks
if (configFile) {
stackBuilder.configure(configFile);
stackBuilder.configure(configFile, undefined, permissionsBoundary);
await stackBuilder.build();
} else {
// When no configuration context provided, we will warn but not fail. This allows 'cdk bootstrap', 'cdk help'
Expand Down
25 changes: 21 additions & 4 deletions lib/stack-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { IVpcInterfaceEndpointsProps } from "./vpc-interface-endpoints-stack";
import * as path from "path";
import * as fs from "fs";
import * as ri from "@aws-cdk/region-info"
import * as cdk from 'aws-cdk-lib';

export interface namedVpcStack {
name: string;
Expand Down Expand Up @@ -93,6 +94,7 @@ export class StackBuilderClass {
workload: [],
};
configParser: ConfigParser;
permissionsBoundary: cdk.PermissionsBoundary;
c: IConfig;
interfaceDiscovery: Array<ServiceDetail> = [];
interfaceList: Array<string> = [];
Expand All @@ -102,11 +104,14 @@ export class StackBuilderClass {
this.stackMapper = new StackMapper({});
}

configure(configFilename?: string, configContents?: string) {
configure(configFilename?: string, configContents?: string, permissionsBoundary?: string) {
this.configParser = new ConfigParser({
configFilename: configFilename,
configContents: configContents,
});
if (permissionsBoundary) {
this.permissionsBoundary = cdk.PermissionsBoundary.fromName(permissionsBoundary);
}
try {
this.configParser.parse();
this.c = this.configParser.config;
Expand Down Expand Up @@ -185,6 +190,7 @@ export class StackBuilderClass {
shareWithVpcs: sharedWithAppStacks,
shareWithExistingVpcs: dnsStanza.shareWithExistingVpcs,
},
permissionsBoundary: this.permissionsBoundary,
}
);
}
Expand All @@ -196,13 +202,15 @@ export class StackBuilderClass {
const allNamedStacks = this.allNamedStacks();
this.stackMapper.transitGatewayRoutesStack("transit-gateway-routes", {
tgwAttachmentsAndRoutes: allNamedStacks,
useLegacyIdentifiers: this.c.global.useLegacyIdentifiers ? this.c.global.useLegacyIdentifiers : false
})
useLegacyIdentifiers: this.c.global.useLegacyIdentifiers ? this.c.global.useLegacyIdentifiers : false,
permissionsBoundary: this.permissionsBoundary,
});
// Use our Dummy Stack to assure our key exports (tgw ID, vpc ID, TGW attach ID remain exported)
// Really only required when we're attaching to a TGW. Stand alone VPCs don't require exports to
// co-ordinate their installation.
this.stackMapper.cdkExportPersistStack("cdk-export-persistence", {
persistExports: allNamedStacks,
permissionsBoundary: this.permissionsBoundary,
});
}
}
Expand Down Expand Up @@ -232,6 +240,7 @@ export class StackBuilderClass {
ssmParameterPrefix: this.c.global.ssmPrefix,
vpcCidr: configStanza.vpcCidr,
createSubnets: subnets,
permissionsBoundary: this.permissionsBoundary,
};

const transitGatewayName = this.workloadHasTransit(workloadVpcName);
Expand Down Expand Up @@ -307,6 +316,7 @@ export class StackBuilderClass {
props: {
namePrefix: transitGatewayName,
tgwDescription: "imported",
permissionsBoundary: this.permissionsBoundary,
},
};
this.stacks.transitGateway.push({
Expand All @@ -322,6 +332,7 @@ export class StackBuilderClass {
{
namePrefix: transitGatewayName,
tgwDescription: configStanza.tgwDescription,
permissionsBoundary: this.permissionsBoundary,
}
),
});
Expand Down Expand Up @@ -361,6 +372,7 @@ export class StackBuilderClass {
"transitGateway",
configStanza.useTransit
).tgw,
permissionsBoundary: this.permissionsBoundary,
}
),
});
Expand All @@ -383,7 +395,8 @@ export class StackBuilderClass {
existingDxGwTransitGatewayRouteTableId: configStanza.existingDxGwTransitGatewayRouteTableId,
tgw: {
attrId: configStanza.existingTgwId
}
},
permissionsBoundary: this.permissionsBoundary,
}
),
});
Expand Down Expand Up @@ -469,6 +482,7 @@ export class StackBuilderClass {
"transitGateway",
configStanza.useTransit
).tgw,
permissionsBoundary: this.permissionsBoundary,
} as IVpcInterfaceEndpointsProps
),
});
Expand Down Expand Up @@ -510,6 +524,7 @@ export class StackBuilderClass {
"transitGateway",
configStanza.useTransit
).tgw,
permissionsBoundary: this.permissionsBoundary,
} as IVpcRoute53ResolverEndpointsProps
),
});
Expand Down Expand Up @@ -539,6 +554,7 @@ export class StackBuilderClass {
"transitGateway",
configStanza.useTransit
).tgw,
permissionsBoundary: this.permissionsBoundary,
}
),
});
Expand Down Expand Up @@ -567,6 +583,7 @@ export class StackBuilderClass {
"transitGateway",
configStanza.useTransit
).tgw,
permissionsBoundary: this.permissionsBoundary,
}
),
});
Expand Down