Skip to content

feat(gateway): report TENANT_RLS_MODE, require 052 receipt columns, run 048 off-proof in CI - #240

Merged
PetrefiedThunder merged 4 commits into
mainfrom
fix/rls-followups
Oct 26, 2026
Merged

PetrefiedThunder merged 4 commits into
mainfrom
fix/rls-followups

Conversation

@PetrefiedThunder

@PetrefiedThunder PetrefiedThunder commented Oct 26, 2026 •

Copy link
Copy Markdown
Collaborator

Codex follow-ups from #234 and #236.

  • TENANT_RLS_MODE reporting. The startup runtime_posture log line, which is the one operator posture line, now includes tenant_rls_mode. GET /health returns tenant_rls_mode: off or enforce, a validated enum and never a secret. The default stays off.
  • Boot schema check. REQUIRED_TRUST_COLUMNS["receipts"] now includes enforcement_mode and gateway_build from migration 052, so a database without them fails at startup.
  • CI. The Postgres proofs job creates an empty amw_rls_off_migration database and sets TENANT_RLS_OFF_MIGRATION_DATABASE_URL in the migration round-trip step. That step now runs test_047_048_negative_paths.py::test_postgres_default_off_creates_policies_but_leaves_rls_disabled, which skipped before. proof_log_gate.py already fails the job on any SKIPPED line, so the test has to run.

Tests: new gateway/tests/test_tenant_rls_reporting.py covers the posture line and /health for both modes, the off default, and the boot check naming the missing 052 columns. CHANGELOG updated, and docs/openapi.json regenerated for the /health description.

Local: full gateway suite 5971 passed, 102 skipped. The 048 proof passes against a local PostgreSQL 16 empty database.

This PR doesn't touch the duplicate guard or the hash-chain code. It doesn't port tenant_rls.py; that's a separate PR.


Note

Medium Risk
Startup will refuse databases missing migration 052 receipt columns, and Docker builds can fail when commit SHA sources disagree; health/logging changes are low risk.

Overview
Exposes tenant RLS posture in ops surfaces: the startup runtime_posture log and GET /health now include tenant_rls_mode (off or enforce; default unchanged). OpenAPI/CHANGELOG document the health field.

Boot fails earlier on databases that never ran migration 052: receipts.enforcement_mode and receipts.gateway_build are required trust columns at schema check, not only on first receipt write.

CI Postgres proofs add a dedicated empty DB (amw_rls_off_migration) and TENANT_RLS_OFF_MIGRATION_DATABASE_URL so the migration 048 “default-off RLS” negative proof runs instead of skipping.

Gateway image commit stamping is reworked: write_build_commit_sha.py and the Dockerfile build-metadata stage accept RELEASE_COMMIT_SHA → RAILWAY_GIT_COMMIT_SHA → GIT_COMMIT_SHA → staged .build_commit_sha, require every set source to be a 7–40 hex SHA and agree, and fail the build on mismatch (stale pinned override vs Railway/CI). Smoke script and unit tests cover the new paths; BUILD_COMMIT_SHA/COMMIT_SHA remain ignored.

Reviewed by Cursor Bugbot for commit eabf2ae. Bugbot is set up for automated code reviews on this repo. Configure here.

Build commit stamp (added)

railway up builds failed the stamp step because .build_commit_sha is gitignored. gateway/scripts/write_build_commit_sha.py now resolves, highest precedence first:

  1. RELEASE_COMMIT_SHA build arg (explicit override, kept so the pinned staging variable keeps working)
  2. RAILWAY_GIT_COMMIT_SHA (declared as an ARG in gateway/Dockerfile, so Railway passes it at build time)
  3. GIT_COMMIT_SHA build arg (CI: --build-arg GIT_COMMIT_SHA=$(git rev-parse HEAD))
  4. staged root .build_commit_sha

Every set source must be a 7-40 char hex SHA and all set sources must agree, otherwise the build fails; a stale pin cannot be stamped. BUILD_COMMIT_SHA/COMMIT_SHA stay unread (stale service variables). Tests in test_write_build_commit_sha.py and new smoke cases in smoke_gateway_image.sh.

… at boot

The startup runtime_posture log line and GET /health now carry tenant_rls_mode (off or enforce; the default stays off). REQUIRED_TRUST_COLUMNS now includes receipts.enforcement_mode and receipts.gateway_build, so a database missing migration 052 fails the boot schema check.

Signed-off-by: Christopher <131207452+PetrefiedThunder@users.noreply.github.com>
Create an empty amw_rls_off_migration database and set TENANT_RLS_OFF_MIGRATION_DATABASE_URL in the migration round-trip step, so the PG-gated default-off test runs. The proof-log gate fails the job if it skips.

Signed-off-by: Christopher <131207452+PetrefiedThunder@users.noreply.github.com>
@vercel

vercel Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
agent-middleware-web Ready Ready Preview Oct 26, 2026 7:21am UTC

