Aws Security Best Practices
Aws Security Best Practices
Best Practices
© SQREEN 2017
www.sqreen.io AWS Security Best Practices
two factors authentication), last usage date Rotate your AWS keys
of access keys. Two steps are necessary:
first the report generation… In a typical production environment, AWS
keys get spread across various services,
$ aws iam generate-credential-report
which have various privilege needs. Many
employees will have access to multiple
{ "State": "COMPLETE" }
keys — DevOps will have access to most
keys, DBAs will have access to the
…then the report retrieval. database keys, backend team to the log
keys…
$ aws iam get-credential-report | jq
It is often necessary to renew these keys
'.Content' -r | base64 -D
user,arn,user_creation_time,password_e (e.g. when someone leaves a team). This
nabled,password_last_used,password_las procedure should be straightforward and
t_changed,password_next_rotation,mfa_a
ctive,access_key_1_active,access_key_1 risk-free, so that you can do it frequently,
_last_rotated,access_key_1_last_used_d and more importantly, in urgent situations.
ate,access_key_1_last_used_region,acce
ss_key_1_last_used_service,access_key_ You can list the active access keys for a
2_active,access_key_2_last_rotated,acc
ess_key_2_last_used_date,access_key_2_ given user in this way:
last_used_region,access_key_2_last_use
d_service,cert_1_active,cert_1_last_ro
tated,cert_2_active,cert_2_last_rotate $ aws iam list-access-keys --user-name
d
Elliot --query 'AccessKeyMetadata[?
<root_account>,arn:aws:iam:: Status==`Active`]'
12345:root, {
2015-08-03T12:09:08+00:00,not_supporte "AccessKeyMetadata": [
d, {
2016-06-23T11:56:59+00:00,not_supporte “CreateDate":
d,not_supported,true,false,N/A,N/A,N/ "2015-10-12T16:52:19Z",
A,N/A,false,N/A,N/A,N/A,N/A,false,N/ "UserName": "Elliot",
A,false,N/A "Status": "Active",
"AccessKeyId":
“AKXXXXXXXXXXXX"
},
Parsing this CSV file is easy {
using e.g. Google Sheets, Numbers, or "CreateDate":
Excel. You can as well use the “Credential "2016-12-06T19:17:25Z",
"UserName": "Elliot",
Report” tool from IAM in order to download "Status": "Active",
the same CSV report. This exhaustive list "AccessKeyId":
"AKZZZZZZZZZZZZZZZZ"
will allow you to warn non-conforming
}
users with a strict deadline. ]
}
© SQREEN 2017
www.sqreen.io AWS Security Best Practices
This will help you distinguish which keys
-r '.[]' > my-keys.txt $ grep -f my-
are used, and which are not. Keeping your
keys.txt -r source_code1 source_code2
set of keys as reduced as possible will help …
you managing these critical secrets!
© SQREEN 2017
www.sqreen.io AWS Security Best Practices
It means your machines will have private IP
GroupName]" --output text)
addresses, preventing by default
while read -r line; do
sgid=$(echo $line | awk '{print connections to the internet and from being
$1;}')
accessible from the Internet.
sgname=$(echo $line | awk '{print
$2;}')
If external internet access is required on
c=$(aws ec2 describe-network-
interfaces --filters "Name=group- your machines, they should use an AWS
id,Values=$sgid" --query NAT gateway as their only way to access
"length(NetworkInterfaces)" --output
text)
the Internet
echo "$sgid,$c,$sgname"
done <<< "$sgs" If you need to grant public access to these
machines from the outside, use an Elastic
Load Balancer, or an Application Load
The result will look like this: group-id,
Balancer. They are the AWS dedicated
number of assignations, group name:
elements that allow you to easily operate
and scale public accesses.
sg-7xxxxx,11,https_everywhere
sg-7xxxxx,2,http_everywhere
For internal access (e.g. a microservice), it
sg-7xxxxx,0,demo
is better to create an internal Load
Balancer (that will be restricted to your
If the number of assignations is > 0, then VPC) in order to decouple the network
this group is used. If its name does not configuration of this specific machine from
explicitly state that it is meant to be public, the configuration of its clients.
you should check it: EC2 -> Network &
The following command will display the list
Security -> Security Groups and make sure
of public IP addresses that are used
this group is legitimate.
amongst your EC2 instances. If your
In this example, the https_everywhere and instances are using internal IP addresses,
http_everywhere are legitimate: they are only your NAT gateway should appear
operating load balancers. here.
© SQREEN 2017
www.sqreen.io AWS Security Best Practices
available. The paid version will tell you
]
about logging, your SSL certificates,
}
exposed IAM keys and key rotation… The
price is high, up to 10% of your
infrastructure price. Only 4 checks are
You can now restrict this list to only display available by default, then you need to
public IP addresses, along with the purchase Business support (100$ / month)
associated EC2 instance ID: to access all of them.
$ aws cloudtrail describe-trails
{
Use Trusted advisor "trailList": [
{
AWS Trusted Advisor is a great way to "Name": "my-trail",
© SQREEN 2017
www.sqreen.io AWS Security Best Practices
security issues. Some of them should be
false,
corrected as soon as possible — even
"S3BucketName": "mytrail",
"HomeRegion": "eu-west-1"
though some previous steps, such as
}
reducing network exposure, can mitigate
]
} some of the issues created by an out-of-
date OS.
And check their status: In AWS, the OS is managed with the AMIs.
You should ensure your AMIs are kept up
to date.
$ aws cloudtrail get-trail-status --
name my-trail
{
When an AMI starts, it will by default
"LatestNotificationAttemptSucceeded": download and apply the latest security
"",
patches. AWS keeps a very up to date list
"TimeLoggingStarted":
"2015-03-07T22:58:34Z",
of the security issues corrected in the AWS
"LatestDigestDeliveryTime": instances.
1497546412.316,
"TimeLoggingStopped": "",
AMIs can be displayed in the AWS Web
"LatestDeliveryAttemptTime":
"2017-06-15T17:04:32Z",
console Pay attention when choosing the
"LatestNotificationAttemptTime": region were your EC2 instances are placed.
"",
"IsLogging": true,
"StartLoggingTime": 1283019477,
"LatestDeliveryAttemptSucceeded": Choose your rights carefully
"2017-06-15T17:04:32Z",
"LatestDeliveryTime":
1497546272.808
Just like your network, the other AWS
} services start with a zero-rights policy
(nothing is allowed by default). So allowing
You can see last time an event was logged certain entities to use this service is part of
with this trail. The same is available from the service configuration. This
the AWS console: configuration need to be tight, and must
not contain any unnecessary privileges.
Access AWS CloudTrail now.
Some tools that are part of AWS IAM can
help perform simulations of the rights you
Update your Amazon Machine are building. The “Access Advisor” in
Images (AMI) IAM will help you fine tune the rights
associated to the roles you create.
Just like any other piece of software, the
OS needs to be upgraded to prevent
© SQREEN 2017
www.sqreen.io AWS Security Best Practices
Monitor billing
Going further
These AWS-authored articles will help you
review what you have done in your
organization and how you should improve
your infrastructure:
© SQREEN 2017
www.sqreen.io AWS Security Best Practices