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

feat: setup narrower guardrails against aws Nuke #300

Merged
merged 4 commits into from
Jul 23, 2024

Conversation

gcharest
Copy link
Contributor

Summary | Résumé

Attempt to further restrict possible locking out of accounts via AWS Nuke

@gcharest gcharest requested a review from a team July 23, 2024 19:28
@gcharest gcharest self-assigned this Jul 23, 2024
Copy link

Plan for org_account/organization

✅   Terraform Init: success
✅   Terraform Validate: success
✅   Terraform Format: success
✅   Terraform Plan: success
✅   Conftest: success

Plan: 2 to add, 0 to change, 0 to destroy
Show summary
CHANGE NAME
add aws_organizations_policy.aws_nuke_guardrails
aws_organizations_policy_attachment.Test-aws_nuke_guardrails
Show plan
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # aws_organizations_policy.aws_nuke_guardrails will be created
  + resource "aws_organizations_policy" "aws_nuke_guardrails" {
      + arn      = (known after apply)
      + content  = jsonencode(
            {
              + Statement = [
                  + {
                      + Action    = [
                          + "iam:DetachRolePolicy",
                          + "iam:DeleteRolePolicy",
                          + "iam:DeleteRole",
                        ]
                      + Condition = {
                          + ArnNotLike = {
                              + "aws:PrincipalArn" = "arn:aws:iam::*:role/AWSAFTExecution"
                            }
                        }
                      + Effect    = "Deny"
                      + Resource  = [
                          + "arn:aws:iam::*:role/aws-service-role/*",
                          + "arn:aws:iam::*:role/AWSControlTower*",
                        ]
                      + Sid       = "ProtectAWSControlTowerRoles"
                    },
                  + {
                      + Action    = "iam:DeleteSAMLProvider"
                      + Condition = {
                          + ArnNotLike = {
                              + "aws:PrincipalArn" = "arn:aws:iam::*:role/AWSAFTExecution"
                            }
                        }
                      + Effect    = "Deny"
                      + Resource  = "arn:aws:iam::*:saml-provider/AWSSSO_*_DO_NOT_DELETE"
                      + Sid       = "ProtectSAMLProvider"
                    },
                  + {
                      + Action    = [
                          + "iam:DetachRolePolicy",
                          + "iam:DeleteRolePolicy",
                          + "iam:DeleteRole",
                        ]
                      + Condition = {
                          + ArnNotLike = {
                              + "aws:PrincipalArn" = "arn:aws:iam::*:role/AWSAFTExecution"
                            }
                        }
                      + Effect    = "Deny"
                      + Resource  = "arn:aws:iam::*:role/AWSReservedSSO_*"
                      + Sid       = "ProtectSSORoles"
                    },
                  + {
                      + Action    = [
                          + "iam:DetachRolePolicy",
                          + "iam:DeletePolicy",
                        ]
                      + Condition = {
                          + ArnNotLike = {
                              + "aws:PrincipalArn" = "arn:aws:iam::*:role/AWSAFTExecution"
                            }
                        }
                      + Effect    = "Deny"
                      + Resource  = "arn:aws:iam::*:policy/AWSReservedSSO_*"
                      + Sid       = "ProtectSSORolePolicies"
                    },
                ]
              + Version   = "2012-10-17"
            }
        )
      + id       = (known after apply)
      + name     = "Control Tower Guardrails"
      + tags_all = (known after apply)
      + type     = "SERVICE_CONTROL_POLICY"
    }

  # aws_organizations_policy_attachment.Test-aws_nuke_guardrails will be created
  + resource "aws_organizations_policy_attachment" "Test-aws_nuke_guardrails" {
      + id        = (known after apply)
      + policy_id = (known after apply)
      + target_id = "ou-5gsq-ectrrn9m"
    }

Plan: 2 to add, 0 to change, 0 to destroy.

─────────────────────────────────────────────────────────────────────────────

Saved the plan to: plan.tfplan

To perform exactly these actions, run the following command to apply:
    terraform apply "plan.tfplan"
