Commit 56a547c
committed
admin: ship S3 bucket write endpoints (P2 slice 2a)
Slice 2a of P2 (docs/design/2026_04_24_proposed_admin_dashboard.md
Section 4.1): POST /admin/api/v1/s3/buckets, PUT
/admin/api/v1/s3/buckets/{name}/acl, and DELETE
/admin/api/v1/s3/buckets/{name} become reachable so the SPA's S3
write modals stop receiving 405. Slice 2b will plumb AdminForward
so a follower can hand these writes off to the leader transparently.
Adapter (`adapter/s3_admin.go`):
- `AdminCreateBucket` performs the same atomic bucket-meta + ACL +
generation-key txn the SigV4 createBucket path does, with three
in-method guards: principal must be AdminRoleFull, the local node
must be the verified S3 leader, and bucket-name + ACL must pass
the existing validators. The owner field is now populated with the
caller's access key so the audit-log breadcrumb survives storage.
- `AdminPutBucketAcl` mutates only `meta.Acl` in place, preserving
generation so existing object references remain valid.
- `AdminDeleteBucket` rejects non-empty buckets with
`ErrAdminBucketNotEmpty` (mirrors the SigV4 path's
`BucketNotEmpty`); the dashboard cannot force a recursive delete
by design.
- New sentinels: `ErrAdminBucketAlreadyExists`,
`ErrAdminBucketNotFound`, `ErrAdminBucketNotEmpty`,
`ErrAdminInvalidBucketName`, `ErrAdminInvalidACL`. Reuses the
shared `ErrAdminForbidden` and `ErrAdminNotLeader` from the
Dynamo side.
Admin package:
- `BucketsSource` interface gains `AdminCreateBucket` /
`AdminPutBucketAcl` / `AdminDeleteBucket`. New types
`CreateBucketRequest` and `PutBucketACLRequest` carry the
documented JSON shapes.
- New sentinels `ErrBucketsNotEmpty`, `ErrBucketsAlreadyExists`
(the former is new for slice 2a; the latter was reserved earlier
and is now wired).
- `S3Handler` now routes POST/PUT/DELETE through dedicated
per-method handlers with `principalForWrite` re-validating the
role on every request against the live `MapRoleStore`. The route
switch was refactored into `serveCollection` + `servePerBucket`
to keep the cyclomatic budget under control as the surface grew.
- `handleCreate` / `handlePutACL` / `handleDelete` log a structured
`admin_audit` line on success matching the Dynamo handler's shape.
- `decodeAdminS3JSONBody` is the strict shared decoder
(`DisallowUnknownFields`, NUL-byte rejection, trailing-token
rejection, 64 KiB cap) used by both POST and PUT.
- `writeBucketsError` translates the source-side sentinels into
the design's HTTP statuses (403 / 503+Retry-After:1 / 404 / 409 /
400 invalid_request via `*ValidationError`).
Bridge (`main_admin.go`):
- `bucketsBridge` gains write methods that call the adapter's
`Admin*` methods and run their errors through
`translateAdminBucketsError` — the same pattern as
`translateAdminTablesError`, with the leader-churn fallback
routing kv-internal sentinels to `admin.ErrBucketsNotLeader` so
the SPA's retry contract stays intact.
Tests:
- 19 admin-package tests covering: create happy path / read-only
rejected / 409 already-exists / 503 not-leader / 400 invalid JSON
shapes (5 sub-cases) / NUL-byte / 413 oversize / put_acl happy +
read-only + missing field + 404 + non-PUT method-not-allowed /
delete happy + read-only + 409 not-empty + 404 + 503 not-leader /
cross-method missing-principal 401.
- 10 adapter-level tests against the in-memory MVCC store covering
the same surfaces from the storage side: happy path round-trips
through describe, ACL default to private, role / leader / ACL /
bucket-name validation rejections, AlreadyExists / NotFound /
NotEmpty paths.
- Existing `TestS3Handler_DescribeBucket_SubpathReturns404` was
superseded by two more precise tests:
`TestS3Handler_PerBucket_UnknownSubpathReturns404` (any non-/acl
sub-path 404s) and `TestS3Handler_PerBucket_AclSubpathRejectsGet`
(the now-valid /acl path returns 405 on GET).1 parent ee521be commit 56a547c
7 files changed
Lines changed: 1286 additions & 63 deletions
File tree
- adapter
- internal/admin
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| |||
175 | 177 | | |
176 | 178 | | |
177 | 179 | | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
0 commit comments