-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
(aws-cdk.aws-kms): Granting cross account access to imported kms #17341
Comments
This is bit tricky as CloudFormation, and hence CDK, doesn't allow cross account/cross stage references because CloudFormation export doesn't work cross account as far as my understanding goes. All these patterns of "centralised" resources fall into that category - ie. resource in one account (or a stage in CDK) referenced by other stages. If the resource is created outside the context of CDK (like via console), then you might as well hardcode the names/arns/etc. throughout the CDK code where its used and that should be sufficient.
It gets more interesting if the creation is also done in the CDK code itself (ie. managed by CloudFormation - not done separately via console/aws-cli etc.). In this case, many times you wouldn't "know" the exact ARNs as the physical-id would be generated by CloudFormation and likely be a part of the ARN. Even influencing the physical-id yourself (like by hardcoding the bucket name) might not solve it in all cases. Eg. Instead of trying to work all that out, it would be best left untouched and let Now all you need to do is to distribute this role-arn and the SSM Parameternames to other stages. Choose an explicit role-name and SSM Parameters. The manual ARN construction given a rolename is pretty straightforward. So distribute that and SSM Parameters around your CDK code to other stages (compile time strings instead of references). In target stages, create custom-resource(s) ( Roundabout way to do a simple thing, but so far that is all I could do to get this to work.
And then in the target stage(s):
That's a generic pattern which should work for any case. |
|
General Issue
apply resource based policy to imported kms
The Question
I have a secret key-value pair in
Secrets Manager
in Account-1 inus-east-1
. This secret is encrypted using a Customer managed KMS key - let's call itKMS-Account-1
. All this has been created via console.Now we turn to
CDK
. We havecdk.pipelines.CodePipeline
which deploysLambda
to multiple stages/environments - so 1st to{ Account-2, us-east-1 }
then to{ Account-3, eu-west-1
} and so on. This has been done.The lambda code in all stages/environments above, now needs to be changed to use the secret key-value pair present with Account-1's
us-east-1
SecretsManager
by getting it viasecretsmanager
client. That code should probably look like this (python
):All lambdas in various accounts and regions (ie. environments) will have the exact same code as above since the secret needs to be fetched from Account-1 in
us-east-1
.cdk
code to facilitate this? How will the code-deploy in code-pipeline get permission to import this customkms
key andSecretManager' secret
and apply correct permissions for cross account access by the lambdas that the cdk pipeline creates ?Can someone please give some pointers?
CDK CLI Version
1.130.0
Framework Version
No response
Node.js Version
No response
OS
No response
Language
Python
Language Version
3.8
Other information
No response
The text was updated successfully, but these errors were encountered: