carlos / platform Public

deployment-buckets: db-reads/ expires (J4, T17); the approval plan for applying it (plan 2, Task 13)

Prepared only: nothing is applied until Paul approves the note's scope.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 425a168e6abc002dd0074bf7ba0c05b59b8f376d parent 276d9e0
3 files changed, +162 −1
  • docs/superpowers/notes/db-reads-lifecycle-approval.md +79 −0
  • infra/modules/deployment-buckets/main.tf +39 −1
  • infra/modules/deployment-buckets/tests/db_reads.tftest.hcl +44 −0
diff --git a/docs/superpowers/notes/db-reads-lifecycle-approval.md b/docs/superpowers/notes/db-reads-lifecycle-approval.md
new file mode 100644
index 000000000..e22865e6f
--- /dev/null
+++ b/docs/superpowers/notes/db-reads-lifecycle-approval.md
@@ -0,0 +1,79 @@
+# Approval plan: the db-reads/ lifecycle rule on the deployment buckets
+
+Status: PREPARED, not applied. AGENTS.md's production rule applies: nothing
+here is applied until Paul approves this scope.
+
+## What and why
+
+Two lifecycle rules on each deployment bucket, both filtered to the prefix
+`db-reads/` (db region forward spec §5.7, §11.1, J4):
+
+- `db-reads-expire`: current versions expire 1 day after creation;
+ noncurrent versions expire 1 day after they become noncurrent; incomplete
+ multipart uploads are aborted after 1 day.
+- `db-reads-delete-markers`: expired object delete markers are removed.
+
+The forwarded read protocol writes create-only objects under `db-reads/`
+and deletes nothing. These rules are its only deletion. They must be in
+place on a deployment's bucket before any console there sets
+`CARLOS_DB_FORWARD=1`; without them `db-reads/` objects are never removed.
+
+The module change is in `infra/modules/deployment-buckets/main.tf`, inside
+the existing `aws_s3_bucket_lifecycle_configuration.deployment`, beside the
+`geoip-noncurrent` rule, which is unchanged. The module test
+`tests/db_reads.tftest.hcl` (T17) pins both rules and the GeoIP rule.
+
+## Scope
+
+| | Dev | Flagship |
+|---|---|---|
+| Account and region | the dev account (profile `kass`), eu-west-1 | the flagship account (profile `keymail`), eu-west-1 |
+| Bucket | `carlos-dev-640012953448` | `carlos-flagship-271376211898` |
+| Root | `platform-infrastructure` (tracks `main`) | `carlosframework/carloku-infrastructure` (modules at a release tag) |
+| Resource | `aws_s3_bucket_lifecycle_configuration.deployment` inside the `deployment-buckets` module | the same |
+| Change | two rules added; the `control/geoip/` rule unchanged | the same |
+
+No IAM change, no new permission, no traffic change. Nothing outside
+`db-reads/` is affected: the filter is the prefix, and no other key in the
+bucket starts with it. A bucket's lifecycle configuration is replaced whole
+by the apply, which is why the plan must show the GeoIP rule still there.
+
+## Cost
+
+Lifecycle expiration is free. Storage of `db-reads/` objects is at most a
+few days of forwarded reads (a query's ciphertext is at most 64 MiB).
+
+## Steps
+
+Dev first (Paul's roll order), then the flagship:
+
+1. Dev: in `platform-infrastructure`, `tofu init -upgrade`, then
+ `tofu plan -target=<the deployment-buckets module address>` (find it
+ with `grep -n 'deployment-buckets' *.tf`). The plan must show only the
+ lifecycle configuration changing in place, with the two rules added and
+ `geoip-noncurrent` kept. Apply with the same `-target` after approval.
+2. Flagship: cut the platform release that carries this module change,
+ push its tag to the GitHub mirror (`git push
+ https://github.com/carlosframework/platform.git refs/tags/vX.Y.Z`), bump
+ every `?ref=` in `carloku-infrastructure`, `tofu init -upgrade`, then the
+ same targeted plan. Apply with the same `-target` after approval. A
+ whole-root apply is not allowed (user_data drift restarts every box).
+
+## Verification
+
+`aws s3api get-bucket-lifecycle-configuration --bucket <deployment bucket>
+--profile <the deployment's profile>` lists `geoip-noncurrent`,
+`db-reads-expire` and `db-reads-delete-markers`, the last two filtered to
+`db-reads/`.
+
+## Rollback
+
+Remove the two rules and apply the same targeted change. Until a rule is
+back, `db-reads/` objects are not removed, so turn forwarding off
+(`CARLOS_DB_FORWARD` unset on the console) first.
+
+## Duration
+
+Permanent while forwarding is in use. Plan 5 (spec §14) moves this traffic
+to a bucket per region, which carries its own copy of these rules; these
+then stay for any object written before the move.
diff --git a/infra/modules/deployment-buckets/main.tf b/infra/modules/deployment-buckets/main.tf
index 9eb12cc50..91dd68c26 100644
--- a/infra/modules/deployment-buckets/main.tf
+++ b/infra/modules/deployment-buckets/main.tf
@@ -28,7 +28,9 @@ resource "aws_s3_bucket_versioning" "deployment" {
# GeoIP databases (platform geoip spec 2026-10-06 §15 step 0, D1): a deleted
# or superseded blob under control/geoip/ must not live on as a noncurrent
# version, because MaxMind's GeoLite EULA requires destroying superseded
-# editions. Scoped to that prefix only; nothing else in this bucket expires.
+# editions. Forwarded db reads (db region forward spec §5.7, J4): every
+# object under db-reads/ expires. Each rule is scoped to its own prefix;
+# nothing else in this bucket expires.
resource "aws_s3_bucket_lifecycle_configuration" "deployment" {
bucket = aws_s3_bucket.deployment.id
@@ -46,6 +48,42 @@ resource "aws_s3_bucket_lifecycle_configuration" "deployment" {
}
}
+ # Forwarded db reads (db region forward spec §5.7, J4): every object under
+ # db-reads/ (requests, queue entries, picked markers, sealed chunks,
+ # results, cancels) expires a day after it is written, each noncurrent
+ # version a day after it becomes noncurrent, and expired delete markers
+ # go. The protocol deletes nothing, so these rules are its only deletion;
+ # a read's ciphertext lives until they act, typically two to four days.
+ rule {
+ id = "db-reads-expire"
+ status = "Enabled"
+ filter {
+ prefix = "db-reads/"
+ }
+ expiration {
+ days = 1
+ }
+ noncurrent_version_expiration {
+ noncurrent_days = 1
+ }
+ abort_incomplete_multipart_upload {
+ days_after_initiation = 1
+ }
+ }
+
+ # S3 refuses an expired-object-delete-marker expiration beside days in one
+ # rule, so the markers have a rule of their own.
+ rule {
+ id = "db-reads-delete-markers"
+ status = "Enabled"
+ filter {
+ prefix = "db-reads/"
+ }
+ expiration {
+ expired_object_delete_marker = true
+ }
+ }
+
depends_on = [aws_s3_bucket_versioning.deployment]
}
diff --git a/infra/modules/deployment-buckets/tests/db_reads.tftest.hcl b/infra/modules/deployment-buckets/tests/db_reads.tftest.hcl
new file mode 100644
index 000000000..627e20acb
--- /dev/null
+++ b/infra/modules/deployment-buckets/tests/db_reads.tftest.hcl
@@ -0,0 +1,44 @@
+# db region forward spec T17 (J4): the deployment bucket expires everything
+# under db-reads/: current versions a day after they are written,
+# noncurrent versions a day after they become noncurrent, and expired
+# delete markers. It is the forwarded read protocol's only deletion.
+
+mock_provider "aws" {}
+
+variables {
+ deployment_bucket_name = "dep"
+ data_bucket_name = "data"
+}
+
+run "db_reads_expire_with_their_versions_and_markers" {
+ command = plan
+
+ assert {
+ condition = length([
+ for r in aws_s3_bucket_lifecycle_configuration.deployment.rule : r
+ if r.id == "db-reads-expire" && r.status == "Enabled" &&
+ one(r.filter).prefix == "db-reads/" &&
+ one(r.expiration).days == 1 &&
+ one(r.noncurrent_version_expiration).noncurrent_days == 1
+ ]) == 1
+ error_message = "db-reads/ must expire current versions after 1 day and noncurrent versions 1 day after they become noncurrent"
+ }
+
+ assert {
+ condition = length([
+ for r in aws_s3_bucket_lifecycle_configuration.deployment.rule : r
+ if r.id == "db-reads-delete-markers" && r.status == "Enabled" &&
+ one(r.filter).prefix == "db-reads/" &&
+ one(r.expiration).expired_object_delete_marker == true
+ ]) == 1
+ error_message = "db-reads/ must remove expired delete markers"
+ }
+
+ assert {
+ condition = length([
+ for r in aws_s3_bucket_lifecycle_configuration.deployment.rule : r
+ if r.id == "geoip-noncurrent" && one(r.filter).prefix == "control/geoip/"
+ ]) == 1
+ error_message = "the control/geoip/ rule must stay as it was"
+ }
+}