Skip to content

fix: configure self-hosted S3 CORS for presigned uploads (#3379) - #3811

Open
ansaftab-1 wants to merge 1 commit into
HeyPuter:mainfrom
ansaftab-1:fix/selfhosted-s3-cors
Open

ansaftab-1 wants to merge 1 commit into
HeyPuter:mainfrom
ansaftab-1:fix/selfhosted-s3-cors

Conversation

@ansaftab-1

Copy link
Copy Markdown

Problem

In self-hosted Puter deployments, browser file uploads fail with a CORS policy error when sending PUT requests to S3 presigned URLs on RustFS (s3.<domain>). The browser issues an HTTP OPTIONS preflight request prior to the upload, but because the bucket was created without a bucket-level CORS policy, RustFS does not return the required Access-Control-Allow-* headers.

Fixes #3379

Solution

  1. Automated Bucket CORS Policy (docker-compose.yml):

    • Updated the s3-init service to pass PUTER_DOMAIN and PUTER_PROTOCOL.
    • s3-init writes and applies a bucket-level CORS configuration allowing origins for ${PUTER_PROTOCOL}://${PUTER_DOMAIN} and its subdomains (api, app, site, dev, host).
    • Configured AllowedMethods: ["GET", "HEAD", "PUT", "POST", "DELETE"], AllowedHeaders: ["*"], ExposeHeaders: ["ETag", "x-amz-request-id"], and MaxAgeSeconds: 3600.
    • Applied via aws --endpoint-url "$endpoint" s3api put-bucket-cors.
  2. Idempotent Initialization:

    • If the bucket already exists (head-bucket succeeds), s3-init does not exit early; it proceeds to apply/update the CORS policy so existing installations receive the fix without data loss.
  3. Installer Support (install.sh & install.ps1):

    • Updated install.sh and install.ps1 to write PUTER_DOMAIN and PUTER_PROTOCOL to .env.
    • Updated install.ps1 to accept -PuterProtocol parameter and dynamically configure protocol and publicEndpoint in config.json.
  4. Documentation:

    • Documented PUTER_DOMAIN and PUTER_PROTOCOL in doc/self-hosting.md and .env.example, including HTTPS setup instructions.
  5. Testing:

    • Added automated test suite (tools/test-s3-cors.mjs) validating default HTTP domain origins, custom HTTPS domain origins, allowed methods/headers, absence of wildcard origins, simulated browser OPTIONS preflights, idempotency logic, and installer consistency.

Tests Run

  • node tools/test-s3-cors.mjs: 20/20 tests passed.
  • git diff --check: Passed with 0 whitespace errors.
  • sh -n install.sh: Passed with exit code 0.
  • PowerShell AST parser validation of install.ps1: Passed with 0 errors.
  • PyYAML validation of docker-compose.yml: Passed with exit code 0.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@Salazareo

Copy link
Copy Markdown
Member

hi @ansaftab-1 could you please sign CLA

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.

CORS policy: Response to preflight request doesn't pass access control check

3 participants