feat(code pipeline): basic cross-account support #1529
Closed
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.
Support for cross-account deployments, and cross-account artifacts replication.
Overview
The work should enable to construct stacks simillar to one described in
reference architecture
https://github.com/awslabs/aws-refarch-cross-account-pipeline
In such a case foreign role have to have access to stored artifacts
in S3 buckets. However in order to achieve this two things must be achieved
artifacts in above bucket (which is impossible to do with AWS managed
one).
Because names of buckets and KMS key aliases have to be known upfront to pass
those in cross region fashion between underlying Cloud Formation
templates, those are derived from pipeline name (similarly as it's right
for scaffold buckets).
As KMS keys doesn't have name the alias to key is used and it's passed
as configuration to pipeline artifact store, so replicated
artifacts will be encrypted with those keys.
Pipeline tries to whitelist foreign accounts on artifacts stores (buckets
and KMS keys), by adding foreign account root principal to resource
policy.
Changes
Add account attribute to action, and treat it in similar way
as it's right now for region.
Introduced new constructs
ArtifactsStore
andImportedArtifactsStore
to encapsulate artifact store (S3 bucket and KMS key), and simplify
managing of stores.
When action is attached to pipeline, check if it's from foreign account,
check if artifact store exists for this region and account. If it doesn't
than create new scaffold stack. Each artifact store created by pipeline
is considered pipeline managed.
If artifact store is pipeline managed whitelist foreign account (add
appropriate resource policy to S3 bucket and KMS key).
When granting permissions to pipeline's artifact bucket
(
grantBucketRead/Write
), store those n list and grant when pipelineis rendered. It's driven by two factors:
all stores has been created;
performed only on imported store to add grants in IAM principal
policy, and not in resource policy (scaffold stacks are deployed
before actual role can be deployed)
Changes to S3 allowing grant to
ArnPrincipal
(would updated onlyresource policy)
Sample workflow
Together with #1449 customers should be able
to create on their own roles, and import those in pipeline stack. When
Some parts of this workflow could be automated, however even without it users would
be enabled to create cross-account pipelines.
(feat(aws-codepipeline): support for pipeline action’s service role #1449) this role would mainly allow
passing Cloud Formation deployment role;
artifact store and pass it to Project Build action,
as Project Build by default encrypts output
with
aws/s3
key (even if default key is set on bucket)TODO
In many places
kms:*
actions are allowed (those should be narrowed to onlythose required for encryption, decryption and alias dereference).
Eventually, use tags and conditional statements to widen access to KMS keys;
Right now all KMS keys are granted for principals (in order to allow
principal access to particular key it's UUID has to be known, alias
can't be used in-place)
Project build action requires passing key from pipeline, otherwise artifacts will not get
replicated, as build action will use default
aws/s3
key.