Skip to content

Commit 1820fc9

Browse files
authored
fix(cdk): allow bootstrap with policy names with a path (#26378)
Policy names with slashes (`/`) are not allowed when bootstrapping. For example: ``` cdk bootstrap --custom-permissions-boundary aaa/bbb ``` Would fail: ``` Error: The permissions boundary name aaa/bbb does not match the IAM conventions. ``` This fix allows to specify paths in the policy name. Closes #26320. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 9d9daba commit 1820fc9

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

packages/@aws-cdk-testing/cli-integ/tests/cli-integ-tests/bootstrapping.integtest.ts

+11
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,17 @@ integTest('can use the custom permissions boundary to bootstrap', withoutBootstr
255255
expect(template).toContain('permission-boundary-name');
256256
}));
257257

258+
integTest('can use the custom permissions boundary (with slashes) to bootstrap', withoutBootstrap(async (fixture) => {
259+
let template = await fixture.cdkBootstrapModern({
260+
// toolkitStackName doesn't matter for this particular invocation
261+
toolkitStackName: fixture.bootstrapStackName,
262+
showTemplate: true,
263+
customPermissionsBoundary: 'permission-boundary-name/with/path',
264+
});
265+
266+
expect(template).toContain('permission-boundary-name/with/path');
267+
}));
268+
258269
integTest('can remove customPermissionsBoundary', withoutBootstrap(async (fixture) => {
259270
const bootstrapStackName = fixture.bootstrapStackName;
260271
const policyName = `${bootstrapStackName}-pb`;

packages/aws-cdk/lib/api/bootstrap/bootstrap-environment.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,9 @@ export class Bootstrapper {
279279

280280
private validatePolicyName(permissionsBoundary: string) {
281281
// https://docs.aws.amazon.com/IAM/latest/APIReference/API_CreatePolicy.html
282-
const regexp: RegExp = /[\w+=,.@-]+/;
282+
// Added support for policy names with a path
283+
// See https://github.com/aws/aws-cdk/issues/26320
284+
const regexp: RegExp = /[\w+\/=,.@-]+/;
283285
const matches = regexp.exec(permissionsBoundary);
284286
if (!(matches && matches.length === 1 && matches[0] === permissionsBoundary)) {
285287
throw new Error(`The permissions boundary name ${permissionsBoundary} does not match the IAM conventions.`);

packages/aws-cdk/test/api/bootstrap2.test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,28 @@ describe('Bootstrapping v2', () => {
207207
]));
208208
});
209209

210+
test('adding permission boundary with path in policy name', async () => {
211+
mockTheToolkitInfo({
212+
Parameters: [
213+
{
214+
ParameterKey: 'InputPermissionsBoundary',
215+
ParameterValue: '',
216+
},
217+
],
218+
});
219+
await bootstrapper.bootstrapEnvironment(env, sdk, {
220+
parameters: {
221+
customPermissionsBoundary: 'permissions-boundary-name/with/path',
222+
},
223+
});
224+
225+
expect(stderrMock.mock.calls).toEqual(expect.arrayContaining([
226+
expect.arrayContaining([
227+
expect.stringMatching(/Adding new permissions boundary permissions-boundary-name\/with\/path/),
228+
]),
229+
]));
230+
});
231+
210232
test('passing trusted accounts without CFN managed policies results in an error', async () => {
211233
await expect(bootstrapper.bootstrapEnvironment(env, sdk, {
212234
parameters: {

0 commit comments

Comments
 (0)