Skip to content

Commit cae3489

Browse files
committed
Add SCP to deny user create
1 parent 26943c1 commit cae3489

9 files changed

+95
-7
lines changed

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,11 @@ repos:
3737
hooks:
3838
- id: shellcheck
3939
#- id: markdown-link-check
40+
# - repo: https://github.com/igorshubovych/markdownlint-cli
41+
# rev: v0.23.2
42+
# hooks:
43+
# - id: markdownlint
44+
# args: [
45+
# "--config=.mdlrc"
46+
# ]
47+
#default_stages: [commit, push]

.terraform-docs.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1+
2+
# https://terraform-docs.io/user-guide/configuration/
3+
14
formatter: markdown
25
#settings:
36
# anchor: false
47
# html: false
8+
9+
#sort:
10+
# enabled: true
11+
# by: required

.tflint.hcl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11

2+
# https://github.com/terraform-linters/tflint
3+
# https://github.com/terraform-linters/tflint/tree/master/docs/user-guide
4+
25
# Run: tflint --init
36

47
plugin "aws" {
@@ -7,15 +10,33 @@ plugin "aws" {
710
source = "github.com/terraform-linters/tflint-ruleset-aws"
811
}
912

13+
rule "terraform_deprecated_index" {
14+
enabled = true
15+
}
16+
rule "terraform_deprecated_interpolation" {
17+
enabled = true
18+
}
1019
rule "terraform_documented_outputs" {
1120
enabled = true
1221
}
1322
rule "terraform_documented_variables" {
1423
enabled = true
1524
}
25+
rule "terraform_required_providers" {
26+
enabled = true
27+
}
28+
rule "terraform_required_version" {
29+
enabled = true
30+
}
31+
#rule "terraform_standard_module_structure" {
32+
# enabled = true
33+
#}
1634
rule "terraform_typed_variables" {
1735
enabled = true
1836
}
1937
rule "terraform_unused_declarations" {
2038
enabled = true
2139
}
40+
rule "terraform_unused_required_providers" {
41+
enabled = true
42+
}

kms.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Manage KMS keys
33

44
# CloudTrail
5-
# regional replicas ??
5+
# key in region where S3 bucket is. Can be cross account
66
# EBS
77
# regional replicas
88
# S3
@@ -32,7 +32,7 @@
3232
#}
3333

3434
# CloudTrail KMS policy
35-
# Allow access to all accounts and regions
35+
# Allow access to all accounts and regions - Not needed for org controlled trail
3636
#{
3737
# "Sid": "Allow CloudTrail to encrypt logs",
3838
# "Effect": "Allow",

modules/scp/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ No modules.
3333
| [aws_organizations_policy.deny_ebs_default_encryption_disable](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/organizations_policy) | resource |
3434
| [aws_organizations_policy.deny_ecr_create_write](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/organizations_policy) | resource |
3535
| [aws_organizations_policy.deny_guardduty_modify](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/organizations_policy) | resource |
36+
| [aws_organizations_policy.deny_iam_user_create](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/organizations_policy) | resource |
3637
| [aws_organizations_policy.deny_member_leaving](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/organizations_policy) | resource |
3738
| [aws_organizations_policy.deny_s3_public](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/organizations_policy) | resource |
3839
| [aws_organizations_policy.deny_s3_unsecure_requests](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/organizations_policy) | resource |

modules/scp/REFERENCES.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ https://asecure.cloud/l/scp/
55
https://summitroute.com/blog/2020/03/25/aws_scp_best_practices/
66
https://globaldatanet.com/tech-blog/scp-best-practices
77
https://d1.awsstatic.com/whitepapers/building_an_aws_perimeter.pdf
8-
8+
https://cloudsecdocs.com/aws/defensive/resources/scps/#sample-scps
99

1010
Update all SCP to exclude role "arn:aws:iam::*:role/OrganizationAccountAccessRole" from deny policies
1111
As a variable??
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Sid": "DenyECRCreateWrite",
6+
"Effect": "Deny",
7+
"Action": [
8+
"ecr:BatchDeleteImage",
9+
"ecr:CompleteLayerUpload",
10+
"ecr:CreateRepository",
11+
"ecr:DeleteRepository",
12+
"ecr:DeleteRepositoryPolicy",
13+
"ecr:GetRepositoryPolicy",
14+
"ecr:InitiateLayerUpload",
15+
"ecr:PutImage",
16+
"ecr:SetRepositoryPolicy",
17+
"ecr:UploadLayerPart"
18+
],
19+
"Resource": [
20+
"*"
21+
],
22+
"Condition": {
23+
"StringNotLike": {
24+
"aws:PrincipalARN":"arn:aws:sts::*:assumed-role/OrganizationAccountAccessRole/*"
25+
}
26+
}
27+
}
28+
]
29+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Sid": "DenyUserCreate",
6+
"Effect": "Deny",
7+
"Action": [
8+
"iam:CreateUser"
9+
],
10+
"Resource": [
11+
"*"
12+
]
13+
}
14+
]
15+
}

modules/scp/main.tf

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,20 @@ resource "aws_organizations_policy" "deny_guardduty_modify" {
8686
#resource "aws_organizations_policy" "deny_iam_password_policy_modify" {
8787
# count = local.enable && var.enable_iam ? 1 : 0
8888
# name = "deny_iam_password_policy_modify"
89-
# description = "Prevent ECR from being created or written too"
89+
# description = "Prevent IAM password policy from being modified"
9090
# tags = var.tags
9191
# type = "SERVICE_CONTROL_POLICY"
92-
# content = file("${path.module}/files/deny-ecr-create-write.json")
92+
# content = file("${path.module}/files/deny-iam-password-policy-modify.json")
9393
#}
94-
# TODO:
95-
# deny user create
94+
resource "aws_organizations_policy" "deny_iam_user_create" {
95+
count = local.enable && var.enable_iam ? 1 : 0
96+
name = "deny_iam_user_create"
97+
description = "Prevent Users from being created"
98+
tags = var.tags
99+
type = "SERVICE_CONTROL_POLICY"
100+
content = file("${path.module}/files/deny-iam-user-create.json")
101+
}
102+
96103
### -----------------------
97104
### Organization
98105
### -----------------------

0 commit comments

Comments
 (0)