For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/cloudformation-aws-user-data-contains-encoded-private-key.md.
A documentation index is available at /llms.txt.
Embedding private keys in instance user data (even if base64-encoded) exposes sensitive credentials that can be decoded and used to gain unauthorized access to instances and pivot within your environment.
For AWS::AutoScaling::LaunchConfiguration resources, Properties.UserData must not contain PEM private key material. This includes raw PEM headers like -----BEGIN RSA PRIVATE KEY or their base64-encoded equivalents. This rule flags UserData entries that contain base64 fragments indicative of an encoded PEM header (for example, fragments such as LS0tLS1CR) or the raw PEM text.
To remediate, store keys and secrets in a secure service (AWS Secrets Manager, Systems Manager Parameter Store) or provision access via EC2 key pairs, instance roles, or runtime retrieval from a secure store instead of hard-coding them into user data.
Secure configuration example (retrieve secret from Secrets Manager at runtime):