Access Control
Identities, actions, bucket scopes, presigned URLs, and TLS
Every S3 request is signed with an access key and its secret key (AWS Signature Version 4). The server recomputes the signature, finds the identity the key belongs to, and checks whether that identity may perform the action on that bucket.
Identities as code
config/s3.json is mounted into the filer and passed with -s3.config:
| Action | Allows |
|---|---|
Read | GET and HEAD objects |
Write | PUT, DELETE, multipart uploads |
List | List objects (and buckets) |
Tagging | Object tags |
Admin | Create and delete buckets, bucket settings, everything else |
An action without a bucket applies to all buckets; Write:app-data
applies to one. An identity can have several credential pairs, which is
how you rotate keys: add the new pair, deploy clients with it, remove the
old one.
Tested
docker compose -f compose_prod.yaml run --rm labs python access_control.py
app PUT app-data/report.txt allowed
app GET app-data/report.txt allowed
app PUT backups/db.bak allowed
app GET finance/salaries.csv AccessDenied
app CREATE bucket app-new AccessDenied
readonly GET finance/salaries.csv allowed
readonly PUT app-data/x AccessDenied
admin DELETE finance/salaries.csv allowedNote the second-to-last column: readonly can read finance. "Read
everything" really means everything, including buckets created later. Scope
read access to buckets too, unless it's genuinely meant to be global.
Least privilege in practice
- One identity per application or job, never a shared admin key. When a key leaks you revoke one service's access, and logs say who did what.
- Applications never get
Admin. Buckets are created by whoever manages infrastructure (a script, Terraform), not by app code at startup. - Backup writers shouldn't be able to delete. A ransomware attack or a
buggy script with the backup job's key shouldn't be able to erase the
backups. In SeaweedFS
Writeincludes delete, so protect backups with versioning and a copy in a second place. - Browsers get presigned URLs, never keys.
Managing identities at runtime
Instead of a file, identities can live in the filer, managed from
weed shell:
> s3.configure -user=reports -access_key=reports -secret_key=... \
-actions=Read,List -buckets=app-data -apply
> s3.configure # print the current configurationThe file approach keeps access reviewable in git; the shell approach needs no restart. Pick one per cluster so there's a single source of truth.
The keys in this module are committed to the repository on purpose, as in
every other module, because it's a lab. In production, secrets come from
a secret manager or are injected at deploy time, and s3.json is
rendered from them, never committed.
TLS
S3 signatures protect requests from being altered, not from being
read. Without TLS, object contents and presigned URLs travel in clear
text. The S3 gateway takes -s3.cert.file and -s3.key.file; more often
a reverse proxy (the Nginx module) terminates TLS in front of several
gateways. Inside the cluster, SeaweedFS's gRPC traffic between masters,
volume servers and filers can use mutual TLS, configured in
security.toml (weed scaffold -config=security).
Lab
- Add an identity
reportsthat can only readapp-dataand test it. - Give
appa second credential pair, switch the lab to it, and remove the first. Did anything else need to change? - With the
readonlykey, try to create a presigned PUT URL and use it. Who is the request checked against?