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

Access log bucket name truncation inconsistency #185

Open
correnarsprowls opened this issue Oct 4, 2024 · 0 comments
Open

Access log bucket name truncation inconsistency #185

correnarsprowls opened this issue Oct 4, 2024 · 0 comments
Labels
bug 🐛 An issue with the system

Comments

@correnarsprowls
Copy link

Describe the Bug

When using this module and having it create a access log bucket, if you use a module.app_label.id that is too long (in this case it was 48 characters) then it will truncate the access log bucket name. But the usage of this truncated name is inconstant. The issue that we have run into is with the bucket policy. In the ForceSSLOnlyAccess statement it is using the truncated/correct bucket name. In the other three statements it is using a non-truncated version of the bucket name that doesn't exist.

Expected Behavior

The correct bucket name gets used everywhere

Steps to Reproduce

Use this module with app label ID with a length of 48 characters or above an let it create an access log bucket for you.

Screenshots

resource "aws_s3_bucket_policy" "default" {
  + bucket = "root-us-east-2-production-app111-rails-project-4-alb-acce-b3c98"
  + id     = (known after apply)
  + policy = jsonencode(
        {
          + Statement = [
              + {
                  + Action    = "s3:*"
                  + Condition = {
                      + Bool = {
                          + "aws:SecureTransport" = "false"
                        }
                    }
                  + Effect    = "Deny"
                  + Principal = "*"
                  + Resource  = [
                      + "arn:aws:s3:::root-us-east-2-production-app111-rails-project-4-alb-acce-b3c98/*",
                      + "arn:aws:s3:::root-us-east-2-production-app111-rails-project-4-alb-acce-b3c98",
                    ]
                  + Sid       = "ForceSSLOnlyAccess"
                },
              + {
                  + Action    = "s3:PutObject"
                  + Effect    = "Allow"
                  + Principal = {
                      + AWS = "arn:aws:iam::XXXXXXXXXXXX:root"
                    }
                  + Resource  = "arn:aws:s3:::root-us-east-2-production-app111-rails-project-4-alb-access-logs/*"
                },
              + {
                  + Action    = "s3:PutObject"
                  + Condition = {
                      + StringEquals = {
                          + "s3:x-amz-acl" = "bucket-owner-full-control"
                        }
                    }
                  + Effect    = "Allow"
                  + Principal = {
                      + Service = "delivery.logs.amazonaws.com"
                    }
                  + Resource  = "arn:aws:s3:::root-us-east-2-production-app111-rails-project-4-alb-access-logs/*"
                },
              + {
                  + Action    = "s3:GetBucketAcl"
                  + Effect    = "Allow"
                  + Principal = {
                      + Service = "delivery.logs.amazonaws.com"
                    }
                  + Resource  = "arn:aws:s3:::root-us-east-2-production-app111-rails-project-4-alb-access-logs"
                },
            ]
          + Version   = "2012-10-17"
        }
    )
}

Trying to add the above policy results in the following error

│ Error: putting S3 Bucket (root-us-east-2-production-app111-rails-project-4-alb-acce-b3c98) Policy: operation error S3: PutBucketPolicy, https response error StatusCode: 400, RequestID: x, HostID: x, api error MalformedPolicy: Policy has invalid resource

Environment

module version: 1.11.1

Additional Context

No response

@correnarsprowls correnarsprowls added the bug 🐛 An issue with the system label Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An issue with the system
Projects
None yet
Development

No branches or pull requests

1 participant