Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement | Sync le-template with le-ref-arch (ISSUE-23) #39

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions template/management/global/organizations/accounts.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#
# Organization accounts
#
# Root account of the organization: mainly used for consolidated billing reports
# but it could also be used to manage the SCPs of the OUs and accounts.
#
# Uncomment after first `apply`
#resource "aws_organizations_account" "management" {
# name = "${var.project_long}-management"
Expand Down
8 changes: 6 additions & 2 deletions template/management/global/organizations/organization.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
resource "aws_organizations_organization" "main" {
# Not needed at first, might be needed later: https://docs.aws.amazon.com/organizations/latest/APIReference/API_EnableAWSServiceAccess.html
aws_service_access_principals = [
"malware-protection.guardduty.amazonaws.com",
"guardduty.amazonaws.com",
"access-analyzer.amazonaws.com",
"aws-artifact-account-sync.amazonaws.com",
"backup.amazonaws.com",
"cloudtrail.amazonaws.com",
"config.amazonaws.com",
"sso.amazonaws.com"
"ram.amazonaws.com",
"sso.amazonaws.com",
"fms.amazonaws.com",
"inspector2.amazonaws.com",
]

# Enable all feature set to enable SCPs
Expand All @@ -25,7 +29,7 @@ resource "aws_organizations_organization" "main" {

#
# Delegate administration of access analyzer to security account
#
#
resource "aws_organizations_delegated_administrator" "access_analyzer_administrator" {
account_id = aws_organizations_account.accounts["security"].id
service_principal = "access-analyzer.amazonaws.com"
Expand Down
86 changes: 86 additions & 0 deletions template/management/global/organizations/policies_scp.tf
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,89 @@ resource "aws_organizations_policy" "standard" {
aws_organizations_organization.main
]
}

#
# Delete protection policy (scp)
#
resource "aws_organizations_policy" "delete_protection" {
name = "delete-protection"
description = "Delete protection"

content = <<JSON
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Statement1",
"Effect": "Deny",
"Action": [
"ec2:DeleteTransitGateway",
"ec2:ModifyTransitGateway",
"ec2:ModifyTransitGatewayVpcAttachment",
"ec2:DeleteTransitGatewayConnectPeer",
"ec2:DeleteTransitGatewayConnect",
"ec2:DeleteTransitGatewayMulticastDomain",
"ec2:DeleteTransitGatewayPeeringAttachment",
"ec2:DeleteTransitGatewayPrefixListReference",
"ec2:DeleteTransitGatewayRoute",
"ec2:DeleteTransitGatewayRouteTable",
"ec2:DeleteTransitGatewayVpcAttachment"
],
"Resource": [
"*"
],
"Condition": {
"ForAnyValue:StringEquals": {
"aws:ResourceTag/protectFromDeletion": [
"true"
]
}
}
}
]
}
JSON
}

#
# Delete protection policy (scp)
#
resource "aws_organizations_policy" "tag_protection" {
name = "tag-protection"
description = "This policy prevents all user but DevOps role to delete or modify tags on EC2, RDs and EKS resources"

content = <<JSON
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Statement1",
"Effect": "Deny",
"Action": [
"ec2:CreateTags",
"ec2:DeleteTags",
"rds:AddTagsToResource",
"rds:RemoveTagsFromResource",
"eks:UntagResource",
"eks:TagResource"
],
"Resource": [
"*"
],
"Condition": {
"StringNotEquals": {
"aws:PrincipalArn": [
"arn:aws:iam::${aws_organizations_account.accounts["shared"].id}:role/DevOps",
]
},
"ForAnyValue:StringEquals": {
"aws:TagKeys": [
"ProtectFromDeletion"
]
}
}
}
]
}
JSON
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,29 @@ resource "aws_organizations_policy_attachment" "policy_attachments" {
aws_organizations_organizational_unit.units
]
}

#
# Delete protection policy attachment
#
resource "aws_organizations_policy_attachment" "delete_protection" {

for_each = { for v in [
"shared",
] : v => v }

policy_id = aws_organizations_policy.delete_protection.id
target_id = aws_organizations_organizational_unit.units[each.value].id
}

