Use of an insecure channel - Cloud Infrastructure - Cloudformation
Need
Secure communication channels for data transmission in AWS
Context
- Usage of CloudFormation for Infrastructure as Code (IaC)
- Usage of AWS SDK for interacting with Amazon Web Services
Description
Insecure Code Example
Parameters:
AccessKey:
Type: String
Default: "my-access-key"
SecretKey:
Type: String
Default: "my-secret-key"
Resources:
MyEC2Instance:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-0c94855ba95c574c8
InstanceType: t2.micro
Tags:
- Key: Name
Value: example-instance
In the above CloudFormation configuration, sensitive credentials such as the AWS access key and secret key are embedded directly into the template. This practice exposes those secrets to version control systems, unauthorized viewers, and increases the risk of compromise. Furthermore, there is no enforcement of secure communication between the infrastructure client and AWS services. Without explicit mention of SSL/TLS configuration or other secure transport methods, it is assumed that the communication may occur over insecure channels, making it vulnerable to Man-in-the-Middle (MitM) attacks and data interception.
Steps
- Use HTTPS instead of HTTP for communication with AWS services
- Enable encryption in transit by configuring SSL/TLS for the communication channel
- Ensure that secure cipher suites and encryption protocols are used
- Implement mutual authentication to verify the identity of the remote end of the connection
- Avoid hardcoding access keys and secret keys in the code, instead use secure credential management solutions
Secure Code Example
Resources:
MyEC2Instance:
Type: AWS::EC2::Instance
Properties:
ImageId: ami-0c94855ba95c574c8
InstanceType: t2.micro
Tags:
- Key: Name
Value: example-instance
BlockDeviceMappings:
- DeviceName: /dev/xvda
Ebs:
VolumeSize: 8
Encrypted: true
This updated CloudFormation snippet avoids embedding sensitive credentials in the template. Instead, credentials are assumed to be provided via IAM roles assigned to the instance or injected securely through environment variables or Secrets Manager, outside of the template itself. Additionally, an encrypted EBS volume is configured for the instance to protect data at rest. Secure communication with AWS services is implicitly enforced when using the AWS SDKs and tools that default to HTTPS with TLS encryption. Best practices include using IAM roles for EC2 and encrypting all sensitive data both at rest and in transit.
References
Last updated
2025/04/04