Skip to content
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

feat(codepipeline): cross-environment (account+region) actions #3694

Merged

Conversation

skinny85
Copy link
Contributor

@skinny85 skinny85 commented Aug 17, 2019

This changes the scaffolding stack logic for the cross-region CodePipelines to include a KMS key and alias as part of it, which are required if an action is simultaneously cross-region and cross-account. We also change to use the KMS key ID instead of the key ARN when rendering the ArtifactStores property.

We also add an alias to the default pipeline artifact bucket.

This required a bunch of changes to the KMS and S3 modules:

  • Alias now implements IKey
  • Added the keyId property to IKey
  • Added removalPolicy property to Alias
  • Granting permissions to a key works if the principal belongs to a stack that is a dependent of the key stack
  • Allow specifying a key when importing a bucket

Fixes #52
Concerns #1584
Fixes #2517
Fixes #2569
Concerns #3275
Fixes #3138
Fixes #3388


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@mergify
Copy link
Contributor

mergify bot commented Aug 17, 2019

Pull Request Checklist

  • Testing
  • Unit test added (prefer to add a new test rather than modify existing tests)
  • CLI change? Re-run/add CLI integration tests
  • Documentation
  • Inline docs: make sure all public APIs are documented (copy & paste from official AWS docs)
  • README: update module README
  • Design: for significant features, follow the design process
  • Title uses the format type(scope): text
  • Type: fix, feat, refactor go into CHANGELOG, chore is hidden
  • Scope: name of the module without the aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
  • Style: use all lower-case, do not end with a period
  • Description
  • Rationale: describe rationale of change and approach taken
  • Issues: Indicate issues fixed via: fixes #xxx or closes #xxx
  • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Sensitive Modules (requires 2 PR approvers)
  • IAM document library (in @aws-cdk/aws-iam)
  • EC2 security groups and ACLs (in @aws-cdk/aws-ec2)
  • Grant APIs (if not based on official documentation with a reference)

@mergify
Copy link
Contributor

mergify bot commented Aug 17, 2019

Codebuild (Continuous Integration) build failed for current commits. Please check log and resolve before PR is merged.

1 similar comment
@mergify
Copy link
Contributor

mergify bot commented Aug 17, 2019

Codebuild (Continuous Integration) build failed for current commits. Please check log and resolve before PR is merged.

@skinny85 skinny85 added the pr/do-not-merge This PR should not be merged at this time. label Aug 17, 2019
@skinny85 skinny85 mentioned this pull request Aug 17, 2019
5 tasks
@mergify
Copy link
Contributor

mergify bot commented Aug 17, 2019

Codebuild (Continuous Integration) build failed for current commits. Please check log and resolve before PR is merged.

@mergify
Copy link
Contributor

mergify bot commented Aug 19, 2019

Pull Request Checklist

  • Testing
  • Unit test added (prefer to add a new test rather than modify existing tests)
  • CLI change? Re-run/add CLI integration tests
  • Documentation
  • Inline docs: make sure all public APIs are documented (copy & paste from official AWS docs)
  • README: update module README
  • Design: for significant features, follow the design process
  • Title uses the format type(scope): text
  • Type: fix, feat, refactor go into CHANGELOG, chore is hidden
  • Scope: name of the module without the aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
  • Style: use all lower-case, do not end with a period
  • Description
  • Rationale: describe rationale of change and approach taken
  • Issues: Indicate issues fixed via: fixes #xxx or closes #xxx
  • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Sensitive Modules (requires 2 PR approvers)
  • IAM document library (in @aws-cdk/aws-iam)
  • EC2 security groups and ACLs (in @aws-cdk/aws-ec2)
  • Grant APIs (if not based on official documentation with a reference)

@skinny85 skinny85 force-pushed the feat/cross-region-and-account-cfn-pipelines branch from c5ac2d8 to 65b7cd3 Compare August 19, 2019 20:27
@skinny85
Copy link
Contributor Author

Updated the decdk test.

