Skip to content

Commit

Permalink
feat(codepipeline): change default value for crossAccountKeys to fals…
Browse files Browse the repository at this point in the history
…e (under feature flag) (#28556)

[The documentation](https://github.com/aws/aws-cdk/blob/f4c1d1253ee34c2837a57a93faa47c9da97ef6d8/packages/aws-cdk-lib/aws-codepipeline/lib/pipeline.ts#L380-L381) mentions updating the default for CDK v2. Sounds like we should add it in with feature flag.

Closes #28247.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
go-to-k authored and TheRealAmazonKendra committed Feb 9, 2024
1 parent db3dbbf commit 4c3b931
Show file tree
Hide file tree
Showing 28 changed files with 153 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const prodStage = {
};

new codepipeline.Pipeline(stack, 'Pipeline', {
crossAccountKeys: true,
stages: [
sourceStage,
prodStage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ new lambda.Function(lambdaStack, 'Lambda', {
// other resources that your Lambda needs, added to the lambdaStack...

const pipelineStack = new cdk.Stack(app, 'PipelineStack');
const pipeline = new codepipeline.Pipeline(pipelineStack, 'Pipeline');
const pipeline = new codepipeline.Pipeline(pipelineStack, 'Pipeline', {
crossAccountKeys: true,
});

// add the source code repository containing this code to your Pipeline,
// and the source code of the Lambda Function, if they're separate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const app = new cdk.App();

const stack = new cdk.Stack(app, 'aws-cdk-codepipeline-lambda');

const pipeline = new codepipeline.Pipeline(stack, 'Pipeline');
const pipeline = new codepipeline.Pipeline(stack, 'Pipeline', {
crossAccountKeys: true,
});

const sourceStage = pipeline.addStage({ stageName: 'Source' });
const bucket = new s3.Bucket(stack, 'PipelineBucket', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const deployStage = {
};

new codepipeline.Pipeline(stack, 'Pipeline', {
crossAccountKeys: true,
stages: [
sourceStage,
deployStage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ const app = new cdk.App();

const stack = new cdk.Stack(app, 'aws-cdk-codepipeline-cloudformation');

const pipeline = new codepipeline.Pipeline(stack, 'Pipeline');
const pipeline = new codepipeline.Pipeline(stack, 'Pipeline', {
crossAccountKeys: true,
});

const bucket = new s3.Bucket(stack, 'PipelineBucket', {
versioned: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const testAction = new cpactions.CodeBuildAction({
});

new codepipeline.Pipeline(stack, 'Pipeline', {
crossAccountKeys: true,
stages: [
{
stageName: 'source',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const eventPattern

const pipeline = new codepipeline.Pipeline(stack, 'Pipeline', {
pipelineName: 'IntegCustomEventPipeline',
crossAccountKeys: true,
stages: [
{
stageName: 'source',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const repo = new codecommit.Repository(stack, 'MyRepo', {
});

new codepipeline.Pipeline(stack, 'Pipeline', {
crossAccountKeys: true,
stages: [
{
stageName: 'source',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const repo = new codecommit.Repository(stack, 'MyRepo', {
});

new codepipeline.Pipeline(stack, 'Pipeline', {
crossAccountKeys: true,
stages: [
{
stageName: 'source',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const app = new cdk.App();

const stack = new cdk.Stack(app, 'aws-cdk-pipeline-event-target');

const pipeline = new codepipeline.Pipeline(stack, 'MyPipeline');
const pipeline = new codepipeline.Pipeline(stack, 'MyPipeline', {
crossAccountKeys: true,
});

const repository = new codecommit.Repository(stack, 'CodeCommitRepo', {
repositoryName: 'foo',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const simpleStateMachine = new stepfunctions.StateMachine(stack, 'SimpleStateMac
definition: startState,
});

const pipeline = new codepipeline.Pipeline(stack, 'MyPipeline');
const pipeline = new codepipeline.Pipeline(stack, 'MyPipeline', {
crossAccountKeys: true,
});
pipeline.addStage({
stageName: 'Source',
actions: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const bucket = new Bucket(stack1, 'ReplicationBucket', {

const artifact = new Artifact();
const pipeline = new Pipeline(stack2, 'Pipeline', {
crossAccountKeys: true,
crossRegionReplicationBuckets: {
'us-east-1': bucket,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const bucket = new s3.Bucket(bucketStack, 'Bucket', {
const pipelineStack = new Stack(app, 'PipelineStack');
const sourceOutput = new codepipeline.Artifact();
new codepipeline.Pipeline(pipelineStack, 'Pipeline', {
crossAccountKeys: true,
stages: [
{
stageName: 'Source',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ const repo = new codecommit.Repository(stack, 'Repo', {
repositoryName: 'TestRepository',
});

const pipeline = new codepipeline.Pipeline(stack, 'pipelinePipeline22F2A91D');
const pipeline = new codepipeline.Pipeline(stack, 'pipelinePipeline22F2A91D', {
crossAccountKeys: true,
});

const srcArtifact = new codepipeline.Artifact('Src');
pipeline.addStage({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class TestCdkStack extends Stack {
});

const pipeline = new cdkp.CdkPipeline(this, 'TestPipeline', {
crossAccountKeys: true,
selfMutating: false,
pipelineName: 'TestPipeline',
cloudAssemblyArtifact,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class CdkpipelinesDemoPipelineStack extends Stack {
autoDeleteObjects: true,
});
const pipeline = new cdkp.CdkPipeline(this, 'Pipeline', {
crossAccountKeys: true,
cloudAssemblyArtifact,
singlePublisherPerType: true,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class CdkpipelinesDemoPipelineStack extends Stack {
autoDeleteObjects: true,
});
const pipeline = new cdkp.CdkPipeline(this, 'Pipeline', {
crossAccountKeys: true,
cloudAssemblyArtifact,

// Where the source can be found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class CdkpipelinesDemoPipelineStack extends Stack {
autoDeleteObjects: true,
});
const pipeline = new cdkp.CdkPipeline(this, 'Pipeline', {
crossAccountKeys: true,
cloudAssemblyArtifact,

// Where the source can be found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ const deployAction = new S3DeployAction({
extract: true,
});
const pipeline = new Pipeline(stack, 'MyPipeline', {
crossAccountKeys: true,
stages: [
{
stageName: 'beta',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const deployment = new BucketDeployment(stack, 'BucketDeployment', {
],
});
const pipeline = new Pipeline(stack, 'Pipeline', {
crossAccountKeys: true,
stages: [
{
stageName: 'source',
Expand Down
20 changes: 19 additions & 1 deletion packages/@aws-cdk/cx-api/FEATURE_FLAGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Flags come in three types:
| [@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials](#aws-cdkaws-rdspreventrenderingdeprecatedcredentials) | When enabled, creating an RDS database cluster from a snapshot will only render credentials for snapshot credentials. | 2.98.0 | (fix) |
| [@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource](#aws-cdkaws-codepipeline-actionsusenewdefaultbranchforcodecommitsource) | When enabled, the CodeCommit source action is using the default branch name 'main'. | 2.103.1 | (fix) |
| [@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction](#aws-cdkaws-cloudwatch-actionschangelambdapermissionlogicalidforlambdaaction) | When enabled, the logical ID of a Lambda permission for a Lambda action includes an alarm ID. | 2.124.0 | (fix) |
| [@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse](#aws-cdkaws-codepipelinecrossaccountkeysdefaultvaluetofalse) | Enables Pipeline to set the default value for crossAccountKeys to false. | V2NEXT | (default) |

<!-- END table -->

Expand Down Expand Up @@ -118,7 +119,8 @@ The following json shows the current recommended set of flags, as `cdk init` wou
"@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true,
"@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true,
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true,
"@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": true
"@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": true,
"@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": true
}
}
```
Expand Down Expand Up @@ -1213,4 +1215,20 @@ If the flag is set to false then it can only make one alarm for the Lambda with
| 2.124.0 | `false` | `true` |


### @aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse

*Enables Pipeline to set the default value for crossAccountKeys to false.* (default)

When this feature flag is enabled, and the `crossAccountKeys` property is not provided in a `Pipeline`
construct, the construct automatically defaults the value of this property to false.


| Since | Default | Recommended |
| ----- | ----- | ----- |
| (not in v1) | | |
| V2NEXT | `false` | `true` |

**Compatibility with old behavior:** Pass `crossAccountKeys: true` to `Pipeline` construct to restore the previous behavior.


<!-- END details -->
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const prodStage = {
};

new codepipeline.Pipeline(stack, 'Pipeline', {
crossAccountKeys: true,
stages: [
sourceStage,
prodStage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ new lambda.Function(lambdaStack, 'Lambda', {
// other resources that your Lambda needs, added to the lambdaStack...

const pipelineStack = new cdk.Stack(app, 'PipelineStack');
const pipeline = new codepipeline.Pipeline(pipelineStack, 'Pipeline');
const pipeline = new codepipeline.Pipeline(pipelineStack, 'Pipeline', {
crossAccountKeys: true,
});

// add the source code repository containing this code to your Pipeline,
// and the source code of the Lambda Function, if they're separate
Expand Down
8 changes: 5 additions & 3 deletions packages/aws-cdk-lib/aws-codepipeline/lib/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ export interface PipelineProps {
* encrypted with an AWS-managed key). However, cross-account deployments will
* no longer be possible.
*
* @default true
* @default false - false if the feature flag `CODEPIPELINE_CROSS_ACCOUNT_KEYS_DEFAULT_VALUE_TO_FALSE`
* is true, true otherwise
*/
readonly crossAccountKeys?: boolean;

Expand Down Expand Up @@ -386,8 +387,9 @@ export class Pipeline extends PipelineBase {
throw new Error('Only one of artifactBucket and crossRegionReplicationBuckets can be specified!');
}

// @deprecated(v2): switch to default false
this.crossAccountKeys = props.crossAccountKeys ?? true;
// The feature flag is set to true by default for new projects, otherwise false.
this.crossAccountKeys = props.crossAccountKeys
?? (FeatureFlags.of(this).isEnabled(cxapi.CODEPIPELINE_CROSS_ACCOUNT_KEYS_DEFAULT_VALUE_TO_FALSE) ? false : true);
this.enableKeyRotation = props.enableKeyRotation;

// Cross account keys must be set for key rotation to be enabled
Expand Down
43 changes: 43 additions & 0 deletions packages/aws-cdk-lib/aws-codepipeline/test/pipeline.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,49 @@ describe('', () => {
'EnableKeyRotation': true,
});
});

test('crossAccountKeys as default value is set to false when feature flag is enabled', () => {
const app = new cdk.App();
app.node.setContext(cxapi.CODEPIPELINE_CROSS_ACCOUNT_KEYS_DEFAULT_VALUE_TO_FALSE, true);

const stack = new cdk.Stack(app, 'PipelineStack');
const sourceOutput = new codepipeline.Artifact();
new codepipeline.Pipeline(stack, 'Pipeline', {
stages: [
{
stageName: 'Source',
actions: [new FakeSourceAction({ actionName: 'Source', output: sourceOutput })],
},
{
stageName: 'Build',
actions: [new FakeBuildAction({ actionName: 'Build', input: sourceOutput })],
},
],
});

Template.fromStack(stack).resourceCountIs('AWS::KMS::Key', 0);
});

test('crossAccountKeys as default value is set to true when feature flag is not set', () => {
const app = new cdk.App();

const stack = new cdk.Stack(app, 'PipelineStack');
const sourceOutput = new codepipeline.Artifact();
new codepipeline.Pipeline(stack, 'Pipeline', {
stages: [
{
stageName: 'Source',
actions: [new FakeSourceAction({ actionName: 'Source', output: sourceOutput })],
},
{
stageName: 'Build',
actions: [new FakeBuildAction({ actionName: 'Build', input: sourceOutput })],
},
],
});

Template.fromStack(stack).resourceCountIs('AWS::KMS::Key', 1);
});
});
});

Expand Down
20 changes: 19 additions & 1 deletion packages/aws-cdk-lib/cx-api/FEATURE_FLAGS.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Flags come in three types:
| [@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials](#aws-cdkaws-rdspreventrenderingdeprecatedcredentials) | When enabled, creating an RDS database cluster from a snapshot will only render credentials for snapshot credentials. | 2.98.0 | (fix) |
| [@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource](#aws-cdkaws-codepipeline-actionsusenewdefaultbranchforcodecommitsource) | When enabled, the CodeCommit source action is using the default branch name 'main'. | 2.103.1 | (fix) |
| [@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction](#aws-cdkaws-cloudwatch-actionschangelambdapermissionlogicalidforlambdaaction) | When enabled, the logical ID of a Lambda permission for a Lambda action includes an alarm ID. | 2.124.0 | (fix) |
| [@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse](#aws-cdkaws-codepipelinecrossaccountkeysdefaultvaluetofalse) | Enables Pipeline to set the default value for crossAccountKeys to false. | V2NEXT | (default) |

<!-- END table -->

Expand Down Expand Up @@ -118,7 +119,8 @@ The following json shows the current recommended set of flags, as `cdk init` wou
"@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier": true,
"@aws-cdk/aws-rds:preventRenderingDeprecatedCredentials": true,
"@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource": true,
"@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": true
"@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction": true,
"@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": true
}
}
```
Expand Down Expand Up @@ -1213,4 +1215,20 @@ If the flag is set to false then it can only make one alarm for the Lambda with
| 2.124.0 | `false` | `true` |


### @aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse

*Enables Pipeline to set the default value for crossAccountKeys to false.* (default)

When this feature flag is enabled, and the `crossAccountKeys` property is not provided in a `Pipeline`
construct, the construct automatically defaults the value of this property to false.


| Since | Default | Recommended |
| ----- | ----- | ----- |
| (not in v1) | | |
| V2NEXT | `false` | `true` |

**Compatibility with old behavior:** Pass `crossAccountKeys: true` to `Pipeline` construct to restore the previous behavior.


<!-- END details -->
17 changes: 17 additions & 0 deletions packages/aws-cdk-lib/cx-api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,20 @@ _cdk.json_
}
}
```

* `@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse`

Enables Pipeline to set the default value for `crossAccountKeys` to false.

When this feature flag is enabled, and the `crossAccountKeys` property is not provided in a `Pipeline`
construct, the construct automatically defaults the value of this property to false.

_cdk.json_

```json
{
"context": {
"@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse": true
}
}
```
14 changes: 14 additions & 0 deletions packages/aws-cdk-lib/cx-api/lib/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const AURORA_CLUSTER_CHANGE_SCOPE_OF_INSTANCE_PARAMETER_GROUP_WITH_EACH_P
export const APPSYNC_ENABLE_USE_ARN_IDENTIFIER_SOURCE_API_ASSOCIATION = '@aws-cdk/aws-appsync:useArnForSourceApiAssociationIdentifier';
export const CODECOMMIT_SOURCE_ACTION_DEFAULT_BRANCH_NAME = '@aws-cdk/aws-codepipeline-actions:useNewDefaultBranchForCodeCommitSource';
export const LAMBDA_PERMISSION_LOGICAL_ID_FOR_LAMBDA_ACTION = '@aws-cdk/aws-cloudwatch-actions:changeLambdaPermissionLogicalIdForLambdaAction';
export const CODEPIPELINE_CROSS_ACCOUNT_KEYS_DEFAULT_VALUE_TO_FALSE = '@aws-cdk/aws-codepipeline:crossAccountKeysDefaultValueToFalse';

export const FLAGS: Record<string, FlagInfo> = {
//////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -993,6 +994,19 @@ export const FLAGS: Record<string, FlagInfo> = {
introducedIn: { v2: '2.124.0' },
recommendedValue: true,
},

//////////////////////////////////////////////////////////////////////
[CODEPIPELINE_CROSS_ACCOUNT_KEYS_DEFAULT_VALUE_TO_FALSE]: {
type: FlagType.ApiDefault,
summary: 'Enables Pipeline to set the default value for crossAccountKeys to false.',
detailsMd: `
When this feature flag is enabled, and the \`crossAccountKeys\` property is not provided in a \`Pipeline\`
construct, the construct automatically defaults the value of this property to false.
`,
introducedIn: { v2: 'V2NEXT' },
recommendedValue: true,
compatibilityWithOldBehaviorMd: 'Pass `crossAccountKeys: true` to `Pipeline` construct to restore the previous behavior.',
},
};

const CURRENT_MV = 'v2';
Expand Down

0 comments on commit 4c3b931

Please sign in to comment.