Commit 2bae541
authored
admin: S3 bucket write endpoints (P2 slice 2a) (#669)
P2 slice 2a of
[docs/design/2026_04_24_proposed_admin_dashboard.md](https://github.com/bootjp/elastickv/blob/main/docs/design/2026_04_24_proposed_admin_dashboard.md).
Ships the S3 admin write endpoints so the SPA's S3 modals stop receiving
405. Slice 2b will plumb AdminForward so a follower can hand these
writes off to the leader transparently.
## Summary
- **`*adapter.S3Server.AdminCreateBucket` / `AdminPutBucketAcl` /
`AdminDeleteBucket`** — SigV4-bypass write methods 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. `AdminCreateBucket` reuses the same atomic bucket-meta + ACL
+ generation-key txn the SigV4 path does — no new code path through the
storage layer. `AdminDeleteBucket` rejects non-empty buckets (the
dashboard cannot force recursive delete by design).
- **`internal/admin` write surface** — `BucketsSource` gains the three
write methods + `CreateBucketRequest` / `PutBucketACLRequest` types with
the documented JSON shapes. `S3Handler.serveCollection` +
`servePerBucket` route POST/PUT/DELETE through dedicated handlers with
`principalForWrite` re-validating the role on every request against the
live `MapRoleStore`.
- **Strict body decoder** — `decodeAdminS3JSONBody` is generic over the
request type, applies `DisallowUnknownFields`, rejects NUL bytes,
rejects trailing tokens, and caps at 64 KiB (matches design 4.4). Used
by both POST and PUT.
- **`writeBucketsError`** translates the source-side sentinels into the
design's HTTP statuses: 403 forbidden / 503 + Retry-After:1
leader_unavailable / 404 not_found / 409 already_exists / 409
bucket_not_empty / 400 invalid_request via `*ValidationError`.
- **Bridge** — `bucketsBridge` gains write methods running through
`translateAdminBucketsError`, mirroring `translateAdminTablesError` on
the Dynamo side. Leader-churn sentinels from the kv coordinator route to
`admin.ErrBucketsNotLeader` so the SPA's retry contract stays intact.
## What is NOT in this PR
- AdminForward integration for S3 admin writes — slice 2b.
- Rolling-upgrade compatibility flag (criterion 5) — still deferred
behind a cluster-version bump.
## Test plan
- [x] `go build ./...`
- [x] `go vet ./...`
- [x] `golangci-lint run` (admin + main + adapter packages: 0 issues)
- [x] `go test ./internal/admin/ -count=1 -race` — 19 new handler tests
pass
- [x] `go test . -count=1 -race` — main package passes
- [x] `go test -run "TestS3Server_Admin" ./adapter/ -count=1 -race` — 10
new adapter tests pass
- [ ] Full `go test ./adapter/` times out at 120s due to a pre-existing
flake (verified earlier on PRs #648 / #658 against `main` — unrelated to
this branch)
- [ ] End-to-end smoke against a 3-node cluster — slice 2b first, then a
manual exercise
## Acceptance criteria coverage (Section 4.1)
| Endpoint | This PR |
|---|---|
| `GET /admin/api/v1/s3/buckets` | ✓ (#658) |
| `GET /admin/api/v1/s3/buckets/{name}` | ✓ (#658) |
| `POST /admin/api/v1/s3/buckets` | ✅ |
| `PUT /admin/api/v1/s3/buckets/{name}/acl` | ✅ |
| `DELETE /admin/api/v1/s3/buckets/{name}` | ✅ |
## Self-review (5 lenses)
1. **Data loss**: `AdminCreateBucket` reuses `s.coordinator.Dispatch`
with the same `OperationGroup` shape as the SigV4 path — bucket meta +
generation key in one txn. No new FSM / Pebble / Raft path.
`AdminDeleteBucket`'s "must be empty" guard is a SnapshotAt scan + size
check identical to the SigV4 path.
2. **Concurrency**: Writes go through `retryS3Mutation` which already
handles transient mid-dispatch leader churn. The leader check is
`isVerifiedS3Leader` — same primitive the SigV4 path uses. Role gate is
re-evaluated against the live `MapRoleStore` on every request, so a key
downgrade picked up between login and write is enforced immediately.
3. **Performance**: One additional load-bucket-meta read on PutACL /
Delete. No hot-path changes; admin writes are operator-rate, not
data-plane-rate.
4. **Data consistency**: `AdminCreateBucket` writes (BucketMetaKey,
BucketGenerationKey) atomically. `AdminPutBucketAcl` mutates only
`meta.Acl` and re-encodes the entire BucketMeta — generation is
preserved so existing object references stay valid. `AdminDeleteBucket`
removes only BucketMetaKey (BucketGenerationKey is left behind, matching
the SigV4 path's behaviour — a future re-create gets a fresh
generation).
5. **Test coverage**: 29 new tests (19 admin-package + 10 adapter-level)
covering happy paths, role gates, leader checks, validation rejections,
all four sentinel error mappings, and the cross-method missing-principal
401. The existing `TestS3Handler_DescribeBucket_SubpathReturns404` was
superseded by two more precise tests now that `/acl` is a real
sub-resource.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **New Features**
* S3 bucket admin endpoints: create, update ACL, and delete with
enforced write authorization, input validation, leader-forwarding, and
clear HTTP error mappings.
* **Documentation**
* New admin docs covering dashboard config, TLS/role semantics, audit
logging, and troubleshooting for admin operations.
* **Tests**
* Extensive end-to-end and unit tests for bucket lifecycle, forwarding,
auth/validation, and error scenarios.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->22 files changed
Lines changed: 3477 additions & 140 deletions
File tree
- adapter
- docs
- internal/admin
- proto
- scripts
| 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 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
0 commit comments