Skip to content

Commit 188a3d1

Browse files
Sync documentation and add default rules
1 parent 2aafa5f commit 188a3d1

File tree

11 files changed

+262
-154
lines changed

11 files changed

+262
-154
lines changed

.config/.terraform-docs.yml

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,44 @@ content: |-
1313
1414
GitHub: [StratusGrid/terraform-aws-config-rules](https://github.com/StratusGrid/terraform-aws-config-rules)
1515
16+
Terraform Registry: [StratusGrid/config-rules](https://registry.tf-registry-prod-use1.terraform.io/modules/StratusGrid/config-rules/aws/latest)
17+
1618
AWS Config rules module to put in standard policies
1719
18-
Note: Config Rule requires an existing Configuration Recorder to be present.
20+
Note: Config Rule requires an existing Configuration Recorder to be present. There is available a StratusGrid terraform module to provision it [StratusGrid/config-recorder](https://registry.tf-registry-prod-use1.terraform.io/modules/StratusGrid/config-recorder/aws/latest)
1921
2022
## Example Single Region Configuration:
23+
The simplest example deploy the default AWS managed rules we added in the module
24+
- ROOT_ACCOUNT_MFA_ENABLED
25+
- IAM_ROOT_ACCESS_KEY_CHECK
26+
- IAM_USER_MFA_ENABLED
27+
28+
If you want to disable those default rules set `enable_default_aws_managed_rules = false`
29+
2130
```hcl
2231
{{ include "examples/single-region/example1.tfnot" }}
2332
```
2433
---
34+
The second example adds besides the default AWS managed rules added in the example 1 the AWS managed rule required_tags_enabled along with the required parameters
35+
36+
```hcl
37+
{{ include "examples/single-region/example2.tfnot" }}
38+
```
39+
---
40+
The third example use the aws_managed_rules map with two defined rules. The existing AWS Managed rules can be found [here](https://docs.aws.amazon.com/config/latest/developerguide/managed-rules-by-aws-config.html), and you can map them as shown below.
41+
42+
```hcl
43+
{{ include "examples/single-region/example3.tfnot" }}
44+
```
45+
![Alt aws-manage-rules](.config/aws-managed-rules.png)
46+
47+
---
48+
The fourth example shows the creation of a custom rule using [Guard domain-specific language (DSL)](https://docs.aws.amazon.com/cfn-guard/latest/ug/writing-rules.html)
49+
50+
```hcl
51+
{{ include "examples/single-region/example4.tfnot" }}
52+
```
53+
2554
## Example Multi Region Configuration:
2655
```hcl
2756
{{ include "examples/multi-region/example1.tfnot" }}

.config/aws-managed-rules.png

419 KB
Loading

README.md

Lines changed: 85 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,108 @@
1414

1515
GitHub: [StratusGrid/terraform-aws-config-rules](https://github.com/StratusGrid/terraform-aws-config-rules)
1616

17+
Terraform Registry: [StratusGrid/config-rules](https://registry.tf-registry-prod-use1.terraform.io/modules/StratusGrid/config-rules/aws/latest)
18+
1719
AWS Config rules module to put in standard policies
1820

19-
Note: Config Rule requires an existing Configuration Recorder to be present.
21+
Note: Config Rule requires an existing Configuration Recorder to be present. There is available a StratusGrid terraform module to provision it [StratusGrid/config-recorder](https://registry.tf-registry-prod-use1.terraform.io/modules/StratusGrid/config-recorder/aws/latest)
2022

2123
## Example Single Region Configuration:
24+
The simplest example deploy the default AWS managed rules we added in the module
25+
- ROOT_ACCOUNT_MFA_ENABLED
26+
- IAM_ROOT_ACCESS_KEY_CHECK
27+
- IAM_USER_MFA_ENABLED
28+
29+
If you want to disable those default rules set `enable_default_aws_managed_rules = false`
30+
2231
```hcl
2332
module "aws_config_rules_us_east_1" {
2433
source = "StratusGrid/config-rules/aws"
2534
# StratusGrid recommends pinning every module to a specific version
2635
version = "x.x.x"
2736
28-
include_global_resource_rules = true #only include global resource on one region to prevent duplicate rules
29-
required_tags_enabled = true
37+
}
38+
```
39+
---
40+
The second example adds besides the default AWS managed rules added in the example 1 the AWS managed rule required_tags_enabled along with the required parameters
3041

42+
```hcl
43+
module "aws_config_rules_us_east_1" {
44+
source = "StratusGrid/config-rules/aws"
45+
# StratusGrid recommends pinning every module to a specific version
46+
version = "x.x.x"
47+
48+
required_tags_enabled = true
3149
required_tags = { # Yes, the actual required format is tag#Key and tag#Value
3250
tag1Key = "Provisioner"
3351
tag1Value = "Terraform"
3452
tag2Key = "Customer"
3553
tag3Key = "Application"
3654
}
55+
56+
}
57+
```
58+
---
59+
The third example use the aws_managed_rules map with two defined rules. The existing AWS Managed rules can be found [here](https://docs.aws.amazon.com/config/latest/developerguide/managed-rules-by-aws-config.html), and you can map them as shown below.
60+
61+
```hcl
62+
module "aws_config_rules_us_east_1" {
63+
source = "StratusGrid/config-rules/aws"
64+
# StratusGrid recommends pinning every module to a specific version
65+
version = "x.x.x"
66+
67+
aws_managed_rules = {
68+
access-keys-rotated = {
69+
description = "Checks if active IAM access keys are rotated (changed) within the number of days specified in maxAccessKeyAge. The rule is NON_COMPLIANT if access keys are not rotated within the specified time period."
70+
identifier = "ACCESS_KEYS_ROTATED"
71+
input_parameters = {
72+
maxAccessKeyAge = "10"
73+
}
74+
}
75+
cloudtrail-security-trail-enabled = {
76+
description = "Checks that there is at least one AWS CloudTrail trail defined with security best practices. This rule is COMPLIANT if there is at least one trail that meets: https://docs.aws.amazon.com/config/latest/developerguide/cloudtrail-security-trail-enabled.html"
77+
identifier = "CLOUDTRAIL_SECURITY_TRAIL_ENABLED"
78+
input_parameters = {}
79+
}
80+
}
3781
}
3882
```
83+
![Alt aws-manage-rules](.config/aws-managed-rules.png)
84+
3985
---
86+
The fourth example shows the creation of a custom rule using [Guard domain-specific language (DSL)](https://docs.aws.amazon.com/cfn-guard/latest/ug/writing-rules.html)
87+
88+
```hcl
89+
module "aws_config_rules_us_east_1" {
90+
source = "StratusGrid/config-rules/aws"
91+
# StratusGrid recommends pinning every module to a specific version
92+
version = "x.x.x"
93+
94+
custom_managed_rules = {
95+
out-of-scope-ec2-instance-families = {
96+
description = "Ensure EC2 instance configurations do not belong to out-of-scope families."
97+
scope = {
98+
compliance_resource_types = ["AWS::EC2::Instance"]
99+
}
100+
source = {
101+
source_detail = {
102+
message_type = "ConfigurationItemChangeNotification"
103+
}
104+
custom_policy_details = {
105+
policy_runtime = "guard-2.x.x"
106+
policy_text = <<POLICY
107+
rule check_out_of_scope_instance_families when resourceType == "AWS::EC2::Instance" {
108+
configuration.instanceType != /x1e\.*/
109+
configuration.instanceType != /x2i\.*/
110+
}
111+
POLICY
112+
}
113+
}
114+
}
115+
}
116+
}
117+
```
118+
40119
## Example Multi Region Configuration:
41120
```hcl
42121
module "aws_config_rules_us_east_1" {
@@ -131,7 +210,10 @@ module "aws_config_rules_us_west_2" {
131210
|------|-------------|------|---------|:--------:|
132211
| <a name="input_aws_managed_rules"></a> [aws\_managed\_rules](#input\_aws\_managed\_rules) | A list of AWS Managed Rules that should be enabled on the account.<br><br>See the following for a list of possible rules to enable:<br>https://docs.aws.amazon.com/config/latest/developerguide/managed-rules-by-aws-config.html | <pre>map(object({<br> description = string<br> identifier = string<br> input_parameters = any<br> }))</pre> | `{}` | no |
133212
| <a name="input_custom_managed_rules"></a> [custom\_managed\_rules](#input\_custom\_managed\_rules) | A list of AWS Managed Custom Rules that should be enabled on the account.<br><br>Reference<br>https://docs.aws.amazon.com/config/latest/developerguide/evaluate-config_develop-rules.html | `map(any)` | `{}` | no |
213+
| <a name="input_enable_default_aws_managed_rules"></a> [enable\_default\_aws\_managed\_rules](#input\_enable\_default\_aws\_managed\_rules) | True/False to add default Config Rules. Default is true | `bool` | `true` | no |
134214
| <a name="input_input_tags"></a> [input\_tags](#input\_input\_tags) | Map of tags to apply to resources | `map(any)` | <pre>{<br> "Developer": "StratusGrid",<br> "Provisioner": "Terraform"<br>}</pre> | no |
215+
| <a name="input_required_tags"></a> [required\_tags](#input\_required\_tags) | Map of tag keys, and optionally values, that are required. | `map(any)` | `{}` | no |
216+
| <a name="input_required_tags_enabled"></a> [required\_tags\_enabled](#input\_required\_tags\_enabled) | True/False to add RequiredTags to Config. Default is false | `bool` | `false` | no |
135217

136218
## Outputs
137219

examples/single-region/example1.tfnot

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,4 @@ module "aws_config_rules_us_east_1" {
33
# StratusGrid recommends pinning every module to a specific version
44
version = "x.x.x"
55

6-
include_global_resource_rules = true #only include global resource on one region to prevent duplicate rules
7-
required_tags_enabled = true
8-
9-
required_tags = { # Yes, the actual required format is tag#Key and tag#Value
10-
tag1Key = "Provisioner"
11-
tag1Value = "Terraform"
12-
tag2Key = "Customer"
13-
tag3Key = "Application"
14-
}
156
}

examples/single-region/example2.tfnot

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module "aws_config_rules_us_east_1" {
2+
source = "StratusGrid/config-rules/aws"
3+
# StratusGrid recommends pinning every module to a specific version
4+
version = "x.x.x"
5+
6+
required_tags_enabled = true
7+
required_tags = { # Yes, the actual required format is tag#Key and tag#Value
8+
tag1Key = "Provisioner"
9+
tag1Value = "Terraform"
10+
tag2Key = "Customer"
11+
tag3Key = "Application"
12+
}
13+
14+
}

examples/single-region/example3.tfnot

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module "aws_config_rules_us_east_1" {
2+
source = "StratusGrid/config-rules/aws"
3+
# StratusGrid recommends pinning every module to a specific version
4+
version = "x.x.x"
5+
6+
aws_managed_rules = {
7+
access-keys-rotated = {
8+
description = "Checks if active IAM access keys are rotated (changed) within the number of days specified in maxAccessKeyAge. The rule is NON_COMPLIANT if access keys are not rotated within the specified time period."
9+
identifier = "ACCESS_KEYS_ROTATED"
10+
input_parameters = {
11+
maxAccessKeyAge = "10"
12+
}
13+
}
14+
cloudtrail-security-trail-enabled = {
15+
description = "Checks that there is at least one AWS CloudTrail trail defined with security best practices. This rule is COMPLIANT if there is at least one trail that meets: https://docs.aws.amazon.com/config/latest/developerguide/cloudtrail-security-trail-enabled.html"
16+
identifier = "CLOUDTRAIL_SECURITY_TRAIL_ENABLED"
17+
input_parameters = {}
18+
}
19+
}
20+
}

examples/single-region/example4.tfnot

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module "aws_config_rules_us_east_1" {
2+
source = "StratusGrid/config-rules/aws"
3+
# StratusGrid recommends pinning every module to a specific version
4+
version = "x.x.x"
5+
6+
custom_managed_rules = {
7+
out-of-scope-ec2-instance-families = {
8+
description = "Ensure EC2 instance configurations do not belong to out-of-scope families."
9+
scope = {
10+
compliance_resource_types = ["AWS::EC2::Instance"]
11+
}
12+
source = {
13+
source_detail = {
14+
message_type = "ConfigurationItemChangeNotification"
15+
}
16+
custom_policy_details = {
17+
policy_runtime = "guard-2.x.x"
18+
policy_text = <<POLICY
19+
rule check_out_of_scope_instance_families when resourceType == "AWS::EC2::Instance" {
20+
configuration.instanceType != /x1e\.*/
21+
configuration.instanceType != /x2i\.*/
22+
}
23+
POLICY
24+
}
25+
}
26+
}
27+
}
28+
}

inputs.tf

Lines changed: 0 additions & 69 deletions
This file was deleted.

locals.tf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Default AWS Manage Rules
2+
locals {
3+
default_aws_managed_rules = var.enable_default_aws_managed_rules == true ? {
4+
root-account-mfa-enabled = {
5+
description = "Checks if the root user of your AWS account requires multi-factor authentication for console sign-in."
6+
identifier = "ROOT_ACCOUNT_MFA_ENABLED"
7+
input_parameters = {}
8+
}
9+
iam-root-access-key-check = {
10+
description = "Checks if the root user access key is available."
11+
identifier = "IAM_ROOT_ACCESS_KEY_CHECK"
12+
input_parameters = {}
13+
}
14+
iam-user-mfa-enabled = {
15+
description = "Checks if the AWS Identity and Access Management (IAM) users have multi-factor authentication (MFA) enabled."
16+
identifier = "IAM_USER_MFA_ENABLED"
17+
input_parameters = {}
18+
}
19+
} : {}
20+
21+
aws_managed_rule_required_tags = var.required_tags_enabled == true ? {
22+
required-tags = {
23+
description = "Checks if your resources have the tags that you specify."
24+
identifier = "REQUIRED_TAGS"
25+
input_parameters = var.required_tags
26+
}
27+
} : {}
28+
29+
# Merge the default rules with the user defined rules
30+
aws_managed_rules = merge(var.aws_managed_rules, local.default_aws_managed_rules, local.aws_managed_rule_required_tags)
31+
32+
}

0 commit comments

Comments
 (0)