Instance security requires that you fully understand AWS security groups, along with patching responsibility, key pairs, and various tenancy options.
As a precursor to this post, you should have a thorough understanding of the AWS Shared Responsibility Model before moving onto discussing instance-level security within your Virtual Private Cloud (VPC).
AWS security groups (SGs) are associated with EC2 instances and provide security at the protocol and port access level. Each security group — working much the same way as a firewall — contains a set of rules that filter traffic coming into and out of an EC2 instance. Unlike network access control lists (NACLs), there are no “Deny” rules. If there is no rule that explicitly permits a particular data packet, it will be dropped.
You should always aim to restrict access with your security group to help maintain restriction of access at the protocol and port level. In addition to this, you should implement the rule of least privilege when it comes to designing and implementing your rules in your security groups. Only allow the access that is needed, and do not apply overly permissive access as this can result in future security breaches and vulnerabilities.
Each security group must have a name, allowing you to easily distinguish it from others. The description is optional, but it does offer you the ability to add additional contextual information to help you understand the security groups. Security groups are specific to a VPC. As a result, during your security groups, you must specify which VPC the SG will reside. Be sure to select the correct VPC for the resource in which you want to protect.
The actual rule of a security group that filters traffic is defined in two tables: Inbound and Outbound. AWS security groups are stateful, meaning you do not need to add rules for return. Therefore, any rule that allows traffic into an EC2 instance, will automatically allow responses to pass back out to the sender without an explicit rule in the Outbound rule set.
Each rule is comprised of five fields: Type, Protocol, Port Range, Source, and Description. This applies to both Inbound and Outbound rules.
You can create security groups in different ways, such as the AWS CLI or the AWS Management Console. From within the AWS Management Console, you can create a security group during the launch of an EC2 instance, at Step 6: Configure Security Group as shown below.
If you simply want to create a security group without having to launch an instance, you can follow these steps:
1. Log in to the AWS Management Console
2. Select the EC2 service
3. Select “Security Groups” from under the “Network & Security” category on the left:
4. Select the blue “Create Security Group” button
5. Enter the security group name and description
6. Select the appropriate VPC
7. Add your rules, as required, by selecting the “Add Rule” button. In the example below, I have added a rule to allow SSH connectivity from the 10.0.1.0/24 subnet
While AWS security groups are normally associated with instances during their creation, you can also add or remove them from running instances. To carry out these changes via the AWS Management Console:
1. Log in to the AWS Management Console
2. Select the EC2 service
3. Select “Instances” from under the “Instances” category on the left
4. Select the instance you want to modify
5. Click Actions > Networking > Change Security Groups
Limits
There are a number of default limits to be aware of when creating security groups. These can be defined as follows:
Applying the latest security patches to your instances is, again, your responsibility – even if you built your instance from an AWS-defined AMI. No matter which operating system you deploy, I recommend that you regularly download the latest security patches. New vulnerabilities and security flaws are being discovered and fixed all the time, and you can’t afford to ignore them. AWS takes security as its number one priority and we need to do the same.
After creating an instance, you should download and install the latest patches as you do not know how long ago the AMI was created and it’s very likely that there are a number of security patches available. You could look at automating this process through instance user data when creating your instances. For example, entering the following command on a Linux-based AMI would automatically perform a yum update at instance launch:
yum update -y
The “user data” section can be found in Step 3: Configure Instance Details under “Advanced Details.”
Ensuring the latest patches are installed on your instances, protects you from vulnerabilities and threats to your OS. This is a simple yet necessary security addition to your instance deployment.
Tenancy relates to what underlying host your EC2 instance will reside on, essentially the physical server within an AWS Data Center. When deploying your instances, you will have the opportunity to specify 1 of 3 tenancy options for your instance:
With these options available to you, there are pros and cons to each.
If you do not need to address any compliance or security issues that require dedicated tenancy, then I recommend using shared tenancy to reduce your overall costs. Not all instance types are eligible for dedicated tenancy, so if you are thinking of using it, consult the AWS documentation.
At the very end of your EC2 instance creation, you will need to select an existing Key Pair or create and download a new one.
A key pair, as the name implies, is made up of two components: a public key and a private key.
The function of key pairs is to encrypt the login information for Linux and Windows EC2 instances and then decrypt the same information, allowing you to authenticate onto the instance. The public key encrypts data, such as the username and password. For Window instances, the private key is used to decrypt this data, allowing you to gain access to the login credentials including the password. For Linux instances, the private key is used to remotely connect onto the instance via SSH.
The public key is held and kept by AWS, and the private key is your responsibility to keep and ensure that it is not lost.
So, going back to when you create your EC2 instance and a new key pair, you are given the opportunity to download the key pair. Once you have done this, you must keep that file safe until you are ready to log onto the associated EC2 instance. It’s worth noting that you can use the same key pair on multiple instances to save you from managing multiple private keys. Do bear in mind; however, should the private key become compromised, access could be gained to all instances where that key pair was used.
Once you have authenticated to the EC2 instance the first time, you can set up additional less privileged access controls, such as local Windows accounts allowing other users to connect and authenticate to or even utilize Microsoft Active Directory.secu.
You might also want to take the following course, which also touches on some of the information covered within this post: Working with AWS Networking and Amazon VPC.
Thank you for taking the time to read my article. If you have any feedback please do leave a comment below.
It's Flash Sale time! Get 50% off your first year with Cloud Academy: all access to AWS, Azure, and Cloud…
In this blog post, we're going to answer some questions you might have about the new AWS Certified Data Engineer…
This is my 3rd and final post of this series ‘Navigating the Vocabulary of Gen AI’. If you would like…