Your Top n Steps for Hardening your AWS Infrastructure

For some value of n. . .


Related discussions:

I guess the first would be stuffing your private stuff into a VPC and not giving certain back end things direct public access.

The most impact comes from limiting your public footprint. The fewer attack vectors the better.

These are some basic tips to that end. They won’t entirely apply to complex infrastructures.

  • Avoid opening any ingress on any port to 0.0.0.0/0 if it can be avoided.
  • Use managed services for public access where you can
    ** Easiest example - put your web server(s) behind an ELB even if you only have one instance. That way port 80 on the web server only needs to grant ports 80/443 access to the ELB not to the entire internet. The ELB then is in a public subnet but the instance is in a private one.
  • Set up a VPN on your work network (if you don’t already have one) then use your security groups so that your work IPs are the only ones allowed access to your systems outside your VPC. If you’re on the road or at home you can then VPN into work and have access to everything.
  • Use a bastion server if you can. If not at least only open SSH on one of your machines and ssh to your others from there.
  • Disable access to regions you’re not using - a common use of a compromised account it to spin up a large number of instances in an unused region with the hope of getting a lot of done before you notice your bill.

Excellent tips, thank you!

Have you ever used the EC2 Systems Manager? If so, would you recommend that over regular SSH?

We’re tinkering it with it, but most of our systems automation is via chef. Our use of EC2 predates systems manager by many years.

How do you disable access to regions? I have set up cloud trail to audit all regions, and config to alert me if cloudtrail is disabled, but I don’t see a way to disable a region. Conditional policies only seem to work for some services.

There are also side benefits of tucking in behind cloudfront. That means they are doing a bunch of blocking of malformed requests and suspicious actors out on the Edge locations.

Nice. . . did not know that, thank you.

One of my SysOps did it for us. I think it might be at the IAM level but I’m not sure.

I am policies. Basically deny all actions to any resource where region isn’t the one you want.

The other infrastructure-centric points are already addressed, but there’s others that matter just as much if not more for me.

  1. Scan for accidental commits of AWS credentials and S3 buckets into publicly available source control (Github, Gitlab, Bitbucket, etc.) and watch your granted credentials constantly
  2. Do not ever give developers private keys for instances you haven’t hardened / approved. I’m a developer, we do BAD things in security just to get our work done under the gun of deadlines and laziness like chmod 666 * and listening on 0.0.0.0
  3. Setup Cloudwatch billing alerts
  4. Use IAM profiles and roles to avoid using API keys
  5. Avoid putting any long-lived secrets into launch configuration userdata. If an instance is owned, you’ll wind up giving attackers more information from a quick curl 169.254.169.254
  6. Deploy janitor monkey or another form of automation that can scan for improperly tagged resources. Also, try to very frequently monitor Lambda functions or trigger alerts upon creation of them (a lot can be done with short-lived Lambda functions that can slide under people’s billing and usage radar).

Excellent, thanks!

Use IAM profiles and roles to avoid using API keys

Would you say that IAM roles can be used instead of API keys 100% of the time? I’m guessing the answer is yes or close to 100%.

It’s tough to sum it up in a “top” set of steps because that list will vary depending on the services you use. There are numerous best practices to follow, however. I would rank them:

  1. Account security. Disable the root account. Use IAM users only. Limit their permissions using specific policies instead of “.”. Enable MFA for all users. Do not use hard coded credentials (access keys) in any applications. Use IAM roles instead.

  2. Auditing. Turn on CloudTrail (in every region, even the ones you don’t use). Turn on CloudTrail log validation and encryption so you can see if someone’s tampered with the logs. Make sure the S3 bucket they’re being sent to has the proper permissions and has “MFA delete” enabled so someone can’t delete the logs without that extra step. Integrate your CloudTrail logs with CloudWatch and setup alerts for specific actions. Turn on VPC Flow logs. Turn on ConfigService.

  3. Encryption/Backup. Use EBS volume encryption, S3 encryption at rest, KMS key rotation, RDS encryption, EMR encryption, RedShift encryption. Setup proper backups for those services and ensure they are active and tested.

  4. Networking. Don’t allow “0.0.0.0/0” access for security groups for anything other than web traffic (unless you expect public access for another service). Use a private/public architecture for VPCs. Don’t launch EC2 instances in EC2 classic. Don’t put instances in the public tier, put them behind an ELB instead. Use the latest ELB SSL/TLS policies.

There are lots more, but these cover the core services. Shameless plug/full disclosure: I’m the founder of CloudSploit, a service that I wrote to continually check that these best practices are enabled and properly setup within your AWS accounts.

This CIS AWS Benchmark has a list of controls as well as prescriptive guidance on how to secure your AWS account. Tony de la Fuente from Alfresco has a tool on Github to automate all of the checks here.

  • Cloudtrail
  • ec2 roles
  • use iam roles for administration not root creds
  • set up cloudtrail alert on root creds access

All our developers are using STS credentials from their IAM role for any API access, unless whatever they’re doing doesn’t support STS credentials which we have seen. Static keys are really only for service accounts that can’t use an IAM instance profile.

Can you elaborate on this? Would things not running on AWS be, say something like, internal jenkins servers that deploy AWS infrastructure / on to infrastructure? I’m trying to understand how one could perform this kind of automation without static API keys.

E: looks like I should probably investigate STS.

Use a bastion server if you can. If not at least only open SSH on one of your machines and ssh to your others from there.

Better yet, use ProxyCommand to use the bastion or jumper as a tunnel. This limits needing to store the EC2 keypairs on your bastion, and doesnt use ssh-agent forwarding which can be monitored by users on the bastion (say, in the event of compromise).

Ensure theres some form of attestation and non-repudiation; logging / auditing and backups thereof.

Scout2 and/or Security Monkey would be something in the same vein.

Fairly easy to use tools for security auditing.

Interesting, could you describe what a typical use case is and how it works? I.e. i that just for developers running commands/tools on their local machines?