paint-brush
Setting Up AWS SecurityHub With Terraform in a Minuteby@mantux
4,667 reads
4,667 reads

Setting Up AWS SecurityHub With Terraform in a Minute

by Leandro MantovaniJanuary 14th, 2022
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

The first section of the code enables SecurityHub automatically for all new accounts in the Organization. This lets us keep our environment fully compliant, and centralize all findings in security account. The second resource enables the CIS benchmark. This is very useful since it’ll give you a lot of checks that you can use to size the level of compliance resources in your accounts. The first time you enabled it, you need to add existing accounts in this way. For new accounts, you are covered with auto_enable flag.

Companies Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Setting Up AWS SecurityHub With Terraform in a Minute
Leandro Mantovani HackerNoon profile picture

I’m going to show you how to create a SecurityHub multi-account setup using terraform.

AWS Organizations

If you are using AWS Organizations, you have something similar to the setup below. For configuring SecurityHub at the Organization level, you need to add 

securityhub.amazonaws.com
 to service access principals. In this way, you’re telling Organizations that you want to use SecurityHub.

A best practice recommended by AWS is to delegate all security-related systems to a separate account, like a security or audit account. It’s a bad practice to mix Organization service with security services. If you do that, you will end up granting account access to users that not necessarily are Security Staff, like Finance people that need access to the Organization service account to see the bills.

At the last part of the code you can see the delegation resource, and the 

admin_account_id
, which in this case is the id of the security account.

Cheers! You have configured Organizations and delegated administration of SecurityHub to security account, well done.

SecurityHub

It’s time to go to the security account.

Depending on the setup you have for terraform projects, you will have both accounts in the same terraform project, or maybe you have them in different projects separated by directories, so you need to figure out where it’s the best place to put your code, depending on your setup.

The first section of the code enables SecurityHub automatically for all new accounts in the Organization. This lets us keep our environment fully compliant and centralize all findings in the security account.

The second resource enables the CIS benchmark. This is very useful since it’ll give you a lot of checks that you can use to size the level of compliance resources in your accounts.

Finally, we add two existing accounts to SecurityHub as members. The first time you enable it, you need to add existing accounts in this way. For new accounts, you are covered with 

auto_enable
 flag.

That’s Not All, Folks!

I hope that you’ve learned something new with my post, and if this is your case, I encourage you to become one of my followers. You’ll be notified when I upload more useful content like this one.

Also Published Here