Skip to content

Commit 4bbca89

Browse files
authored
chore: update examples for security best practices and Bridgecrew monitoring (#6)
1 parent 3550f1b commit 4bbca89

File tree

10 files changed

+205
-60
lines changed

10 files changed

+205
-60
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
repos:
22
- repo: git://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.50.0
3+
rev: v1.51.0
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_docs
77
- repo: git://github.com/pre-commit/pre-commit-hooks
8-
rev: v3.4.0
8+
rev: v4.0.1
99
hooks:
1010
- id: check-merge-conflict

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,21 @@ Examples codified under the [`examples`](./examples) are intended to give users
6161
- [IAM auth. w/ PostgreSQL Aurora cluster](./examples/postgresql_iam_cluster)
6262
- [IAM auth. w/ PostgreSQL RDS instance](./examples/postgresql_iam_instance)
6363

64+
## Security & Compliance [<img src="https://cloudposse.com/wp-content/uploads/2020/11/bridgecrew.svg" width="250" align="right" />](https://bridgecrew.io/)
65+
66+
Security scanning results provided by Bridgecrew. Bridgecrew is the leading fully hosted, cloud-native solution providing continuous Terraform security and compliance.
67+
68+
| Benchmark | Description |
69+
|--------|---------------|
70+
| [![Infrastructure Tests](https://www.bridgecrew.cloud/badges/github/clowdhaus/terraform-aws-rds-proxy/general)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=clowdhaus%2Fterraform-aws-rds-proxy&benchmark=INFRASTRUCTURE+SECURITY) | Infrastructure Security Compliance |
71+
| [![Infrastructure Tests](https://www.bridgecrew.cloud/badges/github/clowdhaus/terraform-aws-rds-proxy/cis_aws)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=clowdhaus%2Fterraform-aws-rds-proxy&benchmark=CIS+AWS+V1.2) | Center for Internet Security, AWS Compliance |
72+
| [![Infrastructure Tests](https://www.bridgecrew.cloud/badges/github/clowdhaus/terraform-aws-rds-proxy/pci_dss_v321)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=clowdhaus%2Fterraform-aws-rds-proxy&benchmark=PCI-DSS+V3.2.1) | Payment Card Industry Data Security Standards Compliance |
73+
| [![Infrastructure Tests](https://www.bridgecrew.cloud/badges/github/clowdhaus/terraform-aws-rds-proxy/nist)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=clowdhaus%2Fterraform-aws-rds-proxy&benchmark=NIST-800-53) | National Institute of Standards and Technology Compliance |
74+
| [![Infrastructure Tests](https://www.bridgecrew.cloud/badges/github/clowdhaus/terraform-aws-rds-proxy/iso)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=clowdhaus%2Fterraform-aws-rds-proxy&benchmark=ISO27001) | Information Security Management System, ISO/IEC 27001 Compliance |
75+
| [![Infrastructure Tests](https://www.bridgecrew.cloud/badges/github/clowdhaus/terraform-aws-rds-proxy/soc2)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=clowdhaus%2Fterraform-aws-rds-proxy&benchmark=SOC2) | Service Organization Control 2 Compliance |
76+
| [![Infrastructure Tests](https://www.bridgecrew.cloud/badges/github/clowdhaus/terraform-aws-rds-proxy/hipaa)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=clowdhaus%2Fterraform-aws-rds-proxy&benchmark=HIPAA) | Health Insurance Portability and Accountability Compliance |
77+
| [![Infrastructure Tests](https://www.bridgecrew.cloud/badges/github/clowdhaus/terraform-aws-rds-proxy/fedramp_moderate)](https://www.bridgecrew.cloud/link/badge?vcs=github&fullRepo=clowdhaus%2Fterraform-aws-rds-proxy&benchmark=FEDRAMP+%28MODERATE%29) | FedRAMP Moderate Impact Level |
78+
6479
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
6580
## Requirements
6681

examples/mysql_iam_cluster/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ An EC2 instance configuration has been provided for use in validating the exampl
3737

3838
| Name | Version |
3939
|------|---------|
40-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.38 |
41-
| <a name="provider_random"></a> [random](#provider\_random) | n/a |
40+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 3.59.0 |
41+
| <a name="provider_random"></a> [random](#provider\_random) | 3.1.0 |
4242

4343
## Modules
4444

4545
| Name | Source | Version |
4646
|------|--------|---------|
47-
| <a name="module_ec2_instance"></a> [ec2\_instance](#module\_ec2\_instance) | terraform-aws-modules/ec2-instance/aws | ~> 2 |
47+
| <a name="module_ec2_instance"></a> [ec2\_instance](#module\_ec2\_instance) | terraform-aws-modules/ec2-instance/aws | ~> 3 |
4848
| <a name="module_ec2_sg"></a> [ec2\_sg](#module\_ec2\_sg) | terraform-aws-modules/security-group/aws | ~> 4 |
4949
| <a name="module_rds"></a> [rds](#module\_rds) | terraform-aws-modules/rds-aurora/aws | ~> 4 |
50-
| <a name="module_rds_proxy"></a> [rds\_proxy](#module\_rds\_proxy) | ../../ | |
50+
| <a name="module_rds_proxy"></a> [rds\_proxy](#module\_rds\_proxy) | ../../ | n/a |
5151
| <a name="module_rds_proxy_sg"></a> [rds\_proxy\_sg](#module\_rds\_proxy\_sg) | terraform-aws-modules/security-group/aws | ~> 4 |
5252
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3 |
5353

examples/mysql_iam_cluster/main.tf

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ module "vpc" {
5151
create_database_subnet_group = true
5252
enable_nat_gateway = true
5353
single_nat_gateway = true
54+
map_public_ip_on_launch = false
55+
56+
manage_default_security_group = true
57+
default_security_group_ingress = []
58+
default_security_group_egress = []
59+
60+
enable_flow_log = true
61+
flow_log_destination_type = "cloud-watch-logs"
62+
create_flow_log_cloudwatch_log_group = true
63+
create_flow_log_cloudwatch_iam_role = true
64+
flow_log_max_aggregation_interval = 60
65+
flow_log_log_format = "$${version} $${account-id} $${interface-id} $${srcaddr} $${dstaddr} $${srcport} $${dstport} $${protocol} $${packets} $${bytes} $${start} $${end} $${action} $${log-status} $${vpc-id} $${subnet-id} $${instance-id} $${tcp-flags} $${type} $${pkt-srcaddr} $${pkt-dstaddr} $${region} $${az-id} $${sublocation-type} $${sublocation-id}"
5466

5567
tags = local.tags
5668
}
@@ -71,13 +83,18 @@ module "rds" {
7183
engine_version = "5.7"
7284
replica_count = 1
7385
instance_type = "db.t3.medium"
74-
storage_encrypted = false
86+
storage_encrypted = true
7587
apply_immediately = true
7688
skip_final_snapshot = true
7789

78-
vpc_id = module.vpc.vpc_id
79-
subnets = module.vpc.database_subnets
80-
allowed_security_groups = [module.rds_proxy_sg.security_group_id]
90+
enabled_cloudwatch_logs_exports = ["general", "error", "slowquery"]
91+
monitoring_interval = 60
92+
create_monitoring_role = true
93+
94+
vpc_id = module.vpc.vpc_id
95+
subnets = module.vpc.database_subnets
96+
create_security_group = false
97+
vpc_security_group_ids = [module.rds_proxy_sg.security_group_id]
8198

8299
db_subnet_group_name = local.name # Created by VPC module
83100
db_parameter_group_name = aws_db_parameter_group.aurora_db_mysql57_parameter_group.id
@@ -90,12 +107,16 @@ resource "aws_db_parameter_group" "aurora_db_mysql57_parameter_group" {
90107
name = "example-aurora-db-57-parameter-group"
91108
family = "aurora-mysql5.7"
92109
description = "example-aurora-db-57-parameter-group"
110+
111+
tags = local.tags
93112
}
94113

95114
resource "aws_rds_cluster_parameter_group" "aurora_cluster_mysql57_parameter_group" {
96115
name = "example-aurora-57-cluster-parameter-group"
97116
family = "aurora-mysql5.7"
98117
description = "example-aurora-57-cluster-parameter-group"
118+
119+
tags = local.tags
99120
}
100121

101122
################################################################################
@@ -105,6 +126,8 @@ resource "aws_rds_cluster_parameter_group" "aurora_cluster_mysql57_parameter_gro
105126
resource "aws_iam_instance_profile" "ec2_test" {
106127
name_prefix = local.name
107128
role = aws_iam_role.ec2_test.name
129+
130+
tags = local.tags
108131
}
109132

110133
data "aws_iam_policy_document" "ec2_test_assume" {
@@ -121,6 +144,8 @@ resource "aws_iam_role" "ec2_test" {
121144
name_prefix = local.name
122145
force_detach_policies = true
123146
assume_role_policy = data.aws_iam_policy_document.ec2_test_assume.json
147+
148+
tags = local.tags
124149
}
125150

126151
data "aws_iam_policy_document" "ec2_test" {
@@ -171,14 +196,23 @@ module "ec2_sg" {
171196

172197
module "ec2_instance" {
173198
source = "terraform-aws-modules/ec2-instance/aws"
174-
version = "~> 2"
199+
version = "~> 3"
200+
201+
name = local.name
175202

176-
name = local.name
177-
instance_count = 1
203+
monitoring = true
204+
ebs_optimized = true
205+
metadata_options = {
206+
http_endpoint = "disabled"
207+
}
208+
root_block_device = [
209+
{
210+
encrypted = true
211+
}
212+
]
178213

179-
associate_public_ip_address = true
180-
iam_instance_profile = aws_iam_instance_profile.ec2_test.name
181-
user_data = <<-EOT
214+
iam_instance_profile = aws_iam_instance_profile.ec2_test.name
215+
user_data = <<-EOT
182216
#!/usr/bin/env bash
183217
184218
mkdir -p /home/ssm-user/ && wget -O /home/ssm-user/AmazonRootCA1.pem https://www.amazontrust.com/repository/AmazonRootCA1.pem
@@ -191,7 +225,7 @@ module "ec2_instance" {
191225
ami = data.aws_ami.ubuntu.id
192226
instance_type = "t3.micro"
193227
vpc_security_group_ids = [module.ec2_sg.security_group_id]
194-
subnet_ids = module.vpc.private_subnets
228+
subnet_id = element(module.vpc.private_subnets, 0)
195229

196230
tags = local.tags
197231
}

examples/mysql_iam_instance/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ An EC2 instance configuration has been provided for use in validating the exampl
3737

3838
| Name | Version |
3939
|------|---------|
40-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.38 |
41-
| <a name="provider_random"></a> [random](#provider\_random) | n/a |
40+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 3.59.0 |
41+
| <a name="provider_random"></a> [random](#provider\_random) | 3.1.0 |
4242

4343
## Modules
4444

4545
| Name | Source | Version |
4646
|------|--------|---------|
47-
| <a name="module_ec2_instance"></a> [ec2\_instance](#module\_ec2\_instance) | terraform-aws-modules/ec2-instance/aws | ~> 2 |
47+
| <a name="module_ec2_instance"></a> [ec2\_instance](#module\_ec2\_instance) | terraform-aws-modules/ec2-instance/aws | ~> 3 |
4848
| <a name="module_ec2_sg"></a> [ec2\_sg](#module\_ec2\_sg) | terraform-aws-modules/security-group/aws | ~> 4 |
4949
| <a name="module_rds"></a> [rds](#module\_rds) | terraform-aws-modules/rds/aws | ~> 3 |
50-
| <a name="module_rds_proxy"></a> [rds\_proxy](#module\_rds\_proxy) | ../../ | |
50+
| <a name="module_rds_proxy"></a> [rds\_proxy](#module\_rds\_proxy) | ../../ | n/a |
5151
| <a name="module_rds_proxy_sg"></a> [rds\_proxy\_sg](#module\_rds\_proxy\_sg) | terraform-aws-modules/security-group/aws | ~> 4 |
5252
| <a name="module_rds_sg"></a> [rds\_sg](#module\_rds\_sg) | terraform-aws-modules/security-group/aws | ~> 4 |
5353
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3 |

examples/mysql_iam_instance/main.tf

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,21 @@ module "vpc" {
4848
private_subnets = ["10.0.3.0/24", "10.0.4.0/24", "10.0.5.0/24"]
4949
database_subnets = ["10.0.7.0/24", "10.0.8.0/24", "10.0.9.0/24"]
5050

51-
enable_nat_gateway = true
52-
single_nat_gateway = true
51+
create_database_subnet_group = true
52+
enable_nat_gateway = true
53+
single_nat_gateway = true
54+
map_public_ip_on_launch = false
55+
56+
manage_default_security_group = true
57+
default_security_group_ingress = []
58+
default_security_group_egress = []
59+
60+
enable_flow_log = true
61+
flow_log_destination_type = "cloud-watch-logs"
62+
create_flow_log_cloudwatch_log_group = true
63+
create_flow_log_cloudwatch_iam_role = true
64+
flow_log_max_aggregation_interval = 60
65+
flow_log_log_format = "$${version} $${account-id} $${interface-id} $${srcaddr} $${dstaddr} $${srcport} $${dstport} $${protocol} $${packets} $${bytes} $${start} $${end} $${action} $${log-status} $${vpc-id} $${subnet-id} $${instance-id} $${tcp-flags} $${type} $${pkt-srcaddr} $${pkt-dstaddr} $${region} $${az-id} $${sublocation-type} $${sublocation-id}"
5366

5467
tags = local.tags
5568
}
@@ -94,11 +107,16 @@ module "rds" {
94107
port = 3306
95108
instance_class = "db.t3.micro"
96109
allocated_storage = 5
97-
storage_encrypted = false
110+
storage_encrypted = true
98111
apply_immediately = true
99112

113+
enabled_cloudwatch_logs_exports = ["general", "error", "slowquery"]
114+
monitoring_interval = 60
115+
create_monitoring_role = true
116+
100117
vpc_security_group_ids = [module.rds_sg.security_group_id]
101118
subnet_ids = module.vpc.database_subnets
119+
multi_az = true
102120

103121
maintenance_window = "Mon:00:00-Mon:03:00"
104122
backup_window = "03:00-06:00"
@@ -115,6 +133,8 @@ module "rds" {
115133
resource "aws_iam_instance_profile" "ec2_test" {
116134
name_prefix = local.name
117135
role = aws_iam_role.ec2_test.name
136+
137+
tags = local.tags
118138
}
119139

120140
data "aws_iam_policy_document" "ec2_test_assume" {
@@ -131,6 +151,8 @@ resource "aws_iam_role" "ec2_test" {
131151
name_prefix = local.name
132152
force_detach_policies = true
133153
assume_role_policy = data.aws_iam_policy_document.ec2_test_assume.json
154+
155+
tags = local.tags
134156
}
135157

136158
data "aws_iam_policy_document" "ec2_test" {
@@ -181,14 +203,23 @@ module "ec2_sg" {
181203

182204
module "ec2_instance" {
183205
source = "terraform-aws-modules/ec2-instance/aws"
184-
version = "~> 2"
206+
version = "~> 3"
185207

186-
name = local.name
187-
instance_count = 1
208+
name = local.name
209+
210+
monitoring = true
211+
ebs_optimized = true
212+
metadata_options = {
213+
http_endpoint = "disabled"
214+
}
215+
root_block_device = [
216+
{
217+
encrypted = true
218+
}
219+
]
188220

189-
associate_public_ip_address = true
190-
iam_instance_profile = aws_iam_instance_profile.ec2_test.name
191-
user_data = <<-EOT
221+
iam_instance_profile = aws_iam_instance_profile.ec2_test.name
222+
user_data = <<-EOT
192223
#!/usr/bin/env bash
193224
194225
mkdir -p /home/ssm-user/ && wget -O /home/ssm-user/AmazonRootCA1.pem https://www.amazontrust.com/repository/AmazonRootCA1.pem
@@ -201,7 +232,7 @@ module "ec2_instance" {
201232
ami = data.aws_ami.ubuntu.id
202233
instance_type = "t3.micro"
203234
vpc_security_group_ids = [module.ec2_sg.security_group_id]
204-
subnet_ids = module.vpc.private_subnets
235+
subnet_id = element(module.vpc.private_subnets, 0)
205236

206237
tags = local.tags
207238
}

examples/postgresql_iam_cluster/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ An EC2 instance configuration has been provided for use in validating the exampl
3737

3838
| Name | Version |
3939
|------|---------|
40-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.38 |
41-
| <a name="provider_random"></a> [random](#provider\_random) | n/a |
40+
| <a name="provider_aws"></a> [aws](#provider\_aws) | 3.59.0 |
41+
| <a name="provider_random"></a> [random](#provider\_random) | 3.1.0 |
4242

4343
## Modules
4444

4545
| Name | Source | Version |
4646
|------|--------|---------|
47-
| <a name="module_ec2_instance"></a> [ec2\_instance](#module\_ec2\_instance) | terraform-aws-modules/ec2-instance/aws | ~> 2 |
47+
| <a name="module_ec2_instance"></a> [ec2\_instance](#module\_ec2\_instance) | terraform-aws-modules/ec2-instance/aws | ~> 3 |
4848
| <a name="module_ec2_sg"></a> [ec2\_sg](#module\_ec2\_sg) | terraform-aws-modules/security-group/aws | ~> 4 |
4949
| <a name="module_rds"></a> [rds](#module\_rds) | terraform-aws-modules/rds-aurora/aws | ~> 5 |
50-
| <a name="module_rds_proxy"></a> [rds\_proxy](#module\_rds\_proxy) | ../../ | |
50+
| <a name="module_rds_proxy"></a> [rds\_proxy](#module\_rds\_proxy) | ../../ | n/a |
5151
| <a name="module_rds_proxy_sg"></a> [rds\_proxy\_sg](#module\_rds\_proxy\_sg) | terraform-aws-modules/security-group/aws | ~> 4 |
5252
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3 |
5353

0 commit comments

Comments
 (0)