Putting S3 behind a CDN breaks signatures
Moving to SeaweedFS, putting the S3 API behind the Cloudflare proxy caused random SignatureDoesNotMatch errors. The two-hostname fix and other traps.
The MinIO community edition was archived. No more security updates were coming. So a new S3-compatible store had to be chosen. The choice was easy; the real lessons came after the setup.
Why SeaweedFS?
- Ceph is powerful but too heavy at small scale. Keeping it running is a job of its own.
- Garage is light, but it has some gaps in S3 compatibility.
- SeaweedFS is Apache 2.0 licensed, actively developed and runs as a single binary. Cross-site sync (
filer.sync) is built in.
Design
- Apps upload the file and store only the object's path in their database.
- Customers download files through short-lived presigned URLs.
- A second site gets a near-real-time copy. On top of that, a nightly copy goes to a separate store.
Pitfall 1: the CDN proxy breaks the signature
Once the S3 API was put behind the Cloudflare proxy, random 403 SignatureDoesNotMatch errors started. The same request would pass once and fail the next time.
Why does it happen?
- For extensions that look cacheable, the proxy can forward a
HEADrequest to origin as aGET. The S3 signature covers the HTTP method too. When the method changes, the signature no longer matches. - On standard plans, the proxy caps the request body at 100 MB. Large uploads can't go through that path anyway.
The fix is two separate hostnames:
| Host | Cloudflare | Purpose |
|---|---|---|
s3.example.com |
DNS only | API, writes |
cdn.example.com |
Proxied | Presigned downloads, GET/HEAD/OPTIONS only |
The load balancer rejects write methods on the cdn host. An example with Caddy:
cdn.example.com {
@write not method GET HEAD OPTIONS
respond @write 405
reverse_proxy 10.0.0.10:8333 10.0.0.11:8333
}
The app that generates presigned URLs must also sign them with the cdn hostname. The Host header is part of the signature.
Pitfall 2: Write permission was not enough for PutObject
In the SeaweedFS version used, a bucket-scoped Write permission was not enough for PutObject; it returned AccessDenied. A bucket-scoped Admin permission was needed. That permission still stays limited to that bucket only.
{
"identities": [
{
"name": "app-ornek",
"credentials": [{ "accessKey": "<erisim-anahtari>", "secretKey": "<gizli-anahtar>" }],
"actions": ["Read:ornek-bucket", "List:ornek-bucket", "Admin:ornek-bucket"]
}
]
}
Write this behavior down. Otherwise the next person will ask "why does this have Admin?" and take it away.
Pitfall 3: rclone tries to check the bucket
Tools like rclone try to create the bucket, or check that it exists, before writing. If the app key has no permission for that, you get a 403. The fix:
[seaweed]
type = s3
provider = Other
endpoint = https://s3.example.com
access_key_id = <erisim-anahtari>
secret_access_key = <gizli-anahtar>
no_check_bucket = true
Pitfall 4: s3.json must be the same on both sites
Identities are defined in the s3.json file. If the file is not identical on both sites, newly added keys stop working after a failover. Deploy the file from a single source and compare both sides regularly:
sha256sum s3.json # expect the same output on both sites
Lesson
Before putting an endpoint behind a CDN, ask: is this a signature-verifying API, or an edge for presigned downloads? The two should not share a hostname.
Checklist
- [ ] Does the S3 API host bypass the CDN proxy?
- [ ] Does the download host accept only GET/HEAD/OPTIONS?
- [ ] Are presigned URLs signed with the right hostname?
- [ ] Is the bucket-scoped permission requirement documented?
- [ ] Does the rclone config have
no_check_bucket = true? - [ ] Is
s3.jsonthe same on both sites?