Repository navigation
fix(bootstrap): disallow AssumeRole with ExternalId by default #811
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
Merged
+474
−69
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
d8fb679
fix(bootstrap): disallow AssumeRole with ExternalId by default
rix0rrr dda1be1
Add command line argument properly
rix0rrr 32e1938
Add integ test
rix0rrr 1e0fcd4
Add a second test to ensure the protection can be switched off
rix0rrr a2e79b3
Bump bootstrap stack version
rix0rrr d5fb15e
Add parameter to test templates
rix0rrr 27619f3
Update packages/aws-cdk/lib/cli/user-input.ts
rix0rrr 3b87814
Merge remote-tracking branch 'origin/main' into huijbers/no-deputized…
rix0rrr a1808f4
chore: self mutation
invalid-email-address 51f3b4e
Allow deploying legacy templates
rix0rrr 8072bd0
Merge branch 'huijbers/no-deputized-assumeroles' of github.com:aws/aw…
rix0rrr 180b34d
Update template
rix0rrr 0cbaede
Template and tests
rix0rrr cceb843
Fix tests
rix0rrr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
47 changes: 47 additions & 0 deletions
47
...tests/bootstrap/cdk-bootstrap-deploy-role-cannot-be-assumed-with-external-id.integtest.ts
This file contains hidden or 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,47 @@ | ||
| import { AssumeRoleCommand } from '@aws-sdk/client-sts'; | ||
| import { integTest, withoutBootstrap } from '../../../lib'; | ||
|
|
||
| jest.setTimeout(2 * 60 * 60_000); // Includes the time to acquire locks, worst-case single-threaded runtime | ||
|
|
||
| integTest('deploy role cannot be assumed with external id', withoutBootstrap(async (fixture) => { | ||
| const bootstrapStackName = fixture.bootstrapStackName; | ||
|
|
||
| await fixture.cdkBootstrapModern({ | ||
| toolkitStackName: bootstrapStackName, | ||
| cfnExecutionPolicy: 'arn:aws:iam::aws:policy/AdministratorAccess', | ||
| }); | ||
|
|
||
| const account = await fixture.aws.account(); | ||
| const deployRoleArn = `arn:aws:iam::${account}:role/cdk-${fixture.qualifier}-deploy-role-${account}-${fixture.aws.region}`; | ||
|
|
||
| // Attempt to assume the deploy role with an external ID should fail | ||
| await expect( | ||
| fixture.aws.sts.send(new AssumeRoleCommand({ | ||
| RoleArn: deployRoleArn, | ||
| RoleSessionName: 'test-external-id-failure', | ||
| ExternalId: 'some-external-id', | ||
| })), | ||
| ).rejects.toThrow(); | ||
| })); | ||
|
|
||
| integTest('deploy role can be assumed with ExternalId if protection is switched off', withoutBootstrap(async (fixture) => { | ||
| const bootstrapStackName = fixture.bootstrapStackName; | ||
|
|
||
| await fixture.cdkBootstrapModern({ | ||
| toolkitStackName: bootstrapStackName, | ||
| cfnExecutionPolicy: 'arn:aws:iam::aws:policy/AdministratorAccess', | ||
| denyExternalId: false, | ||
| }); | ||
|
|
||
| const account = await fixture.aws.account(); | ||
| const deployRoleArn = `arn:aws:iam::${account}:role/cdk-${fixture.qualifier}-deploy-role-${account}-${fixture.aws.region}`; | ||
|
|
||
| // Attempt to assume the deploy role with an external ID should fail | ||
| await expect( | ||
| fixture.aws.sts.send(new AssumeRoleCommand({ | ||
| RoleArn: deployRoleArn, | ||
| RoleSessionName: 'test-external-id-failure', | ||
| ExternalId: 'some-external-id', | ||
| })), | ||
| ).resolves.toBeTruthy(); | ||
| })); |
This file contains hidden or 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 hidden or 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 hidden or 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
73 changes: 73 additions & 0 deletions
73
packages/@aws-cdk/toolkit-lib/test/api/bootstrap/external-id.test.ts
This file contains hidden or 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,73 @@ | ||
| import { Bootstrapper } from '../../../lib/api/bootstrap'; | ||
| import type { IIoHost } from '../../../lib/api/io'; | ||
| import { asIoHelper } from '../../../lib/api/io/private'; | ||
|
|
||
| describe('ExternalId Protection Integration Test', () => { | ||
| let ioHost: IIoHost; | ||
| let ioHelper: any; | ||
|
|
||
| beforeEach(() => { | ||
| ioHost = { | ||
| notify: jest.fn(), | ||
| requestResponse: jest.fn(), | ||
| }; | ||
| ioHelper = asIoHelper(ioHost, 'bootstrap'); | ||
| }); | ||
|
|
||
| test('bootstrap template denies AssumeRole with ExternalId by default', async () => { | ||
| // GIVEN | ||
| const bootstrapper = new Bootstrapper({ source: 'default' }, ioHelper); | ||
|
|
||
| // WHEN | ||
| const template = await (bootstrapper as any).loadTemplate(); | ||
|
|
||
| // THEN | ||
| // Verify the parameter exists | ||
| expect(template.Parameters.DenyExternalId).toMatchObject({ | ||
| Type: 'String', | ||
| Default: 'true', | ||
| AllowedValues: ['true', 'false'], | ||
| }); | ||
|
|
||
| // Verify the condition exists | ||
| expect(template.Conditions.ShouldDenyExternalId).toEqual({ | ||
| 'Fn::Equals': ['true', { Ref: 'DenyExternalId' }], | ||
| }); | ||
|
|
||
| // Verify each role has the ExternalId condition | ||
| const rolesToCheck = [ | ||
| 'FilePublishingRole', | ||
| 'ImagePublishingRole', | ||
| 'LookupRole', | ||
| 'DeploymentActionRole', | ||
| ]; | ||
|
|
||
| for (const roleName of rolesToCheck) { | ||
| const role = template.Resources[roleName]; | ||
| expect(role).toBeDefined(); | ||
|
|
||
| // Find AssumeRole statements for AWS principals (not service principals) | ||
| const assumeRoleStatements = role.Properties.AssumeRolePolicyDocument.Statement.filter( | ||
| (stmt: any) => stmt.Action === 'sts:AssumeRole' && stmt.Principal?.AWS, | ||
| ); | ||
|
|
||
| // Each AssumeRole statement should have the ExternalId condition | ||
| for (const stmt of assumeRoleStatements) { | ||
| expect(stmt.Condition).toEqual({ | ||
| 'Fn::If': [ | ||
| 'ShouldDenyExternalId', | ||
| { Null: { 'sts:ExternalId': 'true' } }, | ||
| { Ref: 'AWS::NoValue' }, | ||
| ], | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| // Verify CloudFormationExecutionRole does NOT have the condition (it's assumed by service) | ||
| const cfnRole = template.Resources.CloudFormationExecutionRole; | ||
| const cfnStatements = cfnRole.Properties.AssumeRolePolicyDocument.Statement; | ||
| for (const stmt of cfnStatements) { | ||
| expect(stmt.Condition).toBeUndefined(); | ||
| } | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Q: Should this just be a warning?
Q: Should we apply this to EVERY paramter?
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.
A1: Perhaps. But we're making a clear distinction between passing the value and not passing it. If you pass the value, I don't think we'd want to drop it with only a warning.
A2: Perhaps. Hasn't caused a problem so far, so I'm not going to be holier than the pope without any customer pressure.