Review Base64-encoded private keys in launch configuration user data

Base64 encoding does not keep a private key secret. Remove actual private keys from EC2 user data.

Description

A private key in user_data_base64 can be recovered from code, Terraform state or instance user data. Check whether the value is a real private key or a public certificate.

Potential impact

A disclosed key can be used for authentication or signing on every system that still trusts it.

Remediation

Retrieve required secrets from Secrets Manager or a Parameter Store SecureString with a workload role limited to those secrets. Replace an exposed key at every consumer and remove trust in the old key.

Examples

Both excerpts use the legacy aws_launch_configuration and require a separate AMI lookup. Launch configurations cannot be edited. To migrate to a launch template, create one, point the Auto Scaling group to it and roll out replacement instances.

Before

hcl
resource "aws_launch_configuration" "app_launch_config" {
  image_id         = data.aws_ami.ubuntu.id
  instance_type    = "m4.large"
  user_data_base64 = "LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpzb21lS2V5"
}

The encoded value illustrates a private-key header.

After

hcl
resource "aws_launch_configuration" "app_launch_config" {
  image_id      = data.aws_ami.ubuntu.id
  instance_type = "m4.large"
}

The second configuration removes user_data_base64 entirely. Configure any required bootstrap tasks separately without embedding secrets.

References