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

Adding policies #11

Merged
merged 50 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
78d721d
adding extra policies
jamengual Feb 26, 2021
90a9ed3
adding extra policies
jamengual Feb 26, 2021
1ddfc43
fixing parameter
jamengual Feb 26, 2021
ecad0ab
removing duplicated SCP
jamengual Feb 26, 2021
58fb667
Fixing SCPs
jamengual Feb 26, 2021
46bacd1
Update catalog/sagemaker-policies.yaml
jamengual Feb 26, 2021
974569b
Fixing SCPs
jamengual Feb 26, 2021
ac2b179
Fixing SCPs
jamengual Feb 26, 2021
05b2e0c
Fixing SCPs
jamengual Feb 26, 2021
7ee4b1c
Trying to fix list parameters
jamengual Feb 26, 2021
a304693
Trying to fix list parameters
jamengual Feb 26, 2021
de3aa65
Trying to fix list parameters
jamengual Feb 26, 2021
baff5b4
Trying to fix list parameters
jamengual Feb 26, 2021
299489d
Trying to fix list parameters
jamengual Feb 26, 2021
2aef591
Trying to fix list parameters
jamengual Feb 26, 2021
6cce204
Trying to fix list parameters
jamengual Feb 26, 2021
c03ee28
Fixing yamls
jamengual Feb 28, 2021
5d9a222
Using some of the policies to avoid POLICY_CONTENT_LIMIT_EXCEEDED
jamengual Feb 28, 2021
7a90a5e
Auto Format
cloudpossebot Feb 28, 2021
38f5fa2
Updating values to lists
jamengual Mar 1, 2021
0bf76ae
Auto Format
cloudpossebot Mar 1, 2021
b203cba
FMT
jamengual Mar 1, 2021
dc5ac0a
Merge branch 'adding_policies' of github.com:cloudposse/terraform-aws…
jamengual Mar 1, 2021
17bd6ac
merging master
jamengual Mar 1, 2021
b129668
Addressing PR review
jamengual Mar 2, 2021
f4cfd24
Adding disable roor SCP
jamengual Mar 4, 2021
eea00d5
Removing s3 invalid policy
jamengual Mar 4, 2021
4ad705b
Delete .DS_Store
jamengual Mar 9, 2021
f45cb99
Fixing conflics
jamengual Mar 15, 2021
b4f212c
Merge branch 'adding_policies' of github.com:cloudposse/terraform-aws…
jamengual Mar 15, 2021
18b8a25
Update catalog/cloudwatch-logs-policies.yaml
jamengual Mar 15, 2021
01370e6
Update catalog/ec2-policies.yaml
jamengual Mar 15, 2021
42cee61
Update catalog/ec2-policies.yaml
jamengual Mar 15, 2021
d8ab7fb
Fixing names
jamengual Mar 16, 2021
9153397
passing list to scp
jamengual Mar 23, 2021
ea30579
Auto Format
cloudpossebot Mar 23, 2021
65deebb
Fixing passing lists and adding better region lockdown policy
jamengual Mar 23, 2021
a2eaca0
Fixing passing lists and adding better region lockdown policy
jamengual Mar 23, 2021
5a0aacd
Fixing passing lists and adding better region lockdown policy
jamengual Mar 23, 2021
35a4c27
Auto Format
cloudpossebot Mar 23, 2021
29dc02d
Deleting some rules
jamengual Mar 23, 2021
a74a558
Merge branch 'adding_policies' of github.com:cloudposse/terraform-aws…
jamengual Mar 23, 2021
4bf414a
Fixing templating usinf for
jamengual Mar 24, 2021
77d7fdb
Auto Format
cloudpossebot Mar 24, 2021
75ef711
Fixing templating using for
jamengual Mar 24, 2021
b42da77
Merge branch 'adding_policies' of github.com:cloudposse/terraform-aws…
jamengual Mar 24, 2021
ce3bb52
Adding real regions to example
jamengual Mar 24, 2021
ac553b5
Fixing conflicts
jamengual Mar 23, 2022
b57ee88
Addressing feedback
jamengual Mar 23, 2022
0bad794
Addressing feedback
jamengual Mar 24, 2022
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
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ For additional context, refer to some of these links.
- [Terraform Module Requirements](https://www.terraform.io/docs/registry/modules/publish.html#requirements) - HashiCorp's guidance on all the requirements for publishing a module. Meeting the requirements for publishing a module is extremely easy.
- [Terraform `random_integer` Resource](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/integer) - The resource random_integer generates random values from a given range, described by the min and max attributes of a given resource.
- [Terraform Version Pinning](https://www.terraform.io/docs/configuration/terraform.html#specifying-a-required-terraform-version) - The required_version setting can be used to constrain which versions of the Terraform CLI can be used with your configuration
- [SCPs size limits](https://github.com/hashicorp/terraform-provider-aws/issues/12597) - The SCP have a size limit and creating many policies at once can result in a POLICY_CONTENT_LIMIT_EXCEEDED error


## Help
Expand Down Expand Up @@ -381,14 +382,16 @@ Check out [our other projects][github], [follow us on twitter][twitter], [apply
### Contributors

<!-- markdownlint-disable -->
| [![Erik Osterman][osterman_avatar]][osterman_homepage]<br/>[Erik Osterman][osterman_homepage] | [![Andriy Knysh][aknysh_avatar]][aknysh_homepage]<br/>[Andriy Knysh][aknysh_homepage] |
|---|---|
| [![Erik Osterman][osterman_avatar]][osterman_homepage]<br/>[Erik Osterman][osterman_homepage] | [![Andriy Knysh][aknysh_avatar]][aknysh_homepage]<br/>[Andriy Knysh][aknysh_homepage] | [![PePe Amengual][jamengual_avatar]][jamengual_homepage]<br/>[PePe Amengual][jamengual_homepage] |
|---|---|---|
<!-- markdownlint-restore -->

[osterman_homepage]: https://github.com/osterman
[osterman_avatar]: https://img.cloudposse.com/150x150/https://github.com/osterman.png
[aknysh_homepage]: https://github.com/aknysh
[aknysh_avatar]: https://img.cloudposse.com/150x150/https://github.com/aknysh.png
[jamengual_homepage]: https://github.com/jamengual
[jamengual_avatar]: https://img.cloudposse.com/150x150/https://github.com/jamengual.png

[![README Footer][readme_footer_img]][readme_footer_link]
[![Beacon][beacon]][website]
Expand Down
6 changes: 5 additions & 1 deletion README.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ references:
- name: "Terraform Version Pinning"
description: "The required_version setting can be used to constrain which versions of the Terraform CLI can be used with your configuration"
url: "https://www.terraform.io/docs/configuration/terraform.html#specifying-a-required-terraform-version"

- name: "SCPs size limits"
description: "The SCP have a size limit and creating many policies at once can result in a POLICY_CONTENT_LIMIT_EXCEEDED error"
url: "https://github.com/hashicorp/terraform-provider-aws/issues/12597"
# Short description of this project
description: |-
Terraform module to provision Service Control Policies (SCP) for AWS Organizations, Organizational Units, and AWS accounts.
Expand Down Expand Up @@ -148,3 +150,5 @@ contributors:
github: "osterman"
- name: "Andriy Knysh"
github: "aknysh"
- name: "PePe Amengual"
github: "jamengual"
7 changes: 7 additions & 0 deletions catalog/account-policies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- sid: "DenyAccountRegionDisableEnable"
effect: "Deny"
actions:
- "account:EnableRegion"
- "account:DisableRegion"
resources:
- "*"
9 changes: 9 additions & 0 deletions catalog/cloudtrail-policies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- sid: "DenyCloudTrailActions"
effect: "Deny"
actions:
- "cloudtrail:DeleteTrail"
- "cloudtrail:PutEventSelectors"
- "cloudtrail:StopLogging"
- "cloudtrail:UpdateTrail"
resources:
- "*"
14 changes: 13 additions & 1 deletion catalog/cloudwatch-logs-policies.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
- sid: "DenyDeletingCloudWatchLogs"
- sid: "DenyCloudWatchDeletingLogs"
effect: "Deny"
actions:
- "ec2:DeleteFlowLogs"
- "logs:DeleteLogGroup"
- "logs:DeleteLogStream"
resources:
- "*"

- sid: "DenyDisablingCloudWatch"
effect: "Deny"
actions:
- "cloudwatch:DeleteAlarms"
- "cloudwatch:DeleteDashboards"
- "cloudwatch:DisableAlarmActions"
- "cloudwatch:PutDashboard"
- "cloudwatch:PutMetricAlarm"
- "cloudwatch:SetAlarmState"
resources:
- "*"
12 changes: 12 additions & 0 deletions catalog/config-policies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- sid: "DenyConfigRulesDelete"
effect: "Deny"
actions:
- "config:DeleteConfigRule"
- "config:DeleteConfigurationRecorder"
- "config:DeleteDeliveryChannel"
- "config:StopConfigurationRecorder"
- "config:DeleteRetentionConfiguration"
- "config:DeleteEvaluationResults"
- "config:DeleteConfigurationAggregator"
resources:
- "*"
78 changes: 76 additions & 2 deletions catalog/ec2-policies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# This policy denies instance types that aren't based on the Nitro system as documented in the following document:
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html#ec2-nitro-instances
#
- sid: "DenyNonNitroInstances"
- sid: "DenyEC2NonNitroInstances"
effect: "Deny"
actions:
- "ec2:RunInstances"
Expand Down Expand Up @@ -83,7 +83,7 @@
# This policy denies instance types that aren't based on the Nitro system and don't support Encryption-in-Transit as
# described in the following document:
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/data-protection.html#encryption-transit
- sid: "DenyInstancesWithoutEncryptionInTransit"
- sid: "DenyEC2InstancesWithoutEncryptionInTransit"
effect: "Deny"
actions:
- "ec2:RunInstances"
Expand All @@ -109,3 +109,77 @@
- r5n
resources:
- "arn:aws:ec2:*:*:instance/*"

- sid: "DenyEC2PublicAMI"
effect: "Deny"
actions:
- "ec2:RunInstances"
condition:
- test: "Bool"
variable: "ec2:Public"
values:
- true
resources:
- "arn:aws:ec2:*::image/*"

- sid: "DenyEC2AssociatePublicIp"
effect: "Deny"
actions:
- "ec2:RunInstances"
condition:
- test: "Bool"
variable: "ec2:AssociatePublicIpAddress"
values:
- true
resources:
- "arn:aws:ec2:*:*:network-interface/*"

- sid: "DenyEC2AMIWithNoResourceTag"
effect: "Deny"
actions:
- "ec2:RunInstances"
condition:
- test: "StringNotEqualsIgnoreCase"
variable: "ec2:ResourceTag/${ami_tag_key}"
values:
- "${ami_tag_value}"
resources:
- "arn:aws:ec2:*::image/ami-*"

- sid: "DenyEC2WithNoIMDSv2"
effect: "Deny"
actions:
- "ec2:RunInstances"
condition:
- test: "StringNotEquals"
variable: "ec2:MetadataHttpTokens"
values:
- "required"
resources:
- "arn:aws:ec2:*:*:instance/*"

- sid: "DenyEC2ApiWithNoMFA"
effect: "Deny"
actions:
- "ec2:StopInstances"
- "ec2:TerminateInstances"
- "ec2:SendDiagnosticInterrupt"
condition:
- test: "BoolIfExists"
variable: "aws:MultiFactorAuthPresent"
values:
- false
resources:
- "*"

- sid: "DenyEC2AMINotCreatedBy"
effect: "Deny"
actions:
- "ec2:RunInstances"
condition:
- test: "StringNotEquals"
variable: "ec2:Owner"
values:
- "${ami_creator_account}"
resources:
- "arn:aws:ec2:*::image/ami-*"
43 changes: 43 additions & 0 deletions catalog/guardduty-policies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
- sid: "DenyGuardDutyDisassociation"
effect: "Deny"
actions:
- "guardduty:DisassociateFromMasterAccount"
resources:
- "*"

- sid: "DenyDisablingGuardDuty"
effect: "Deny"
actions:
- "guardduty:AcceptInvitation"
- "guardduty:ArchiveFindings"
- "guardduty:CreateDetector"
- "guardduty:CreateFilter"
- "guardduty:CreateIPSet"
- "guardduty:CreateMembers"
- "guardduty:CreatePublishingDestination"
- "guardduty:CreateSampleFindings"
- "guardduty:CreateThreatIntelSet"
- "guardduty:DeclineInvitations"
- "guardduty:DeleteDetector"
- "guardduty:DeleteFilter"
- "guardduty:DeleteInvitations"
- "guardduty:DeleteIPSet"
- "guardduty:DeleteMembers"
- "guardduty:DeletePublishingDestination"
- "guardduty:DeleteThreatIntelSet"
- "guardduty:DisassociateFromMasterAccount"
- "guardduty:DisassociateMembers"
- "guardduty:InviteMembers"
- "guardduty:StartMonitoringMembers"
- "guardduty:StopMonitoringMembers"
- "guardduty:TagResource"
- "guardduty:UnarchiveFindings"
- "guardduty:UntagResource"
- "guardduty:UpdateDetector"
- "guardduty:UpdateFilter"
- "guardduty:UpdateFindingsFeedback"
- "guardduty:UpdateIPSet"
- "guardduty:UpdatePublishingDestination"
- "guardduty:UpdateThreatIntelSet"
resources:
- "*"
35 changes: 32 additions & 3 deletions catalog/iam-policies.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
- sid: "DenyCreatingIAMUsers"
- sid: "DenyIAMCreatingUsers"
jamengual marked this conversation as resolved.
Show resolved Hide resolved
effect: "Deny"
actions:
- "iam:CreateUser"
- "iam:CreateAccessKey"
resources:
- "*"


- sid: "ProtectIAMRoles"
- sid: "DenyIAMRolesChanges"
effect: "Deny"
actions:
- "iam:AttachRolePolicy"
Expand All @@ -22,3 +21,33 @@
- "iam:UpdateRoleDescription"
resources:
- "*"

- sid: "DenyIAMNoMFA"
effect: "Deny"
not_actions:
- "iam:CreateVirtualMFADevice"
- "iam:EnableMFADevice"
- "iam:GetUser"
- "iam:ListMFADevices"
- "iam:ListVirtualMFADevices"
- "iam:ResyncMFADevice"
- "sts:GetSessionToken"
condition:
- test: "BoolIfExists"
variable: "aws:MultiFactorAuthPresent"
values:
jamengual marked this conversation as resolved.
Show resolved Hide resolved
- false
resources:
- "*"

- sid: "DenyIAMRootAccount"
effect: "Deny"
actions:
- "*"
condition:
- test: "StringLike"
variable: "aws:PrincipalArn"
values:
- "arn:aws:iam::*:root"
resources:
- "*"
12 changes: 12 additions & 0 deletions catalog/lambda-policies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
- sid: "DenyLambdaWithoutVpc"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jamengual is this policy correct?

  1. It says "Deny" but the value is true - should it be "false"?
  2. Other policies use "Bool" in the test, not "Null"
condition:
    - test: "Bool"
      variable: "rds:StorageEncrypted"
      values:
        - false

effect: "Deny"
actions:
- "lambda:CreateFunction"
- "lambda:UpdateFunctionConfiguration"
condition:
- test: "Null"
variable: "lambda:VpcIds"
values:
- true
resources:
- "*"
5 changes: 2 additions & 3 deletions catalog/organization-policies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
resources:
- "*"


- sid: "DenyRootAccountAccess"
effect: "Deny"
actions:
- "*"
resources:
- "*"
condition:
- test: "StringLike"
variable: "aws:PrincipalArn"
values:
- "arn:aws:iam::*:root"
resources:
- "*"
16 changes: 16 additions & 0 deletions catalog/rds-policies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- sid: "DenyRDSUnencrypted"
effect: "Deny"
actions:
- "rds:CreateDBCluster"
- "rds:CreateDBInstance"
- "rds:RestoreDBClusterFromS3"
- "rds:RestoreDBInstanceFromS3"
- "rds:RestoreDBClusterFromDBSnapshot"
- "rds:RestoreDBClusterToPointInTime"
condition:
- test: "Bool"
variable: "rds:StorageEncrypted"
values:
- false
resources:
- "*"
23 changes: 23 additions & 0 deletions catalog/region-specific-policies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
- sid: "DenyRegionUsage"
effect: "Deny"
not_actions:
aknysh marked this conversation as resolved.
Show resolved Hide resolved
- "cloudfront:*"
- "iam:*"
- "route53:*"
- "support:*"
- "organizations:*"
- "waf:*"
- "budgets:*"
- "globalaccelerator:*"
- "cur:*"
- "ce:*"
- "directconnect:*"
condition:
- test: "StringNotEqualsIgnoreCase"
variable: "aws:RequestedRegion"
values:
# The regions that can't be used for deploying infrastructure
- "${region1_lockdown}"
jamengual marked this conversation as resolved.
Show resolved Hide resolved
jamengual marked this conversation as resolved.
Show resolved Hide resolved
- "${region2_lockdown}"
jamengual marked this conversation as resolved.
Show resolved Hide resolved
resources:
- "*"
2 changes: 1 addition & 1 deletion catalog/route53-policies.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- sid: "DenyDeletingRoute53Zones"
- sid: "DenyRoute53DeletingZones"
effect: "Deny"
actions:
- "route53:DeleteHostedZone"
Expand Down
Loading