|
3 | 3 | import * as deployStack from '../../../lib/api/deployments/deploy-stack';
|
4 | 4 | import type { Stack } from '@aws-sdk/client-cloudformation';
|
5 | 5 | import { CreatePolicyCommand, GetPolicyCommand } from '@aws-sdk/client-iam';
|
| 6 | +import { Match, Template } from 'aws-cdk-lib/assertions'; |
| 7 | + |
6 | 8 | import {
|
7 | 9 | mockBootstrapStack,
|
8 | 10 | mockIAMClient,
|
@@ -642,4 +644,93 @@ describe('Bootstrapping v2', () => {
|
642 | 644 | },
|
643 | 645 | );
|
644 | 646 | });
|
| 647 | + |
| 648 | + describe('contains sts:TagSession on trusted accounts', () => { |
| 649 | + let template: Template; |
| 650 | + |
| 651 | + const iamRoleName = (name: string) => { |
| 652 | + return { |
| 653 | + 'Fn::Sub': `cdk-\${Qualifier}-${name}-\${AWS::AccountId}-\${AWS::Region}`, |
| 654 | + }; |
| 655 | + }; |
| 656 | + |
| 657 | + const statementWithCondition = (conditionName: string) => { |
| 658 | + return Match.objectLike({ |
| 659 | + 'Fn::If': Match.arrayWith([ |
| 660 | + conditionName, |
| 661 | + Match.objectLike({ |
| 662 | + Action: Match.arrayWith(['sts:AssumeRole', 'sts:TagSession']), |
| 663 | + }), |
| 664 | + ]), |
| 665 | + }); |
| 666 | + }; |
| 667 | + |
| 668 | + beforeEach(async () => { |
| 669 | + let rawTemplate: any; |
| 670 | + mockDeployStack.mockImplementation((args: deployStack.DeployStackOptions) => { |
| 671 | + rawTemplate = args.stack.template; |
| 672 | + return Promise.resolve({ |
| 673 | + type: 'did-deploy-stack', |
| 674 | + noOp: false, |
| 675 | + outputs: {}, |
| 676 | + stackArn: 'arn:stack', |
| 677 | + }); |
| 678 | + }); |
| 679 | + await bootstrapper.bootstrapEnvironment(env, sdk, {}); |
| 680 | + template = Template.fromJSON(rawTemplate); |
| 681 | + }); |
| 682 | + |
| 683 | + test('in the FilePublishingRole', async () => { |
| 684 | + template.hasResource('AWS::IAM::Role', { |
| 685 | + Properties: { |
| 686 | + RoleName: iamRoleName('file-publishing-role'), |
| 687 | + AssumeRolePolicyDocument: { |
| 688 | + Statement: Match.arrayWith([ |
| 689 | + statementWithCondition('HasTrustedAccounts'), |
| 690 | + ]), |
| 691 | + }, |
| 692 | + }, |
| 693 | + }); |
| 694 | + }); |
| 695 | + |
| 696 | + test('in the ImagePublishingRole', async () => { |
| 697 | + template.hasResource('AWS::IAM::Role', { |
| 698 | + Properties: { |
| 699 | + RoleName: iamRoleName('image-publishing-role'), |
| 700 | + AssumeRolePolicyDocument: { |
| 701 | + Statement: Match.arrayWith([ |
| 702 | + statementWithCondition('HasTrustedAccounts'), |
| 703 | + ]), |
| 704 | + }, |
| 705 | + }, |
| 706 | + }); |
| 707 | + }); |
| 708 | + |
| 709 | + test('in the LookupRole', async () => { |
| 710 | + template.hasResource('AWS::IAM::Role', { |
| 711 | + Properties: { |
| 712 | + RoleName: iamRoleName('lookup-role'), |
| 713 | + AssumeRolePolicyDocument: { |
| 714 | + Statement: Match.arrayWith([ |
| 715 | + statementWithCondition('HasTrustedAccountsForLookup'), |
| 716 | + statementWithCondition('HasTrustedAccounts'), |
| 717 | + ]), |
| 718 | + }, |
| 719 | + }, |
| 720 | + }); |
| 721 | + }); |
| 722 | + |
| 723 | + test('in the DeploymentActionRole', async () => { |
| 724 | + template.hasResource('AWS::IAM::Role', { |
| 725 | + Properties: { |
| 726 | + RoleName: iamRoleName('deploy-role'), |
| 727 | + AssumeRolePolicyDocument: { |
| 728 | + Statement: Match.arrayWith([ |
| 729 | + statementWithCondition('HasTrustedAccounts'), |
| 730 | + ]), |
| 731 | + }, |
| 732 | + }, |
| 733 | + }); |
| 734 | + }); |
| 735 | + }); |
645 | 736 | });
|
0 commit comments