Skip to the content.

Infrastructure Security

EC2 Keypairs

Keypairs are used to interact with EC2 instances without entering any username or passwords.

To connect to the EC2 instance using the generated/downloaded keypair:

ssh -i keyfile.pem ec2-user@10.1.2.3 

Change permissions When you first generate a keypair in the AWS console and download it locally, the default permissions of the keypair is 777. When you use it to connect to the EC2 instance for the first time, you’ll get prompted with an error:

WARNING: UNPROTECTED KEY FILE! 

To change the permissions, use the command below. 400 permissions means only the owner can use it.

sudo chmod 400 keyfile.pem 

Generating keypair locally We can also generate a keypair from any Linux machine using the command below.

ssh-keygen -t rsa -n 4096 

This will generate a key pair:

We can then import the public key onto the EC2 menu. To learn more, see:

Invalidate the key When you delete the keypair in the EC2 menu, it will only prevent any future usage of that key. However if you have existing instances that use that keypair, the keypair can still be used to connect to those instance.

To fully revoke the keypair, login to any machines that are using the keypair and delete the key from the machine:

sudo vi ~/.ssh/authorized_keys  

Hypervisors, Isolation, and Dedicated Instances

Hypervisors

This is the engine that sits on top of physical machines which allows us to run virtual machines on top of the machines.

Isolations

The hypervsor can only be accessed by AWS administrators when there is a valid business case.

Dedicated Hosts vs. Dedicated Instances

A dedicated instance may or may not share the physical host with shared instances, from the same AWS account.

A dedicated host gives you control about instance placement in that physical host.

AWS Systems Manager (SSM)

This allows you to centralize operational data from multiple AWS services and automate tasks across your AWS resources.

AWS Systems Manager: Parameter Store

We can use Parameter Store to store and retrieve any parameter, such as usernames, passwords, and API keys.

AWS Systems Manager: Run Command

This automation tool allows us to run a command in a given group of systems (manual or tag-based selection).

AWS VPC

Amazon Virtual Private Cloud (Amazon VPC) enables you to launch AWS resources into a virtual network that you’ve defined. This virtual network closely resembles a traditional network that you’d operate in your own data center, with the benefits of using the scalable infrastructure of AWS.

NACLs vs. Security Groups

Network ACLs (NACLs) is applied into the entire subnet which serves as some sort of a firewall for the subnet.

Security groups are applied on the specific instance.

VPC Connectivity Options

To enable internet connectivity:

A few notes on NAT Instances:

See Comparison of NAT Gateway and NAT Instances.

VPN vs. Direct Connect

VPN Gateway:

Direct Connect

See AWS Direct Connect + VPN.

AWS Marketplace Security Products

There are some capabilities that AWS does not offer as a feature, but is available through third-party vendors. These capabilities include:

AWS does not provide network packet inspection, but we can utilize:

Recommended wat is to use third-party solution such as:

For penetration testing, this is allowed for some AWS services without prior approval. See AWS Penetration Testing.