new kms.Alias(this, 'ArtifactsBucketEncryptionKeyAlias', {
aliasName: this.generateNameForDefaultBucketKeyAlias(),
targetKey: encryptionKey,
removalPolicy: RemovalPolicy.RETAIN, // alias should be retained, like the key
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that not mean that destroying and redeploying the stack will fail?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but that was always true, even before adding the Alias (because of the orphaned, physically-named S3 Bucket backing the Pipeline).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pinging about this.

@skinny85 skinny85 force-pushed the feat/cross-region-and-account-cfn-pipelines branch from 65b7cd3 to 2556de0 Compare August 22, 2019 18:04
@skinny85
Copy link
Contributor Author

skinny85 commented Aug 22, 2019

Added retention policy Retain to the scaffold Alias.

@mergify
Copy link
Contributor

mergify bot commented Aug 22, 2019

Codebuild (Continuous Integration) build failed for current commits. Please check log and resolve before PR is merged.

@mergify
Copy link
Contributor

mergify bot commented Aug 23, 2019

Pull Request Checklist

  • Testing
  • Unit test added (prefer to add a new test rather than modify existing tests)
  • CLI change? Re-run/add CLI integration tests
  • Documentation
  • Inline docs: make sure all public APIs are documented (copy & paste from official AWS docs)
  • README: update module README
  • Design: for significant features, follow the design process
  • Title uses the format type(scope): text
  • Type: fix, feat, refactor go into CHANGELOG, chore is hidden
  • Scope: name of the module without the aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
  • Style: use all lower-case, do not end with a period
  • Description
  • Rationale: describe rationale of change and approach taken
  • Issues: Indicate issues fixed via: fixes #xxx or closes #xxx
  • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Sensitive Modules (requires 2 PR approvers)
  • IAM document library (in @aws-cdk/aws-iam)
  • EC2 security groups and ACLs (in @aws-cdk/aws-ec2)
  • Grant APIs (if not based on official documentation with a reference)

rix0rrr
rix0rrr previously approved these changes Aug 23, 2019
@mergify
Copy link
Contributor

mergify bot commented Aug 28, 2019

Pull Request Checklist

  • Testing
  • Unit test added (prefer to add a new test rather than modify existing tests)
  • CLI change? Re-run/add CLI integration tests
  • Documentation
  • Inline docs: make sure all public APIs are documented (copy & paste from official AWS docs)
  • README: update module README
  • Design: for significant features, follow the design process
  • Title uses the format type(scope): text
  • Type: fix, feat, refactor go into CHANGELOG, chore is hidden
  • Scope: name of the module without the aws- or cdk- prefix or postfix (e.g. s3 instead of aws-s3-deployment)
  • Style: use all lower-case, do not end with a period
  • Description
  • Rationale: describe rationale of change and approach taken
  • Issues: Indicate issues fixed via: fixes #xxx or closes #xxx
  • Breaking?: last paragraph: BREAKING CHANGE: <describe what changed + link for details>
  • Sensitive Modules (requires 2 PR approvers)
  • IAM document library (in @aws-cdk/aws-iam)
  • EC2 security groups and ACLs (in @aws-cdk/aws-ec2)
  • Grant APIs (if not based on official documentation with a reference)

Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the title talks about "simultaneous". You basically mean "support cross account and region actions"?

const replicationBucket = new s3.Bucket(replicationStack, 'ReplicationBucket', {
// like was said above - replication buckets need a set physical name
bucketName: PhysicalName.GENERATE_IF_NEEDED,
encryptionKey: key, // does not work!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what "does not work!" mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll get a "Can only reference cross stacks in the same region and account." error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow up with @jerry-aws in a separate PR and revisit this doc. I think he will be able to help.

@@ -128,6 +133,53 @@ $ cdk deploy MyMainStack
See [the AWS docs here](https://docs.aws.amazon.com/codepipeline/latest/userguide/actions-create-cross-region.html)
for more information on cross-region CodePipelines.

#### Creating an encrypted replication bucket

If you're passing a replication bucket created in a different stack,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This documentation is weird. Should mostly describe how to do things and not what doesn't work...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted to point out a potential "gotcha!" that might trip people up.

If you have a suggestion how to re-structure this documentation, I'm all ears.

eladb
eladb previously requested changes Aug 29, 2019
Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need a walk through this code. I am really struggling to understand what's going on here (it's me!).
Any chance you can schedule some time next week?

packages/@aws-cdk/aws-kms/lib/alias.ts Outdated Show resolved Hide resolved
// This is a problem if the stack the grantee is part of depends on the key stack
// (as it won't exist before the key policy is attempted to be created).
// In that case, make the account the resource policy principal
const granteeStackDependsOnKeyStack = this.granteeStackDependsOnKeyStack(grantee);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have some doc reference (or appsec consultation) that this is the best practice?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would you suggest as an alternative here, given the comment?

packages/@aws-cdk/aws-kms/lib/key.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-kms/lib/key.ts Show resolved Hide resolved
packages/@aws-cdk/aws-kms/test/test.key.ts Show resolved Hide resolved
@@ -160,7 +167,7 @@ export class Grant {
const statement = new PolicyStatement({
actions: options.actions,
resources: (options.resourceSelfArns || options.resourceArns),
principals: [options.grantee!.grantPrincipal]
principals: [options.resourcePolicyPrincipal || options.grantee!.grantPrincipal]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing test for this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have separate tests in the IAM library for methods like addToPrincipalAndResource - they're exercised only through tests in the particular Construct Libraries that use them. I'd rather not add them as part of this change. With the KMS test added above, this is now covered as well.

@skinny85
Copy link
Contributor Author

Why is the title talks about "simultaneous". You basically mean "support cross account and region actions"?

"Simultaneous" means "at the same time", because this PR deals specifically with actions that are both cross-region and cross-account at the same time. "Simultaneous" is just shorter.

@skinny85 skinny85 force-pushed the feat/cross-region-and-account-cfn-pipelines branch from 2556de0 to e71e78c Compare September 10, 2019 01:45
@mergify mergify bot dismissed stale reviews from rix0rrr and eladb September 10, 2019 01:46

Pull request has been modified.

@skinny85
Copy link
Contributor Author

Updated with feedback from comments & rebased.

@eladb eladb changed the title feat(codepipeline): support simultaneous cross-account and cross-region actions feat(codepipeline): cross-environment (account+region) actions Sep 10, 2019
eladb
eladb previously approved these changes Sep 10, 2019
packages/@aws-cdk/aws-kms/lib/key.ts Show resolved Hide resolved
const replicationBucket = new s3.Bucket(replicationStack, 'ReplicationBucket', {
// like was said above - replication buckets need a set physical name
bucketName: PhysicalName.GENERATE_IF_NEEDED,
encryptionKey: key, // does not work!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please follow up with @jerry-aws in a separate PR and revisit this doc. I think he will be able to help.

@mergify
Copy link
Contributor

mergify bot commented Sep 10, 2019

Continuous integration build failed

@mergify mergify bot dismissed eladb’s stale review September 10, 2019 18:41

Pull request has been modified.

@skinny85 skinny85 force-pushed the feat/cross-region-and-account-cfn-pipelines branch from 73df832 to 898cd8e Compare September 10, 2019 22:45
@skinny85
Copy link
Contributor Author

Fixed the Import class in fromKeyArn and rebased over 1.8.0.

@skinny85 skinny85 merged commit 69bff3d into aws:master Sep 11, 2019
@skinny85 skinny85 deleted the feat/cross-region-and-account-cfn-pipelines branch September 11, 2019 00:15
@skinny85
Copy link
Contributor Author

Please follow up with @jerry-aws in a separate PR and revisit this doc. I think he will be able to help.

Done: #4031

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS. pr/do-not-merge This PR should not be merged at this time.
Projects
None yet
4 participants