Show Conftest results
WARN - plan.json - main - Missing Common Tags: ["aws_organizations_organizational_unit.AFT"]
WARN - plan.json - main - Missing Common Tags: ["aws_organizations_organizational_unit.DumpsterFire"]
WARN - plan.json - main - Missing Common Tags: ["aws_organizations_organizational_unit.Production"]
WARN - plan.json - main - Missing Common Tags: ["aws_organizations_organizational_unit.SRETools"]
WARN - plan.json - main - Missing Common Tags: ["aws_organizations_organizational_unit.Sandbox"]
WARN - plan.json - main - Missing Common Tags: ["aws_organizations_organizational_unit.Security"]
WARN - plan.json - main - Missing Common Tags: ["aws_organizations_organizational_unit.Staging"]
WARN - plan.json - main - Missing Common Tags: ["aws_organizations_organizational_unit.Test"]
WARN - plan.json - main - Missing Common Tags: ["aws_organizations_policy.aws_nuke_guardrails"]
WARN - plan.json - main - Missing Common Tags: ["aws_organizations_policy.cds_snc_universal_guardrails"]
WARN - plan.json - main - Missing Common Tags: ["aws_organizations_policy.qurantine_deny_all_policy"]

30 tests, 19 passed, 11 warnings, 0 failures, 0 exceptions

Copy link

Plan for org_account/roles

✅   Terraform Init: success
✅   Terraform Validate: success
✅   Terraform Format: success
✅   Terraform Plan: success
✅   Conftest: success

Plan: 0 to add, 2 to change, 0 to destroy
Show summary
CHANGE NAME
update aws_iam_policy.sre_bot_policy
aws_iam_role.sre_bot
Show plan
Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # aws_iam_policy.sre_bot_policy will be updated in-place
  ~ resource "aws_iam_policy" "sre_bot_policy" {
        id        = "arn:aws:iam::659087519042:policy/sre_bot_policy"
        name      = "sre_bot_policy"
      ~ policy    = jsonencode(
          ~ {
              ~ Statement = [
                    # (2 unchanged elements hidden)
                    {
                        Action   = [
                            "identitystore:UpdateUser",
                            "identitystore:ListUsers",
                            "identitystore:ListGroups",
                            "identitystore:ListGroupMembershipsForMember",
                            "identitystore:ListGroupMemberships",
                            "identitystore:IsMemberInGroups",
                            "identitystore:GetUserId",
                            "identitystore:GetGroupMembershipId",
                            "identitystore:GetGroupId",
                            "identitystore:DescribeUser",
                            "identitystore:DescribeGroupMembership",
                            "identitystore:DescribeGroup",
                            "identitystore:DeleteUser",
                            "identitystore:DeleteGroupMembership",
                            "identitystore:CreateUser",
                            "identitystore:CreateGroupMembership",
                        ]
                        Effect   = "Allow"
                        Resource = "*"
                        Sid      = "ManageIdentityStoreUsers"
                    },
                  - {
                      - Action   = [
                          - "sso:List*",
                        ]
                      - Effect   = "Allow"
                      - Resource = [
                          - "*",
                        ]
                      - Sid      = "sso"
                    },
                ]
                # (1 unchanged attribute hidden)
            }
        )
        tags      = {
            "CostCentre" = "cds-aws-lz-production"
            "Terraform"  = "true"
        }
        # (4 unchanged attributes hidden)
    }

  # aws_iam_role.sre_bot will be updated in-place
  ~ resource "aws_iam_role" "sre_bot" {
      ~ assume_role_policy    = (sensitive value)
        id                    = "sre_bot_role"
        name                  = "sre_bot_role"
        tags                  = {
            "CostCentre" = "cds-aws-lz-production"
            "Terraform"  = "true"
        }
        # (9 unchanged attributes hidden)
    }

Plan: 0 to add, 2 to change, 0 to destroy.

─────────────────────────────────────────────────────────────────────────────

Saved the plan to: plan.tfplan

To perform exactly these actions, run the following command to apply:
    terraform apply "plan.tfplan"
Show Conftest results
WARN - plan.json - main - Missing Common Tags: ["aws_iam_policy.org_account_list_in_sandbox"]
WARN - plan.json - main - Missing Common Tags: ["aws_iam_policy.org_allow_policy_toggle"]

21 tests, 19 passed, 2 warnings, 0 failures, 0 exceptions

@gcharest gcharest merged commit 87dc4c5 into main Jul 23, 2024
15 checks passed
@gcharest gcharest deleted the test/narrower_scp_nuke branch July 23, 2024 19:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants