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: switch to central S3 scan object design #226

Merged
merged 3 commits into from
Jul 11, 2022

Conversation

patheard
Copy link
Member

@patheard patheard commented Jul 5, 2022

Summary

Update the S3 scan object Terraform module to switch to the new centralized
design where the S3 scan object lambda function and SNS topic have been
moved to the Scan Files account.

This works by having S3 object creation events forwarded to the Scan Files
account, which then assumes a role in the Forms account to download
and tag the S3 objects being scanned.

Scan-files Forms content scanning centralized drawio

The benefits of this approach are:

  • Forms will no longer need to manage updates to the S3 scan object
    lambda function; and
  • it reduces the number of AWS resources needed in the Forms accounts.

⚠️ Note

It's possible that the first terraform apply will fail as there is some
name overlap between resources being destroyed and created. If it
does, a second terraform apply should fix the issue.

Related

Update the S3 scan object Terraform module to inlude the version
with the following fixes:
- Skip scans of new S3 folders
- Properly interpret SNS messages with a checksum of `None`.
@patheard patheard added the ISTS label Jul 5, 2022
@patheard patheard self-assigned this Jul 5, 2022
@patheard patheard marked this pull request as draft July 5, 2022 20:18
@cds-snc cds-snc deleted a comment from github-actions bot Jul 7, 2022
@patheard patheard force-pushed the chore/s3-scan-object-version-bump branch from 7e315db to 140300d Compare July 7, 2022 22:05
@github-actions
Copy link

github-actions bot commented Jul 8, 2022

⚠ Terrform update available

Terraform: 1.2.4 (using 1.0.10)
Terragrunt: 0.38.4 (using 0.35.6)

@github-actions
Copy link

github-actions bot commented Jul 8, 2022

Staging: app

✅   Terraform Format: success
✅   Terraform Plan: success
✅   Conftest: success

⚠️   WARNING: resources will be destroyed by this change!

Plan: 5 to add, 4 to change, 13 to destroy
Show plan
Resource actions are indicated with the following symbols:
  + create
  ~ update in-place
  - destroy
 <= read (data resources)

