boltops-tools / terraspace

Terraspace: The Terraform Framework
https://terraspace.cloud
Apache License 2.0
678 stars 46 forks source link

The Bucket Policy ForceSSLOnlyAccess is added in a wrong way and Security Hub still mention it as unsecure #281

Open argo1984 opened 1 year ago

argo1984 commented 1 year ago

Checklist

My Environment

Software Version
Operating System Podman Image bookworm/sid
Terraform v1.3.0
Terraspace 2.2.2
Ruby ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x86_64-linux ]

Expected Behaviour

I added the parameter "config.s3.enforce_ssl = true" in the aws.rb and terraspace should create the following bucket policy:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "ForceSSLOnlyAccess",
            "Effect": "Deny",
            "Principal": "*",
            "Action": "s3:*",
            "Resource": [
                "arn:aws:s3:::BUCKET_ID/*",
                "arn:aws:s3:::BUCKET_ID"
            ],
            "Condition": {
                "Bool": {
                    "aws:SecureTransport": "false"
                }
            }
        }
    ]
}

Current Behavior

The following Bucket Policy is being created and Security Hub still have the following finding: S3.5 S3 buckets should require requests to use Secure Socket Layer

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "ForceSSLOnlyAccess",
            "Effect": "Deny",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::BUCKET_ID/*",
            "Condition": {
                "Bool": {
                    "aws:SecureTransport": "false"
                }
            }
        }
    ]
}

Step-by-step reproduction instructions

Activate config.s3.enforce_ssl = true in aws.rb

Code Sample

TerraspacePluginAws.configure do |config|
  config.auto_create = true # set to false to completely disable auto creation
  config.tag_existing = true # if bucket or dynamodb already exists will tag them. Tags are appended.

  config.s3.access_logging = true # false is the default setting
  config.s3.block_public_access = true
  config.s3.encryption = true
  config.s3.enforce_ssl = true
  config.s3.lifecycle = true
  config.s3.versioning = true
  config.s3.secure_existing = true # run the security controls on existing buckets. by default, only run on newly created bucket the first time
  # config.s3.tags = {} # override config.tags setting

  config.dynamodb.encryption = true
  config.dynamodb.kms_master_key_id = "alias/aws/dynamodb"
  config.dynamodb.sse_type = "KMS"
  # config.dynamodb.tags = {} # override config.tags setting
end

Solution Suggestion

Add the policy which is suggested by AWS: https://docs.aws.amazon.com/securityhub/latest/userguide/securityhub-standards-fsbp-controls.html#s3-5-remediation