-
I created a proof of concept to demonstrate an attack on the popular aws cdk pipelines. This exploits the fact that there is some time between the “Synth" step and the use of the cloudformation templates and lambda assets ("SelfMutate") and that no integrity check is performed by default. After receiving an event from s3, the Lambda function injects the malicious code/resources into the generated files. SAST/DAST controls and pull request checks are bypassed, and other accounts can also be attacked if the pipeline supports cross-account deployments. https://github.com/hupe1980/cfni AWS Security has determined that this is not a security issue as they recommend customers to use cloudformation hooks as a protection mechanism against non-compliant resources. Is there a way to sign the templates and assets generated in the synth step with a public key so that integrity can be verified in later steps using cloudformation hooks? There doesn't seem to be such a function yet and the security notes do not currently indicate such a risk https://docs.aws.amazon.com/cdk/v2/guide/cdk_pipeline.html#cdk_pipeline_security |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Let me see if I understand: You have resources deployed into your own account (such as the artifact bucket and staging bucket), and given enough permissions you are able to replace files in those S3 buckets between when they are written and when they are read, so that the deployment does something else? It's true that protecting against your own developers is not really in the CDK Pipelines threat model. I'm not even sure it's possible. It's fair to say that this should be mentioned in the documentation so that organizations that cannot trust their developers will be aware they should have something like CFN Hooks or AWS Config in place.
Since the Synth step must be able to produce signed artifacts, your developers will implicitly have access to this facility as well. Either because we have to include the private key into the CDK binary (so it's trivially extractable), or because they can run arbitrary code in a CodeBuild job that must needs have permissions to use KMS, AWS Signer, or read from Secrets Manager. If you really wanted to, you could potentially go the way of injecting a CodeBuild job into the pipeline that signs the artifacts before validating them against guard rails and lock down access to that CodeBuild job (though developers will have access to the pipeline definition and will be able to move the guard rails or signing steps around), and then validate the signatures using CloudFormation Hooks or perhaps S3 Object Lambdas... but at that point, wouldn't it be simpler to move the entire suite of guard rails checks into CloudFormation Hooks (for prevention) or AWS Config (for auditing), and bypass the whole process of trying to establish non-forgeable guarantees early on in the pipeline? |
Beta Was this translation helpful? Give feedback.
-
Hello! Reopening this discussion to make it searchable. |
Beta Was this translation helpful? Give feedback.
Let me see if I understand:
You have resources deployed into your own account (such as the artifact bucket and staging bucket), and given enough permissions you are able to replace files in those S3 buckets between when they are written and when they are read, so that the deployment does something else?
It's true that protecting against your own developers is not really in the CDK Pipelines threat model. I'm not even sure it's possible. It's fair to say that this should be mentioned in the documentation so that organizations that cannot trust their developers will be aware they should have something like CFN Hooks or AWS Config in place.