Description
For cfn-init downloads from S3, set roleName to the role in the instance profile. This lets the instance retrieve files without static keys in its metadata.
Potential impact
Keys or passwords left in templates and source history can grant the operations they authorize, including in other environments that reuse them.
Remediation
Give the role read access to the required S3 objects. For other secrets, use references supported by the property or retrieve values at runtime. NoEcho does not mask Metadata, Outputs or logs. Revoke or replace exposed credentials and review their use.
Examples
Include WebServerRole in WebServerInstanceProfile and attach the profile to the instance. Supply the AMI and cfn-init invocation, associate its files or sources with S3AccessCreds and verify retrieval without static keys.
Before
Resources:
WebServer:
Type: AWS::EC2::Instance
Metadata:
AWS::CloudFormation::Authentication:
S3AccessCreds:
type: S3
accessKeyId: AKIAIOSFODNN7EXAMPLE
secretKey: very-secret-value
After
Resources:
WebServer:
Type: AWS::EC2::Instance
Metadata:
AWS::CloudFormation::Authentication:
S3AccessCreds:
type: S3
roleName: !Ref WebServerRole
Properties:
IamInstanceProfile: !Ref WebServerInstanceProfile