#
# Tag protection policy attachment
#
resource "aws_organizations_policy_attachment" "tag_protection" {

for_each = { for v in [
"shared",
] : v => v }

policy_id = aws_organizations_policy.tag_protection.id
target_id = aws_organizations_organizational_unit.units[each.value].id
}
2 changes: 1 addition & 1 deletion template/management/global/sso/config.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ terraform {
required_version = "~> 1.2"

required_providers {
aws = "~> 4.2"
aws = "~> 4.40"
}

backend "s3" {
Expand Down
9 changes: 9 additions & 0 deletions template/management/global/sso/policies.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ data "aws_iam_policy_document" "devops" {
"compute-optimizer:*",
"datasync:*",
"dlm:*",
"ds:*",
"dynamodb:*",
"ec2:*",
"ec2-instance-connect:*",
"ecr:*",
"ecr-public:*",
"ecs:*",
"elasticfilesystem:*",
"eks:*",
"elasticache:*",
"elasticbeanstalk:*",
Expand All @@ -46,10 +49,12 @@ data "aws_iam_policy_document" "devops" {
"kafka:*",
"kms:*",
"lambda:*",
"license-manager:*",
"lightsail:*",
"logs:*",
"network-firewall:*",
"networkmanager:*",
"q:*",
"ram:*",
"rds:*",
"redshift:*",
Expand All @@ -61,12 +66,14 @@ data "aws_iam_policy_document" "devops" {
"route53resolver:*",
"s3:*",
"ses:*",
"secretsmanager:*",
"shield:*",
"sns:*",
"sqs:*",
"ssm:*",
"sts:*",
"support:*",
"servicediscovery:*",
"tag:*",
"transfer:*",
"trustedadvisor:*",
Expand All @@ -75,6 +82,8 @@ data "aws_iam_policy_document" "devops" {
"waf:*",
"wafv2:*",
"waf-regional:*",
"workspaces:*",
"workspaces-web:*",
"wellarchitected:*"
]
resources = ["*"]
Expand Down
8 changes: 8 additions & 0 deletions template/security/primary_region/security-base/account.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ resource "aws_s3_account_public_access_block" "main" {
block_public_acls = true
block_public_policy = true
}

module "root-login-notifications" {
source = "github.com/binbashar/terraform-aws-root-login-notifications.git?ref=v2.3.0"

alarm_suffix = "${var.environment}-account"
send_sns = true
sns_topic_name = var.sns_topic_name_monitoring_sec
}
2 changes: 1 addition & 1 deletion template/security/primary_region/security-base/config.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ terraform {
required_version = "~> 1.2"

required_providers {
aws = "~> 4.0"
aws = "~> 4.10"
}

backend "s3" {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#
# NOTE: In order to enable AccessAnalyzer with the Organization at the zone of
# of trust in the Security account, this account needs to be set as a delegated
# administrator. Such step cannot be performed by Terraform yet so it was set
# up manually as described below:
# https://docs.aws.amazon.com/IAM/latest/UserGuide/access-analyzer-settings.html
#
#
# Access Analyzer
#
resource "aws_accessanalyzer_analyzer" "default" {
Expand Down
10 changes: 10 additions & 0 deletions template/security/primary_region/security-base/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
#=============================#
# Notifications #
#=============================#
#
# AWS SNS -> Lambda -> Slack: tools-monitoring-sec
#
variable "sns_topic_name_monitoring_sec" {
description = ""
default = "sns-topic-slack-notify-monitoring-sec"

#
# security/config/backend.tfvars
#
Expand Down
2 changes: 1 addition & 1 deletion template/shared/primary_region/base-network/config.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ terraform {
required_version = "~> 1.2"

required_providers {
aws = "~> 4.0"
aws = "~> 4.10"
}

backend "s3" {
Expand Down
8 changes: 8 additions & 0 deletions template/shared/primary_region/security-base/account.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ resource "aws_s3_account_public_access_block" "main" {
block_public_acls = true
block_public_policy = true
}

module "root-login-notifications" {
source = "github.com/binbashar/terraform-aws-root-login-notifications.git?ref=v2.3.0"

alarm_suffix = "${var.environment}-account"
send_sns = true
sns_topic_name = var.sns_topic_name_monitoring_sec
}
8 changes: 4 additions & 4 deletions template/shared/primary_region/security-base/config.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
# AWS Provider Settings #
#=============================#
provider "aws" {
region = var.region
profile = var.profile
region = var.region
profile = var.profile
}

#=============================#
# Backend Config (partial) #
#=============================#
terraform {
required_version = ">= 0.14.11"
required_version = "~> 1.2.7"

required_providers {
aws = "~> 3.0"
aws = "~> 4.10"
}

backend "s3" {
Expand Down
11 changes: 11 additions & 0 deletions template/shared/primary_region/security-base/variables.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
#=============================#
# Notifications #
#=============================#
#
# AWS SNS -> Lambda -> Slack: tools-monitoring-sec
#
variable "sns_topic_name_monitoring_sec" {
description = ""
default = "sns-topic-slack-notify-monitoring-sec"
}

#
# shared/config/backend.tfvars
#
Expand Down
Loading