Terraform will perform the following actions:

  # module.vault_scan_object.data.aws_iam_policy_document.s3_scan_object will be read during apply
  # (config refers to values not yet known)
 <= data "aws_iam_policy_document" "s3_scan_object"  {
      ~ id      = "1337480517" -> (known after apply)
      ~ json    = jsonencode(
            {
              - Statement = [
                  - {
                      - Action   = "secretsmanager:GetSecretValue"
                      - Effect   = "Allow"
                      - Resource = "arn:aws:secretsmanager:ca-central-1:806545929748:secret:/scan-files/api_auth_token-1tLf9T"
                      - Sid      = ""
                    },
                  - {
                      - Action   = "kms:Decrypt"
                      - Effect   = "Allow"
                      - Resource = "arn:aws:kms:ca-central-1:806545929748:key/*"
                      - Sid      = ""
                    },
                  - {
                      - Action   = [
                          - "s3:PutObjectVersionTagging",
                          - "s3:PutObjectTagging",
                          - "s3:ListBucket",
                          - "s3:GetObjectVersionTagging",
                          - "s3:GetObjectVersion",
                          - "s3:GetObjectTagging",
                          - "s3:GetObject",
                        ]
                      - Effect   = "Allow"
                      - Resource = [
                          - "arn:aws:s3:::forms-staging-vault-file-storage/*",
                          - "arn:aws:s3:::forms-staging-vault-file-storage",
                        ]
                      - Sid      = ""
                    },
                ]
              - Version   = "2012-10-17"
            }
        ) -> (known after apply)
      - version = "2012-10-17" -> null

      ~ statement {
          ~ actions       = [
              + "logs:CreateLogStream",
              + "logs:PutLogEvents",
              - "secretsmanager:GetSecretValue",
            ]
          - not_actions   = [] -> null
          - not_resources = [] -> null
          ~ resources     = [
              - "arn:aws:secretsmanager:ca-central-1:806545929748:secret:/scan-files/api_auth_token-1tLf9T",
              ~ (known after apply),
              ~ (known after apply),
            ]
            # (1 unchanged attribute hidden)
        }
      ~ statement {
          ~ actions       = [
              - "kms:Decrypt",
              + "lambda:InvokeFunction",
            ]
          - not_actions   = [] -> null
          - not_resources = [] -> null
          ~ resources     = [
              - "arn:aws:kms:ca-central-1:806545929748:key/*",
              + "arn:aws:lambda:ca-central-1:806545929748:function:s3-scan-object",
            ]
            # (1 unchanged attribute hidden)
        }
      - statement {
          - actions       = [
              - "s3:GetObject",
              - "s3:GetObjectTagging",
              - "s3:GetObjectVersion",
              - "s3:GetObjectVersionTagging",
              - "s3:ListBucket",
              - "s3:PutObjectTagging",
              - "s3:PutObjectVersionTagging",
            ] -> null
          - effect        = "Allow" -> null
          - not_actions   = [] -> null
          - not_resources = [] -> null
          - resources     = [
              - "arn:aws:s3:::forms-staging-vault-file-storage",
              - "arn:aws:s3:::forms-staging-vault-file-storage/*",
            ] -> null
        }
    }

  # module.vault_scan_object.aws_cloudwatch_log_group.s3_scan_object will be created
  + resource "aws_cloudwatch_log_group" "s3_scan_object" {
      + arn               = (known after apply)
      + id                = (known after apply)
      + name              = "/aws/lambda/s3-scan-object-vault"
      + retention_in_days = 7
      + tags              = {
          + "CostCentre" = "forms-platform-staging"
          + "Terraform"  = "true"
        }
      + tags_all          = {
          + "CostCentre" = "forms-platform-staging"
          + "Terraform"  = "true"
        }
    }

  # module.vault_scan_object.aws_iam_policy.s3_scan_object will be created
  + resource "aws_iam_policy" "s3_scan_object" {
      + arn       = (known after apply)
      + id        = (known after apply)
      + name      = "S3ScanObject-vault"
      + path      = "/"
      + policy    = (known after apply)
      + policy_id = (known after apply)
      + tags_all  = (known after apply)
    }

  # module.vault_scan_object.aws_iam_policy.scan_files[0] will be updated in-place
  ~ resource "aws_iam_policy" "scan_files" {
        id        = "arn:aws:iam::687401027353:policy/ScanFilesGetObjects"
        name      = "ScanFilesGetObjects"
      ~ policy    = jsonencode(
          ~ {
              ~ Statement = [
                  ~ {
                      ~ Action   = [
                          + "s3:PutObjectVersionTagging",
                          + "s3:PutObjectTagging",
                            "s3:ListBucket",
                            # (4 unchanged elements hidden)
                            "s3:GetBucketLocation",
                          + "s3:DeleteObjectVersionTagging",
                          + "s3:DeleteObjectTagging",
                        ]
                        # (3 unchanged elements hidden)
                    },
                  - {
                      - Action   = "sns:Publish"
                      - Effect   = "Allow"
                      - Resource = "arn:aws:sns:ca-central-1:687401027353:s3-scan-object-complete-vault"
                      - Sid      = ""
                    },
                  - {
                      - Action   = [
                          - "kms:GenerateDataKey*",
                          - "kms:Decrypt",
                        ]
                      - Effect   = "Allow"
                      - Resource = "arn:aws:kms:ca-central-1:687401027353:key/aba11930-da25-4771-9149-fd1ad4dd3d63"
                      - Sid      = ""
                    },
                ]
                # (1 unchanged element hidden)
            }
        )
        tags      = {
            "CostCentre" = "forms-platform-staging"
            "Terraform"  = "true"
        }
        # (4 unchanged attributes hidden)
    }

  # module.vault_scan_object.aws_iam_role.s3_scan_object will be created
  + resource "aws_iam_role" "s3_scan_object" {
      + arn                   = (known after apply)
      + assume_role_policy    = jsonencode(
            {
              + Statement = [
                  + {
                      + Action    = "sts:AssumeRole"
                      + Effect    = "Allow"
                      + Principal = {
                          + Service = "lambda.amazonaws.com"
                        }
                      + Sid       = ""
                    },
                ]
              + Version   = "2012-10-17"
            }
        )
      + create_date           = (known after apply)
      + force_detach_policies = false
      + id                    = (known after apply)
      + managed_policy_arns   = (known after apply)
      + max_session_duration  = 3600
      + name                  = "S3ScanObject-vault"
      + name_prefix           = (known after apply)
      + path                  = "/"
      + tags_all              = (known after apply)
      + unique_id             = (known after apply)

      + inline_policy {
          + name   = (known after apply)
          + policy = (known after apply)
        }
    }

  # module.vault_scan_object.aws_iam_role.scan_files[0] will be updated in-place
  ~ resource "aws_iam_role" "scan_files" {
      ~ assume_role_policy    = jsonencode(
          ~ {
              ~ Statement = [
                  ~ {
                      ~ Principal = {
                          ~ AWS = "arn:aws:iam::806545929748:role/scan-files-api" -> [
                              + "arn:aws:iam::806545929748:role/s3-scan-object",
                              + "arn:aws:iam::806545929748:role/scan-files-api",
                            ]
                        }
                        # (3 unchanged elements hidden)
                    },
                ]
                # (1 unchanged element hidden)
            }
        )
        id                    = "ScanFilesGetObjects"
        name                  = "ScanFilesGetObjects"
        tags                  = {
            "CostCentre" = "forms-platform-staging"
            "Terraform"  = "true"
        }
        # (8 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

  # module.vault_scan_object.aws_iam_role_policy_attachment.s3_scan_object will be created
  + resource "aws_iam_role_policy_attachment" "s3_scan_object" {
      + id         = (known after apply)
      + policy_arn = (known after apply)
      + role       = "S3ScanObject-vault"
    }

  # module.vault_scan_object.aws_kms_key.sns_lambda will be destroyed
  - resource "aws_kms_key" "sns_lambda" {
      - arn                                = "arn:aws:kms:ca-central-1:687401027353:key/aba11930-da25-4771-9149-fd1ad4dd3d63" -> null
      - bypass_policy_lockout_safety_check = false -> null
      - customer_master_key_spec           = "SYMMETRIC_DEFAULT" -> null
      - description                        = "S3 scan objects KMS key for Lambda SNS topic" -> null
      - enable_key_rotation                = true -> null
      - id                                 = "aba11930-da25-4771-9149-fd1ad4dd3d63" -> null
      - is_enabled                         = true -> null
      - key_id                             = "aba11930-da25-4771-9149-fd1ad4dd3d63" -> null
      - key_usage                          = "ENCRYPT_DECRYPT" -> null
      - multi_region                       = false -> null
      - policy                             = jsonencode(
            {
              - Statement = [
                  - {
                      - Action    = "kms:*"
                      - Effect    = "Allow"
                      - Principal = {
                          - AWS = "arn:aws:iam::687401027353:root"
                        }
                      - Resource  = "*"
                      - Sid       = ""
                    },
                  - {
                      - Action    = [
                          - "kms:GenerateDataKey*",
                          - "kms:Decrypt",
                        ]
                      - Effect    = "Allow"
                      - Principal = {
                          - AWS     = "arn:aws:iam::687401027353:role/ScanFilesGetObjects"
                          - Service = "lambda.amazonaws.com"
                        }
                      - Resource  = "*"
                      - Sid       = ""
                    },
                ]
              - Version   = "2012-10-17"
            }
        ) -> null
      - tags                               = {
          - "CostCentre" = "forms-platform-staging"
          - "Terraform"  = "true"
        } -> null
      - tags_all                           = {
          - "CostCentre" = "forms-platform-staging"
          - "Terraform"  = "true"
        } -> null
    }

  # module.vault_scan_object.aws_lambda_function.s3_scan_object will be created
  + resource "aws_lambda_function" "s3_scan_object" {
      + architectures                  = (known after apply)
      + arn                            = (known after apply)
      + filename                       = "/tmp/main.py.zip"
      + function_name                  = "s3-scan-object-vault"
      + handler                        = "main.handler"
      + id                             = (known after apply)
      + invoke_arn                     = (known after apply)
      + last_modified                  = (known after apply)
      + memory_size                    = 512
      + package_type                   = "Zip"
      + publish                        = false
      + qualified_arn                  = (known after apply)
      + reserved_concurrent_executions = 3
      + role                           = (known after apply)
      + runtime                        = "python3.8"
      + signing_job_arn                = (known after apply)
      + signing_profile_version_arn    = (known after apply)
      + source_code_hash               = "H+LWBR73DEeblAitNF5EPT8Pi5KToRQJ/rlEwevztiY="
      + source_code_size               = (known after apply)
      + tags                           = {
          + "CostCentre" = "forms-platform-staging"
          + "Terraform"  = "true"
        }
      + tags_all                       = {
          + "CostCentre" = "forms-platform-staging"
          + "Terraform"  = "true"
        }
      + timeout                        = 3
      + version                        = (known after apply)

      + environment {
          + variables = {
              + "ACCOUNT_ID"                  = "687401027353"
              + "S3_SCAN_OBJECT_FUNCTION_ARN" = "arn:aws:lambda:ca-central-1:806545929748:function:s3-scan-object"
            }
        }

      + tracing_config {
          + mode = "PassThrough"
        }
    }

  # module.vault_scan_object.aws_lambda_permission.scan_complete will be destroyed
  - resource "aws_lambda_permission" "scan_complete" {
      - action        = "lambda:InvokeFunction" -> null
      - function_name = "s3-scan-object-vault" -> null
      - id            = "S3ScanObjectSNSInvoke-vault" -> null
      - principal     = "sns.amazonaws.com" -> null
      - source_arn    = "arn:aws:sns:ca-central-1:687401027353:s3-scan-object-complete-vault" -> null
      - statement_id  = "S3ScanObjectSNSInvoke-vault" -> null
    }

  # module.vault_scan_object.aws_s3_bucket_notification.s3_scan_object will be updated in-place
  ~ resource "aws_s3_bucket_notification" "s3_scan_object" {
        id     = "forms-staging-vault-file-storage"
        # (1 unchanged attribute hidden)

      ~ lambda_function {
            id                  = "ScanObjectCreated"
          ~ lambda_function_arn = "arn:aws:lambda:ca-central-1:687401027353:function:s3-scan-object-vault" -> (known after apply)
            # (1 unchanged attribute hidden)
        }
    }

  # module.vault_scan_object.aws_s3_bucket_policy.upload_bucket[0] will be updated in-place
  ~ resource "aws_s3_bucket_policy" "upload_bucket" {
        id     = "forms-staging-vault-file-storage"
      ~ policy = jsonencode(
          ~ {
              ~ Statement = [
                  ~ {
                      ~ Condition = {
                          ~ StringNotLike = {
                              ~ aws:PrincipalArn = [
                                  - "arn:aws:iam::687401027353:role/s3-scan-object-vault",
                                  + "arn:aws:iam::687401027353:role/ScanFilesGetObjects",
                                ]
                            }
                        }
                        # (5 unchanged elements hidden)
                    },
                  ~ {
                      ~ Principal = {
                          ~ AWS = "arn:aws:iam::687401027353:role/s3-scan-object-vault" -> "arn:aws:iam::687401027353:role/ScanFilesGetObjects"
                        }
                        # (4 unchanged elements hidden)
                    },
                    {
                        Action    = [
                            "s3:ListBucket",
                            "s3:GetObjectVersionTagging",
                            "s3:GetObjectVersion",
                            "s3:GetObjectTagging",
                            "s3:GetObject",
                            "s3:GetBucketLocation",
                        ]
                        Effect    = "Allow"
                        Principal = {
                            AWS = "arn:aws:iam::687401027353:role/ScanFilesGetObjects"
                        }
                        Resource  = [
                            "arn:aws:s3:::forms-staging-vault-file-storage/*",
                            "arn:aws:s3:::forms-staging-vault-file-storage",
                        ]
                        Sid       = ""
                    },
                ]
                # (1 unchanged element hidden)
            }
        )
        # (1 unchanged attribute hidden)
    }

  # module.vault_scan_object.aws_sns_topic.scan_complete will be destroyed
  - resource "aws_sns_topic" "scan_complete" {
      - application_success_feedback_sample_rate = 0 -> null
      - arn                                      = "arn:aws:sns:ca-central-1:687401027353:s3-scan-object-complete-vault" -> null
      - content_based_deduplication              = false -> null
      - fifo_topic                               = false -> null
      - firehose_success_feedback_sample_rate    = 0 -> null
      - http_success_feedback_sample_rate        = 0 -> null
      - id                                       = "arn:aws:sns:ca-central-1:687401027353:s3-scan-object-complete-vault" -> null
      - kms_master_key_id                        = "aba11930-da25-4771-9149-fd1ad4dd3d63" -> null
      - lambda_success_feedback_sample_rate      = 0 -> null
      - name                                     = "s3-scan-object-complete-vault" -> null
      - owner                                    = "687401027353" -> null
      - policy                                   = jsonencode(
            {
              - Statement = [
                  - {
                      - Action    = [
                          - "sns:Subscribe",
                          - "sns:SetTopicAttributes",
                          - "sns:RemovePermission",
                          - "sns:Receive",
                          - "sns:Publish",
                          - "sns:ListSubscriptionsByTopic",
                          - "sns:GetTopicAttributes",
                          - "sns:DeleteTopic",
                          - "sns:AddPermission",
                        ]
                      - Effect    = "Allow"
                      - Principal = {
                          - AWS = "arn:aws:iam::687401027353:root"
                        }
                      - Resource  = "arn:aws:sns:ca-central-1:687401027353:s3-scan-object-complete-vault"
                      - Sid       = "AccountOwnerFullAdmin"
                    },
                  - {
                      - Action    = "sns:Publish"
                      - Effect    = "Allow"
                      - Principal = {
                          - AWS = "arn:aws:iam::687401027353:role/ScanFilesGetObjects"
                        }
                      - Resource  = "arn:aws:sns:ca-central-1:687401027353:s3-scan-object-complete-vault"
                      - Sid       = "AllowScanFilesPublish"
                    },
                ]
              - Version   = "2012-10-17"
            }
        ) -> null
      - sqs_success_feedback_sample_rate         = 0 -> null
      - tags                                     = {
          - "CostCentre" = "forms-platform-staging"
          - "Terraform"  = "true"
        } -> null
      - tags_all                                 = {
          - "CostCentre" = "forms-platform-staging"
          - "Terraform"  = "true"
        } -> null
    }

  # module.vault_scan_object.aws_sns_topic_policy.scan_complete will be destroyed
  - resource "aws_sns_topic_policy" "scan_complete" {
      - arn    = "arn:aws:sns:ca-central-1:687401027353:s3-scan-object-complete-vault" -> null
      - id     = "arn:aws:sns:ca-central-1:687401027353:s3-scan-object-complete-vault" -> null
      - owner  = "687401027353" -> null
      - policy = jsonencode(
            {
              - Statement = [
                  - {
                      - Action    = [
                          - "sns:Subscribe",
                          - "sns:SetTopicAttributes",
                          - "sns:RemovePermission",
                          - "sns:Receive",
                          - "sns:Publish",
                          - "sns:ListSubscriptionsByTopic",
                          - "sns:GetTopicAttributes",
                          - "sns:DeleteTopic",
                          - "sns:AddPermission",
                        ]
                      - Effect    = "Allow"
                      - Principal = {
                          - AWS = "arn:aws:iam::687401027353:root"
                        }
                      - Resource  = "arn:aws:sns:ca-central-1:687401027353:s3-scan-object-complete-vault"
                      - Sid       = "AccountOwnerFullAdmin"
                    },
                  - {
                      - Action    = "sns:Publish"
                      - Effect    = "Allow"
                      - Principal = {
                          - AWS = "arn:aws:iam::687401027353:role/ScanFilesGetObjects"
                        }
                      - Resource  = "arn:aws:sns:ca-central-1:687401027353:s3-scan-object-complete-vault"
                      - Sid       = "AllowScanFilesPublish"
                    },
                ]
              - Version   = "2012-10-17"
            }
        ) -> null
    }

  # module.vault_scan_object.aws_sns_topic_subscription.scan_complete will be destroyed
  - resource "aws_sns_topic_subscription" "scan_complete" {
      - arn                             = "arn:aws:sns:ca-central-1:687401027353:s3-scan-object-complete-vault:9de650dd-dc68-48c9-9409-dcfea719d0a1" -> null
      - confirmation_timeout_in_minutes = 1 -> null
      - confirmation_was_authenticated  = true -> null
      - endpoint                        = "arn:aws:lambda:ca-central-1:687401027353:function:s3-scan-object-vault" -> null
      - endpoint_auto_confirms          = false -> null
      - id                              = "arn:aws:sns:ca-central-1:687401027353:s3-scan-object-complete-vault:9de650dd-dc68-48c9-9409-dcfea719d0a1" -> null
      - owner_id                        = "687401027353" -> null
      - pending_confirmation            = false -> null
      - protocol                        = "lambda" -> null
      - raw_message_delivery            = false -> null
      - topic_arn                       = "arn:aws:sns:ca-central-1:687401027353:s3-scan-object-complete-vault" -> null
    }

  # module.vault_scan_object.module.s3_scan_object.aws_cloudwatch_log_group.this will be destroyed
  - resource "aws_cloudwatch_log_group" "this" {
      - arn               = "arn:aws:logs:ca-central-1:687401027353:log-group:/aws/lambda/s3-scan-object-vault" -> null
      - id                = "/aws/lambda/s3-scan-object-vault" -> null
      - name              = "/aws/lambda/s3-scan-object-vault" -> null
      - retention_in_days = 14 -> null
      - tags              = {
          - "CostCentre" = "forms-platform-staging"
          - "Terraform"  = "true"
        } -> null
      - tags_all          = {
          - "CostCentre" = "forms-platform-staging"
          - "Terraform"  = "true"
        } -> null
    }

  # module.vault_scan_object.module.s3_scan_object.aws_iam_policy.non_vpc_policies[0] will be destroyed
  - resource "aws_iam_policy" "non_vpc_policies" {
      - arn       = "arn:aws:iam::687401027353:policy/s3-scan-object-vault_non_vpc" -> null
      - id        = "arn:aws:iam::687401027353:policy/s3-scan-object-vault_non_vpc" -> null
      - name      = "s3-scan-object-vault_non_vpc" -> null
      - path      = "/" -> null
      - policy    = jsonencode(
            {
              - Statement = [
                  - {
                      - Action   = [
                          - "logs:PutLogEvents",
                          - "logs:CreateLogStream",
                          - "logs:CreateLogGroup",
                        ]
                      - Effect   = "Allow"
                      - Resource = "*"
                      - Sid      = "CloudWatchAccess"
                    },
                  - {
                      - Action   = [
                          - "ecr:GetDownloadUrlForlayer",
                          - "ecr:BatchGetImage",
                        ]
                      - Effect   = "Allow"
                      - Resource = "arn:aws:ecr:ca-central-1:806545929748:scan-files/module/s3-scan-object"
                      - Sid      = "ECRImageAccess"
                    },
                ]
              - Version   = "2012-10-17"
            }
        ) -> null
      - policy_id = "ANPA2ADCLI4MRVKM5VSYR" -> null
      - tags      = {
          - "CostCentre" = "forms-platform-staging"
          - "Terraform"  = "true"
        } -> null
      - tags_all  = {
          - "CostCentre" = "forms-platform-staging"
          - "Terraform"  = "true"
        } -> null
    }

  # module.vault_scan_object.module.s3_scan_object.aws_iam_policy.policies[0] will be destroyed
  - resource "aws_iam_policy" "policies" {
      - arn       = "arn:aws:iam::687401027353:policy/s3-scan-object-vault-0" -> null
      - id        = "arn:aws:iam::687401027353:policy/s3-scan-object-vault-0" -> null
      - name      = "s3-scan-object-vault-0" -> null
      - path      = "/" -> null
      - policy    = jsonencode(
            {
              - Statement = [
                  - {
                      - Action   = "secretsmanager:GetSecretValue"
                      - Effect   = "Allow"
                      - Resource = "arn:aws:secretsmanager:ca-central-1:806545929748:secret:/scan-files/api_auth_token-1tLf9T"
                      - Sid      = ""
                    },
                  - {
                      - Action   = "kms:Decrypt"
                      - Effect   = "Allow"
                      - Resource = "arn:aws:kms:ca-central-1:806545929748:key/*"
                      - Sid      = ""
                    },
                  - {
                      - Action   = [
                          - "s3:PutObjectVersionTagging",
                          - "s3:PutObjectTagging",
                          - "s3:ListBucket",
                          - "s3:GetObjectVersionTagging",
                          - "s3:GetObjectVersion",
                          - "s3:GetObjectTagging",
                          - "s3:GetObject",
                        ]
                      - Effect   = "Allow"
                      - Resource = [
                          - "arn:aws:s3:::forms-staging-vault-file-storage/*",
                          - "arn:aws:s3:::forms-staging-vault-file-storage",
                        ]
                      - Sid      = ""
                    },
                ]
              - Version   = "2012-10-17"
            }
        ) -> null
      - policy_id = "ANPA2ADCLI4MREXRFCSAO" -> null
      - tags      = {
          - "CostCentre" = "forms-platform-staging"
          - "Terraform"  = "true"
        } -> null
      - tags_all  = {
          - "CostCentre" = "forms-platform-staging"
          - "Terraform"  = "true"
        } -> null
    }

  # module.vault_scan_object.module.s3_scan_object.aws_iam_role.this will be destroyed
  - resource "aws_iam_role" "this" {
      - arn                   = "arn:aws:iam::687401027353:role/s3-scan-object-vault" -> null
      - assume_role_policy    = jsonencode(
            {
              - Statement = [
                  - {
                      - Action    = "sts:AssumeRole"
                      - Effect    = "Allow"
                      - Principal = {
                          - Service = "lambda.amazonaws.com"
                        }
                      - Sid       = ""
                    },
                ]
              - Version   = "2012-10-17"
            }
        ) -> null
      - create_date           = "2022-07-05T13:04:44Z" -> null
      - force_detach_policies = false -> null
      - id                    = "s3-scan-object-vault" -> null
      - managed_policy_arns   = [
          - "arn:aws:iam::687401027353:policy/s3-scan-object-vault-0",
          - "arn:aws:iam::687401027353:policy/s3-scan-object-vault_non_vpc",
          - "arn:aws:iam::aws:policy/CloudWatchLambdaInsightsExecutionRolePolicy",
        ] -> null
      - max_session_duration  = 3600 -> null
      - name                  = "s3-scan-object-vault" -> null
      - path                  = "/" -> null
      - tags                  = {
          - "CostCentre" = "forms-platform-staging"
          - "Terraform"  = "true"
        } -> null
      - tags_all              = {
          - "CostCentre" = "forms-platform-staging"
          - "Terraform"  = "true"
        } -> null
      - unique_id             = "AROA2ADCLI4M2DDZVVEXK" -> null

      - inline_policy {}
    }

  # module.vault_scan_object.module.s3_scan_object.aws_iam_role_policy_attachment.attachments[0] will be destroyed
  - resource "aws_iam_role_policy_attachment" "attachments" {
      - id         = "s3-scan-object-vault-20220705130445321100000002" -> null
      - policy_arn = "arn:aws:iam::687401027353:policy/s3-scan-object-vault-0" -> null
      - role       = "s3-scan-object-vault" -> null
    }

  # module.vault_scan_object.module.s3_scan_object.aws_iam_role_policy_attachment.lambda_insights[0] will be destroyed
  - resource "aws_iam_role_policy_attachment" "lambda_insights" {
      - id         = "s3-scan-object-vault-20220705130445315200000001" -> null
      - policy_arn = "arn:aws:iam::aws:policy/CloudWatchLambdaInsightsExecutionRolePolicy" -> null
      - role       = "s3-scan-object-vault" -> null
    }

  # module.vault_scan_object.module.s3_scan_object.aws_iam_role_policy_attachment.non_vpc_policies[0] will be destroyed
  - resource "aws_iam_role_policy_attachment" "non_vpc_policies" {
      - id         = "s3-scan-object-vault-20220705130445333500000003" -> null
      - policy_arn = "arn:aws:iam::687401027353:policy/s3-scan-object-vault_non_vpc" -> null
      - role       = "s3-scan-object-vault" -> null
   ...
Show Conftest results
WARN - plan.json - main - Missing Common Tags: ["module.vault_scan_object.aws_iam_policy.s3_scan_object"]
WARN - plan.json - main - Missing Common Tags: ["module.vault_scan_object.aws_iam_role.s3_scan_object"]

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

@patheard patheard changed the title chore: s3 scan object module version bump feat: switch to central S3 scan object design Jul 8, 2022
@patheard patheard marked this pull request as ready for review July 8, 2022 01:36
Copy link
Contributor

@mohdnr mohdnr left a comment

Choose a reason for hiding this comment

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

LGTM 🚀 ✅

@patheard patheard merged commit 68425c7 into develop Jul 11, 2022
@patheard patheard deleted the chore/s3-scan-object-version-bump branch July 11, 2022 12:59
patheard added a commit that referenced this pull request Sep 21, 2022
Update the S3 scan object Terraform module to inlude the version
with the following fixes:
- Skip scans of new S3 folders
- Properly interpret SNS messages with a checksum of `None`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants