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

fix(kms): cross-environment usage fails when trustAccountIdentities is set #12925

Merged
merged 4 commits into from
Feb 9, 2021

Conversation

njlynch
Copy link
Contributor

@njlynch njlynch commented Feb 8, 2021

When the trustAccountIdentities flag is set (either directly, or set by
default via the @aws-cdk/aws-kms:defaultKeyPolicies feature flag), any grant
statements are always added to the principal OR resource, defaulting to the
principal if possible.

In cross-environment usage, this means that the principal IAM policy is updated,
but the key policy is never updated. However, cross-environment usage always
requires the key policy to be updated. Attempting to use the key in a
cross-environment usage with trustAccountIdentities enabled initially presents
itself as a cross-environment reference issue, but even if the stack was
successfully deployed, the delegated account would not have access to use/admin
the key.

This change updates the logic to make use of the existing cross-environment
logic whenever cross-environment usage is detected, regardless of the value of
trustAccountIdentities. This has the impact of fixing the cross-env references
and ensuring the key policy is properly updated.

fixes #12921, fixes #12741


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

…s set

When the `trustAccountIdentities` flag is set (either directly, or set by
default via the `@aws-cdk/aws-kms:defaultKeyPolicies` feature flag), any grant
statements are always added to the principal OR resource, defaulting to the
principal if possible.

In cross-environment usage, this means that the principal IAM policy is updated,
but the key policy is never updated. However, cross-environment usage always
requires the key policy to be updated. Attempting to use the key in a
cross-environment usage with `trustAccountIdentities` enabled initially presents
itself as a cross-environment reference issue, but even if the stack was
successfully deployed, the delegated account would not have access to use/admin
the key.

This change updates the logic to make use of the existing cross-environment
logic whenever cross-environment usage is detected, regardless of the value of
`trustAccountIdentities`. This has the impact of fixing the cross-env references
and ensuring the key policy is properly updated.

fixes #12921
@njlynch njlynch requested a review from a team February 8, 2021 15:29
@njlynch njlynch self-assigned this Feb 8, 2021
@gitpod-io
Copy link

gitpod-io bot commented Feb 8, 2021

@github-actions github-actions bot added the @aws-cdk/aws-kms Related to AWS Key Management label Feb 8, 2021
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Feb 8, 2021
@nija-at nija-at added the pr/do-not-merge This PR should not be merged at this time. label Feb 8, 2021
packages/@aws-cdk/aws-kms/test/key.test.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-kms/test/key.test.ts Show resolved Hide resolved
@njlynch njlynch removed the pr/do-not-merge This PR should not be merged at this time. label Feb 8, 2021
@mergify
Copy link
Contributor

mergify bot commented Feb 9, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: 9327bd4
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Feb 9, 2021

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 2b917ec into master Feb 9, 2021
@mergify mergify bot deleted the njlynch/kms-cross-account-usage branch February 9, 2021 11:47
nija-at pushed a commit that referenced this pull request Feb 9, 2021
…s set (#12925)

When the `trustAccountIdentities` flag is set (either directly, or set by
default via the `@aws-cdk/aws-kms:defaultKeyPolicies` feature flag), any grant
statements are always added to the principal OR resource, defaulting to the
principal if possible.

In cross-environment usage, this means that the principal IAM policy is updated,
but the key policy is never updated. However, cross-environment usage always
requires the key policy to be updated. Attempting to use the key in a
cross-environment usage with `trustAccountIdentities` enabled initially presents
itself as a cross-environment reference issue, but even if the stack was
successfully deployed, the delegated account would not have access to use/admin
the key.

This change updates the logic to make use of the existing cross-environment
logic whenever cross-environment usage is detected, regardless of the value of
`trustAccountIdentities`. This has the impact of fixing the cross-env references
and ensuring the key policy is properly updated.

fixes #12921, fixes #12741


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
nija-at pushed a commit that referenced this pull request Feb 9, 2021
…s set (#12925)

When the `trustAccountIdentities` flag is set (either directly, or set by
default via the `@aws-cdk/aws-kms:defaultKeyPolicies` feature flag), any grant
statements are always added to the principal OR resource, defaulting to the
principal if possible.

In cross-environment usage, this means that the principal IAM policy is updated,
but the key policy is never updated. However, cross-environment usage always
requires the key policy to be updated. Attempting to use the key in a
cross-environment usage with `trustAccountIdentities` enabled initially presents
itself as a cross-environment reference issue, but even if the stack was
successfully deployed, the delegated account would not have access to use/admin
the key.

This change updates the logic to make use of the existing cross-environment
logic whenever cross-environment usage is detected, regardless of the value of
`trustAccountIdentities`. This has the impact of fixing the cross-env references
and ensuring the key policy is properly updated.

fixes #12921, fixes #12741


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
TLadd pushed a commit to TLadd/aws-cdk that referenced this pull request Feb 9, 2021
…s set (aws#12925)

When the `trustAccountIdentities` flag is set (either directly, or set by
default via the `@aws-cdk/aws-kms:defaultKeyPolicies` feature flag), any grant
statements are always added to the principal OR resource, defaulting to the
principal if possible.

In cross-environment usage, this means that the principal IAM policy is updated,
but the key policy is never updated. However, cross-environment usage always
requires the key policy to be updated. Attempting to use the key in a
cross-environment usage with `trustAccountIdentities` enabled initially presents
itself as a cross-environment reference issue, but even if the stack was
successfully deployed, the delegated account would not have access to use/admin
the key.

This change updates the logic to make use of the existing cross-environment
logic whenever cross-environment usage is detected, regardless of the value of
`trustAccountIdentities`. This has the impact of fixing the cross-env references
and ensuring the key policy is properly updated.

fixes aws#12921, fixes aws#12741


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
NovakGu pushed a commit to NovakGu/aws-cdk that referenced this pull request Feb 18, 2021
…s set (aws#12925)

When the `trustAccountIdentities` flag is set (either directly, or set by
default via the `@aws-cdk/aws-kms:defaultKeyPolicies` feature flag), any grant
statements are always added to the principal OR resource, defaulting to the
principal if possible.

In cross-environment usage, this means that the principal IAM policy is updated,
but the key policy is never updated. However, cross-environment usage always
requires the key policy to be updated. Attempting to use the key in a
cross-environment usage with `trustAccountIdentities` enabled initially presents
itself as a cross-environment reference issue, but even if the stack was
successfully deployed, the delegated account would not have access to use/admin
the key.

This change updates the logic to make use of the existing cross-environment
logic whenever cross-environment usage is detected, regardless of the value of
`trustAccountIdentities`. This has the impact of fixing the cross-env references
and ensuring the key policy is properly updated.

fixes aws#12921, fixes aws#12741


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-kms Related to AWS Key Management contribution/core This is a PR that came from AWS.
Projects
None yet
3 participants