Request Review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-26T07:00:18.888536Z e7cc36e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between ec94637 and eabf2ae.

Files selected for processing: 1
  • gateway/scripts/write_build_commit_sha.py

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.

Walkthrough

The gateway now reports tenant_rls_mode in startup posture logs and the /health response. Startup schema validation requires receipts.enforcement_mode and receipts.gateway_build. The PostgreSQL proofs workflow configures a database and URL for the default-off RLS migration test. Gateway image builds accept Railway and CI commit SHA sources, validate supplied values, and require them to agree with other supplied sources.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: Minimal · up to eabf2

No actionable merge-blocking risk is established for this PR.

Architecture risk: Low · up to eabf2

The change affects 2 systems.

Changed systems: gateway, CHANGELOG.md

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — gateway (service) was modified; 7 changed files map to changed impact.
  • observed — CHANGELOG.md (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in gateway/app/db/database.py: REQUIRED_TRUST_COLUMNS["receipts"] now includes enforcement_mode and gateway_build among the required columns.
  • observed — Modified behavior in gateway/app/main.py: The startup runtime-posture log now records settings.TENANT_RLS_MODE.
  • observed — Modified behavior in gateway/app/main.py: The /health endpoint description now documents tenant_rls_mode as off or enforce.
  • observed — Modified behavior in gateway/app/main.py: The /health response now includes tenant_rls_mode from settings, described as a validated enum indicating whether migrations enable wallet RLS.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 4.55% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly identifies the main gateway changes: TENANT_RLS_MODE reporting, required migration 052 receipt columns, and the CI PostgreSQL proof.
Description check Passed The description is directly related to the changeset and provides relevant details about reporting, boot validation, CI proofs, build provenance, tests, and documented scope.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

Precedence: RELEASE_COMMIT_SHA override, RAILWAY_GIT_COMMIT_SHA, GIT_COMMIT_SHA, staged .build_commit_sha. All set sources must be 7-40 hex and agree, otherwise the build fails.
Signed-off-by: Christopher <131207452+PetrefiedThunder@users.noreply.github.com>
Signed-off-by: Christopher <131207452+PetrefiedThunder@users.noreply.github.com>

@PetrefiedThunder PetrefiedThunder left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delta review of eabf2ae against main 26613d6. The branch is not behind main, all 48 required checks are green on this head (only the two license matrix placeholders are skipped), and 0 threads are unresolved.

Claims checked:

  • gateway/app/main.py:194,1267: TENANT_RLS_MODE appears in the runtime_posture line and in /health. openapi.json:5955 changes only the description, and it matches the source.
  • gateway/app/db/database.py:128-129: enforcement_mode and gateway_build are now in REQUIRED_TRUST_COLUMNS[receipts], and a sqlite boot-check test covers them.
  • ci.yml:463,520-526: the amw_rls_off_migration DB is created, its env var is set, and the 048 default-off test is selected. The proofs job log shows 3 passed with no skips under -rs.
  • write_build_commit_sha.py:50-89 and Dockerfile:12-14: the order is RELEASE, then RAILWAY, then GIT_COMMIT, then staged. Each value must be 7-40 hex, comparison is case-insensitive, any disagreement or a missing source fails the build, and BUILD_COMMIT_SHA/COMMIT_SHA are not read. Smoke cases are at smoke_gateway_image.sh:148-157.
  • The default stays off (config.py:69 plus validator), and the hash chain and duplicate guard are not touched.
  • Tests follow the real-data rule: the SHA/OTHER constants already existed as placeholders, and nothing else is invented.

Non-blocking notes:

  1. main.py:1265-1267: /health echoes the configured mode, not whether RLS is actually on in the database. 048 enables RLS only if it ran under enforce, so flipping the setting later reports enforce while RLS is still off. Suggest wording it as "configured" in the comment and openapi description, or a follow-up that reads pg_class.relrowsecurity.
  2. write_build_commit_sha.py:87: a short SHA and a full SHA that share a prefix do not count as agreeing. This fails closed, which I think is right, but it is worth a docstring line or a test.
  3. write_build_commit_sha.py:69: a whitespace-only arg is treated as unset (fine for empty Docker ARGs). This is a docstring nit only.
  4. tests/test_tenant_rls_reporting.py:54: Settings() reads env/.env, so a local TENANT_RLS_MODE=enforce would fail it. Use monkeypatch.delenv or _env_file=None.
  5. build_metadata.py:10 still accepts 7-64 while the writer now caps at 40. They are consistent in practice, but worth noting.

I could not run the tests locally because the review venv lacks pytest_asyncio. CI on 3.11-3.14 covers them.

REVIEW: PASS codex eabf2ae

@PetrefiedThunder
PetrefiedThunder merged commit fe7d41b into main Oct 26, 2026
50 checks passed
@PetrefiedThunder
PetrefiedThunder deleted the fix/rls-followups branch October 26, 2026 07:35

This branch was successfully deployed

1 active deployment
Preview — eabf2aec Deployed Oct 26, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant