Profile Applicability:
- Level 1
Description:
EC2 User Data can be specified when launching an EC2 instance to configure the instance or include initialization scripts. However, it is critical that sensitive information, such as passwords, API keys, or encryption keys, are not included in user data since this data is not protected by encryption or authentication mechanisms.
Rationale:
User data is easily accessible and can be viewed by anyone with access to the EC2 instance configuration, including administrators, system users, or unauthorized actors. Storing secrets or sensitive data in EC2 user data is insecure because the data is not protected, leading to potential data leaks, security breaches, and compliance violations.
Impact:
Pros:
Improved security by ensuring that sensitive data is stored securely.
Reduced risk of unauthorized access to credentials or sensitive data through EC2 instance configurations.
Cons:
Requires secure storage alternatives for sensitive data (e.g., AWS Secrets Manager), which may incur additional operational complexity.
Default Value:
By default, user data is not encrypted or protected. If sensitive data is stored in user data, it could be easily accessed by anyone with sufficient permissions.
Pre-requisites:
AWS IAM permissions to view and manage EC2 instances and user data:
ec2:DescribeInstances, ec2:ModifyInstanceAttribute
Remediation:
Test Plan:
Using AWS Console:
Log in to the EC2 Console at AWS EC2 Console.
In the left pane, click Instances, then click Instances from the dropdown.
Select an EC2 instance for review.
From the Actions menu, select Instance Settings, then click Edit User Data.
Review the user data for any secrets or sensitive data, such as passwords, keys, or tokens.
If sensitive data is found, refer to the remediation section below.
Repeat steps 3–6 for all EC2 instances across all AWS regions.
Using AWS CLI:
Run the following command to describe EC2 instances and retrieve the user data:
aws ec2 describe-instances --region us-east-1 --output json --query "Reservations[*].Instances[*].{Instance:InstanceId}"
For each instance listed, run the following command to retrieve the user data:
aws ec2 describe-instance-attribute --instance-id <instance-id> --attribute userData
Note that the user data might be Base64 encoded. Decode the output if necessary to check for sensitive information.
Implementation Plan:
Using AWS Console:
Log in to the EC2 Console at AWS EC2 Console.
In the left pane, click Instances, then click Instances from the dropdown.
Select the EC2 instance where sensitive data is found in the user data.
Stop the instance if it is running to ensure no unintended side effects from modifying the user data.
Click Actions > Instance Settings > Edit User Data.
Remove any secrets or sensitive data from the User Data.
Store sensitive data securely using services such as AWS Secrets Manager instead.
Once the changes are made, save the new user data and restart the instance.
Using AWS CLI:
For each instance identified in the audit with sensitive data in the user data, use the modify-instance-attribute command to update the user data:
aws ec2 modify-instance-attribute --instance-id i-1234567abcdefghi0 --user-data "New user data without sensitive information"
If the instance needs to be stopped before the change, use the stop-instances command, followed by the start-instances command once the change is made:
aws ec2 stop-instances --instance-ids i-1234567abcdefghi0 aws ec2 start-instances --instance-ids i-1234567abcdefghi0
Backout Plan:
Using AWS Console:
If removing sensitive data from user data causes issues, you can revert the changes by editing the user data again and restoring any previous configuration (if applicable and necessary).
Ensure that any sensitive data is securely stored in an appropriate service, such as AWS Secrets Manager, before modifying user data.
Using AWS CLI:
If reverting changes causes issues with the EC2 instance, you can restore the previous user data by re-running the modify-instance-attribute command with the old data, or restore from a backup if available.
References:
CIS Controls: