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

fix(terraform): tighten the permission on state bucket #126

Closed
wants to merge 1 commit into from

Conversation

JoshuaLicense
Copy link
Contributor

Description

Tighten the state bucket permissions. Give the read-only OIDC role, only read-only access to the state file.

@JoshuaLicense JoshuaLicense self-assigned this Jun 7, 2024
Copy link
Contributor

github-actions bot commented Jun 7, 2024

Terraform plan for account: nonprod

Commit: 8b29837

Plan summary

2 to add, 0 to change, 2 to destroy

🆕 Creates

module.account-remote-state.module.s3_state_readonly_policy[0].aws_iam_policy.policy[0]
module.account.module.github[0].module.iam_github_oidc_readonly_role[0].aws_iam_role_policy_attachment.this["S3State"]

🗑️ Deletes

module.account-remote-state.module.s3_state_policy[0].aws_iam_policy.policy[0]
module.account.module.github[0].module.iam_github_oidc_readonly_role[0].aws_iam_role_policy_attachment.this["S3StateLock"]

Show full plan
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create
  - destroy
-/+ destroy and then create replacement

Terraform will perform the following actions:

  # module.account-remote-state.module.s3_state_policy[0].aws_iam_policy.policy[0] must be replaced
-/+ resource "aws_iam_policy" "policy" {
      ~ arn              = "arn:aws:iam::054614622558:policy/vol-app-054614622558-terraform-state-policy" -> (known after apply)
      ~ attachment_count = 1 -> (known after apply)
      ~ description      = "Policy to allow access to the Terraform state in S3" -> "Policy to allow full access to the Terraform state in S3" # forces replacement
      ~ id               = "arn:aws:iam::054614622558:policy/vol-app-054614622558-terraform-state-policy" -> (known after apply)
        name             = "vol-app-054614622558-terraform-state-policy"
      + name_prefix      = (known after apply)
      ~ policy_id        = "ANPAQZN2JAFPIDB6QMBAD" -> (known after apply)
      - tags             = {} -> null
      ~ tags_all         = {} -> (known after apply)
        # (2 unchanged attributes hidden)
    }

  # module.account-remote-state.module.s3_state_readonly_policy[0].aws_iam_policy.policy[0] will be created
  + resource "aws_iam_policy" "policy" {
      + arn              = (known after apply)
      + attachment_count = (known after apply)
      + description      = "Policy to allow readonly access to the Terraform state in S3"
      + id               = (known after apply)
      + name             = "vol-app-054614622558-terraform-state-readonly-policy"
      + name_prefix      = (known after apply)
      + path             = "/"
      + policy           = jsonencode(
            {
              + Statement = [
                  + {
                      + Action   = [
                          + "s3:GetObject",
                          + "s3:ListBucket",
                        ]
                      + Effect   = "Allow"
                      + Resource = "arn:aws:s3:::vol-app-054614622558-terraform-state"
                    },
                ]
              + Version   = "2012-10-17"
            }
        )
      + policy_id        = (known after apply)
      + tags_all         = (known after apply)
    }

  # module.account.module.github[0].module.iam_github_oidc_readonly_role[0].aws_iam_role_policy_attachment.this["S3State"] will be created
  + resource "aws_iam_role_policy_attachment" "this" {
      + id         = (known after apply)
      + policy_arn = "arn:aws:iam::054614622558:policy/vol-app-054614622558-terraform-state-readonly-policy"
      + role       = "vol-app-github-actions-readonly-role"
    }

  # module.account.module.github[0].module.iam_github_oidc_readonly_role[0].aws_iam_role_policy_attachment.this["S3StateLock"] will be destroyed
  # (because key ["S3StateLock"] is not in for_each map)
  - resource "aws_iam_role_policy_attachment" "this" {
      - id         = "vol-app-github-actions-readonly-role-20240306201159655000000002" -> null
      - policy_arn = "arn:aws:iam::054614622558:policy/vol-app-054614622558-terraform-state-policy" -> null
      - role       = "vol-app-github-actions-readonly-role" -> null
    }

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

@JoshuaLicense JoshuaLicense deleted the add-readonly-state-policy branch August 7, 2024 15:33
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.

1 participant