lab7: безопасность, mTLS, OpenBao и PKI lifecycle

This commit is contained in:
Vladislav Kunetskiy
2026-11-10 10:58:07 +03:00
parent 3d216fbd50
commit 3441f2269a
183 changed files with 216667 additions and 3165 deletions
+70 -21
View File
@@ -1,27 +1,76 @@
# SeaweedFS identities
# SeaweedFS identities and recovery
`infra/s3/s3.json` is mounted read-only into the `seaweedfs` container and is
the single source of truth for S3 credentials and permissions.
The pinned SeaweedFS 4.51 image runs as one logical `s3` role: the
`seaweedfs` container owns the network namespace and persistent volume;
the `s3` container shares that namespace and serves native HTTPS.
Do not downgrade to 3.80: its COPY authorization allowed foreign-source reads.
Owned COPY plus forbidden foreign-source/destination COPY checks remain required.
- `admin` is used only by the one-shot `s3-init` service (bucket creation and
probing). It is never given to the API and must not be placed in `.env`:
the API service loads `.env` as an environment file. Compose supplies the
synthetic admin values to `s3-init` directly.
- `app` is used by the API and by presigned uploads. It can read/write only
`messenger-attachments/attachments/*` and `messenger-attachments/staging/*`,
and list the bucket for the orphan sweeper.
`infra/s3/s3.json` declares permissions, not credentials. `securityctl.py`
renders operator-local credentials into the read-only `/run/backend/s3.json`
mount of `s3`. Only `s3-init` and the host operator use the operator identity
as clients; application processes receive only their own credentials.
The credentials are synthetic values for the local stand. `.env.example`
carries the same values for the API and `scripts/check_s3_creds.py` fails the
offline check if they drift. Replace them in `.env` for any non-local run.
- `operator` creates the application bucket and maintains the recovery sentinel.
- `api` reads attachment/staging objects and writes staging objects only.
- `worker` reads/writes attachment/staging objects and lists the application
bucket. Bucket-level LIST can disclose foreign-prefix metadata; Write also
permits DELETE within the allowed prefixes.
Verify manually:
## Listener isolation
```sh
# anonymous requests are denied
docker compose exec -T seaweedfs \
wget -qO- http://127.0.0.1:8333/messenger-attachments/attachments/missing
| Listener | Binding and policy |
| --- | --- |
| S3 HTTPS 8333 | Native TLS; SigV4 credentials and prefix ACLs. Host publication is loopback-only. |
| S3 auxiliary gRPC 18333 | Shared namespace; mTLS trusts the role CA and permits only CN `s3`. |
| Master HTTP 9333, filer HTTP 8888, volume HTTP 8080 | Namespace loopback only; not published. |
| Master gRPC 19333, filer gRPC 18888, volume gRPC 18080 | Namespace loopback only, with the same CN `s3` mTLS restriction. |
| Iceberg HTTP 8181, Lance HTTP 9101 | Disabled by `-port.iceberg=0` and `-port.lance=0`; absence must be probed, not excluded from isolation checks. |
# the app identity cannot write outside its prefixes
docker compose run --rm s3-init # probes this and exits non-zero on violation
```
The three internal gRPC Unix sockets stay in the owner's private `/tmp`.
The S3 HTTP Unix socket stays in the S3 container's private `/tmp`.
No additional PKI role, client allowance, or certificate SAN is needed.
Auxiliary 18333 is not an HTTP readiness port: test TLS rejection for
`api`, `worker`, and `operator`, and successful mTLS only for `s3`.
Flags were obtained from the pinned binary with `weed s3 -help` and
`weed server -help`. The configured filer address uses SeaweedFS's explicit
HTTP/gRPC form, `127.0.0.1:8888.18888`, matching the master discovery registry.
The shipped [address parser](https://github.com/seaweedfs/seaweedfs/blob/ffa87c25f/weed/pb/server_address.go)
supports this form. The
[discovery implementation](https://github.com/seaweedfs/seaweedfs/blob/ffa87c25f/weed/wdclient/filer_client.go)
compares raw address spellings and refreshes every five minutes; removing
`127.0.0.1:8888` when discovering its explicit-gRPC equivalent does not mean
that no filer remains.
## Persistent body readiness
The filer's `/healthz` and the public API's DB/OpenBao health cannot prove that
previously stored volume bytes are readable. In the observed restart, S3
started before master leadership and volume topology had recovered.
`Controller.wait_s3()` uses the operator CA, verifies `localhost`, presents
the operator leaf, and signs requests for the published HTTPS S3 endpoint.
It creates exactly one random `operator-readiness/<key>` object in the
configured application bucket on first initialization. Its 64 KiB body forces
volume-backed storage rather than a metadata-only/HEAD probe. Expected bytes
and establishment state live in private `LAB7_OPERATOR_STATE/s3-readiness.json`.
The application identities cannot read, overwrite, or delete this prefix.
After establishment, readiness performs GET and full byte comparison only:
it never rewrites a missing object or reseeds a volume. Missing/unavailable
storage is retried within the readiness deadline; changed bytes or permanent
authorization errors fail the operation. Network operations use five-second
timeouts and body reads are size-capped and deadline-checked.
`wait_ready()` requires this body check before public HTTPS health succeeds.
Store restart first checks the old sentinel, restarts owners, recreates
shared-namespace consumers, checks old bytes again, then restarts applications.
This preserves the existing volumes and does not retry or alter public tests.
Required targeted verification after applying configuration: retain an uploaded
attachment, perform the operator restart hook, read its complete body once,
then compare it byte-for-byte. Also exercise a new staging upload/async COPY,
the existing COPY ACL matrix, auxiliary listener isolation, and the failure
case where an established readiness object is unavailable. Do not remove the
private readiness state to make a persistence check pass.
+10 -8
View File
@@ -1,17 +1,19 @@
{
"identities": [
{
"name": "admin",
"credentials": [
{"accessKey": "lab4admin", "secretKey": "lab4admin-secret"}
],
"name": "operator",
"actions": ["Admin", "Read", "Write", "List", "Tagging"]
},
{
"name": "app",
"credentials": [
{"accessKey": "lab4app", "secretKey": "lab4app-secret"}
],
"name": "api",
"actions": [
"Read:messenger-attachments/attachments/*",
"Read:messenger-attachments/staging/*",
"Write:messenger-attachments/staging/*"
]
},
{
"name": "worker",
"actions": [
"Read:messenger-attachments/attachments/*",
"Write:messenger-attachments/attachments/*",
+35
View File
@@ -0,0 +1,35 @@
# One logical s3 role: HTTP 9333/8888/8080 and gRPC 19333/18888/18080
# stay on namespace loopback. S3 HTTPS 8333 is published only on host loopback.
# Auxiliary gRPC 18333 requires mTLS CN s3; Iceberg 8181 and Lance 9101
# are disabled by the standalone S3 command, not hidden by test exclusions.
[grpc]
ca = "/run/identity/current/ca.crt"
[grpc.master]
cert = "/run/identity/current/tls.crt"
key = "/run/identity/current/tls.key"
allowed_commonNames = "s3"
[grpc.volume]
cert = "/run/identity/current/tls.crt"
key = "/run/identity/current/tls.key"
allowed_commonNames = "s3"
[grpc.filer]
cert = "/run/identity/current/tls.crt"
key = "/run/identity/current/tls.key"
allowed_commonNames = "s3"
[grpc.s3]
cert = "/run/identity/current/tls.crt"
key = "/run/identity/current/tls.key"
allowed_commonNames = "s3"
[grpc.client]
cert = "/run/identity/current/tls.crt"
key = "/run/identity/current/tls.key"
[access]
ui = false
[filer.expose_directory_metadata]
enabled = false