-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CloudFormation Stackset required for enabling multi-account organ…
…ization CloudTrail (#26) ### Added - Auto-deployed CloudFormation StackSet resource when enabling organization trail
- Loading branch information
Showing
6 changed files
with
159 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
data "aws_region" "current" {} | ||
data "aws_caller_identity" "current" {} | ||
data "aws_organizations_organization" "current" {} | ||
|
||
locals { | ||
default_tags = { | ||
"vendor" = "expel" | ||
} | ||
|
||
tags = merge( | ||
var.tags, | ||
local.default_tags, | ||
) | ||
|
||
region = data.aws_region.current.name | ||
customer_aws_account_id = data.aws_caller_identity.current.account_id | ||
customer_aws_organization_id = try(data.aws_organizations_organization.current.roots[0].id, "") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
resource "aws_cloudformation_stack_set" "permeate_account_policy" { | ||
count = var.enable_organization_trail ? 1 : 0 | ||
|
||
name = "PermeateAccountPolicy" | ||
description = "Creates policies in all accounts of the organization for Expel to get basic read permissions of resources in order to investigate alerts" | ||
permission_model = "SERVICE_MANAGED" | ||
capabilities = ["CAPABILITY_NAMED_IAM"] | ||
|
||
auto_deployment { | ||
enabled = true | ||
} | ||
|
||
parameters = { | ||
ExpelCustomerOrganizationGUID = var.expel_customer_organization_guid, | ||
ExpelAssumeRoleARN = aws_iam_role.expel_assume_role.arn | ||
} | ||
|
||
template_body = local.stackset_template | ||
|
||
tags = local.tags | ||
} | ||
|
||
|
||
resource "aws_cloudformation_stack_set_instance" "permeate_account_policy" { | ||
count = var.enable_organization_trail ? 1 : 0 | ||
|
||
deployment_targets { | ||
organizational_unit_ids = [local.customer_aws_organization_id] | ||
} | ||
|
||
region = local.region | ||
stack_set_name = aws_cloudformation_stack_set.permeate_account_policy[0].name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Note: ExpelAccessPolicy is a duplicate policy statement with CloudTrail Manager IAM Policy | ||
locals { | ||
stackset_template = <<TEMPLATE | ||
{ | ||
"AWSTemplateFormatVersion": "2010-09-09", | ||
"Parameters" : { | ||
"ExpelCustomerOrganizationGUID" : { | ||
"Type" : "String" | ||
}, | ||
"ExpelAssumeRoleARN" : { | ||
"Type" : "String" | ||
} | ||
}, | ||
"Resources": { | ||
"IAMR7FYC": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"ManagedPolicyArns": [ | ||
{ | ||
"Ref": "IAMMP12SQ7" | ||
} | ||
], | ||
"RoleName": "ExpelRole", | ||
"AssumeRolePolicyDocument": { | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Principal": { | ||
"AWS": { "Ref": "ExpelAssumeRoleARN" } | ||
}, | ||
"Action": "sts:AssumeRole", | ||
"Condition": { | ||
"StringEquals": { | ||
"sts:ExternalId": { "Ref": "ExpelCustomerOrganizationGUID" } | ||
} | ||
} | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"IAMMP12SQ7": { | ||
"Type": "AWS::IAM::ManagedPolicy", | ||
"Properties": { | ||
"ManagedPolicyName": "ExpelAccessPolicy", | ||
"PolicyDocument": { | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Effect": "Allow", | ||
"Action": [ | ||
"cloudtrail:DescribeTrails", | ||
"cloudtrail:GetTrailStatus", | ||
"config:GetDiscoveredResourceCounts", | ||
"config:ListDiscoveredResources", | ||
"ec2:DescribeInstances", | ||
"ec2:DescribeRegions", | ||
"ec2:DescribeSecurityGroups", | ||
"ec2:DescribeVolumes", | ||
"ecs:DescribeClusters", | ||
"ecs:DescribeContainerInstances", | ||
"ecs:DescribeTaskDefinition", | ||
"ecs:ListClusters", | ||
"ecs:ListContainerInstances", | ||
"ecs:ListTaskDefinitions", | ||
"eks:DescribeCluster", | ||
"eks:ListClusters", | ||
"iam:Get*", | ||
"iam:List*", | ||
"lambda:GetFunction", | ||
"lambda:ListFunctions", | ||
"lightsail:GetInstances", | ||
"lightsail:GetRegions", | ||
"organizations:ListAccounts", | ||
"rds:DescribeDBInstances", | ||
"rds:ListTagsForResource", | ||
"s3:ListAllMyBuckets" | ||
], | ||
"Resource": "*" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
TEMPLATE | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters