security(indexer/dev): separate database privileges and prevent production QA mutation #1396

Closed
opened 2026-10-04 12:38:33 +00:00 by PlasticDigits · 5 comments
Owner

Summary and severity

Medium environment-dependent integrity; High if exposed administrative DB access is confirmed. Runtime database privileges, opt-in networking and QA mutation barriers must constrain accidental or compromised administrative access to financial data.

Internal review references: KIMIK3 AUTH-02, TRU-04, DB-01; chain Q. Investigated against source revision 748579ab718026efad54afcef4b2a5186fe82662 on 2026-10-04. These are engineering findings, not third-party audit certification. Only technical findings and synthetic test cases are included; no conversation, user identity, credentials or real-user activity is published.

Current codebase and evidence

Compose initializes the application-named Postgres bootstrap role; no least-privilege runtime/migration split is provisioned. The automatically loaded docker-compose.override.yml enables host networking for Postgres, removing the intended loopback port-publication boundary. Reachability depends on host/firewall and must be measured, not assumed internet exposure. seed-qa is dispatched before run-mode checks and opens the configured database, runs migrations and can clean/seed it.

A reachable administrative database, misused runtime credential or accidentally invoked production seed command can corrupt balances, activity and downstream price/fee reports. This is not a demonstrated unauthenticated SQL injection. The local verifier also encountered an existing shared migration checksum mismatch; fresh isolated API binaries passed all 55 tests, confirming shared-state risk rather than a new product assertion failure.

Why a new implementation is needed

Runtime database privileges, opt-in networking and QA mutation barriers must constrain accidental or compromised administrative access to financial data.

Constraints and guardrails

  • Preserve legitimate indexing writes and authorized migrations; stage role transition with rollback and verified grants.
  • No reset/drop/migration-checksum edits on shared or production databases as a test shortcut.
  • Do not print DSNs/passwords or infer live superuser flags solely from source defaults.

Relevant files

  • Provision separate runtime, migrator and QA roles with minimum table/schema permissions; keep privileged migration credentials out of the server.
  • Make host-network workaround explicit opt-in and restrict database listen/firewall policy. Require nondefault deployment credentials without logging values.
  • Reject production seed/clean before DB connection, and require an explicit isolated QA database identity. Give integration worktrees isolated databases/migration namespaces.

Acceptance criteria

  • Runtime role cannot create roles/databases, alter schema or mutate unrelated applications; migrator/QA permissions are separately verified.
  • Default compose retains loopback confinement; opt-in host networking has explicit bounded exposure.
  • Prod seed-qa and --clean fail before connect/migrate/write; isolated dev QA still works.
  • Parallel worktree integration checks cannot corrupt shared migration history or production data.

Test plan: supported and failure paths

  • Provision a fresh test DB and query role attributes/GRANT behavior; run allowed runtime writes and denied DDL/cross-schema operations.
  • Mock/trace seed prod/dev/unknown modes and database identity, including --help/--clean and missing config.
  • Compare default/opt-in compose rendered configuration and actual socket reachability from permitted/denied test namespaces; rerun API integration suites.

Test plan: attack, hack and abuse vectors

  • Compromised runtime credential tries ALTER ROLE, schema drop, extension/file/program access and cross-database access: deny by real ACL.
  • Spoof dev mode with a production DB URL or invoke seed cleanup from a reused shell: fail before writes.
  • Synthetic remote DB connect under host-network override and default credentials must not be accepted under the hardened deployment policy.

Verification criteria

  • Source defaults, auto host-network override and seed dispatch were checked; no production role or internet exposure claim is made.
  • Require actual role/ACL and network receipts plus no-connection production seed tests. Isolated 55/55 API tests passed after bypassing the shared test DB safely.
    Record revision, UTC time, exact commands, outcomes and evidence scope. Complete runnable checks first. Unavailable signing, deployment, device or infrastructure checks must be explicitly recorded as unverified; they do not block filing or implementation. An executed failure remains FAIL. Never claim deployment acceptance from unit tests or read-only probes. Public receipts must use synthetic identities and omit secrets.

1395: parser-integrity, 1397: evidence-boundaries. Each report owns its stated acceptance scope.

## Summary and severity Medium environment-dependent integrity; High if exposed administrative DB access is confirmed. Runtime database privileges, opt-in networking and QA mutation barriers must constrain accidental or compromised administrative access to financial data. Internal review references: KIMIK3 AUTH-02, TRU-04, DB-01; chain Q. Investigated against source revision `748579ab718026efad54afcef4b2a5186fe82662` on 2026-10-04. These are engineering findings, not third-party audit certification. Only technical findings and synthetic test cases are included; no conversation, user identity, credentials or real-user activity is published. ## Current codebase and evidence Compose initializes the application-named Postgres bootstrap role; no least-privilege runtime/migration split is provisioned. The automatically loaded docker-compose.override.yml enables host networking for Postgres, removing the intended loopback port-publication boundary. Reachability depends on host/firewall and must be measured, not assumed internet exposure. seed-qa is dispatched before run-mode checks and opens the configured database, runs migrations and can clean/seed it. A reachable administrative database, misused runtime credential or accidentally invoked production seed command can corrupt balances, activity and downstream price/fee reports. This is not a demonstrated unauthenticated SQL injection. The local verifier also encountered an existing shared migration checksum mismatch; fresh isolated API binaries passed all 55 tests, confirming shared-state risk rather than a new product assertion failure. ## Why a new implementation is needed Runtime database privileges, opt-in networking and QA mutation barriers must constrain accidental or compromised administrative access to financial data. ## Constraints and guardrails - Preserve legitimate indexing writes and authorized migrations; stage role transition with rollback and verified grants. - No reset/drop/migration-checksum edits on shared or production databases as a test shortcut. - Do not print DSNs/passwords or infer live superuser flags solely from source defaults. ## Relevant files - [docker-compose.yml](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/docker-compose.yml) - [docker-compose.override.yml](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/docker-compose.override.yml) - [indexer/src/main.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/indexer/src/main.rs) - [indexer/src/config.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/indexer/src/config.rs) - [scripts/setup-postgres-dev-databases.sh](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/scripts/setup-postgres-dev-databases.sh) - [scripts/lib/postgres-bootstrap-role.sh](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/scripts/lib/postgres-bootstrap-role.sh) - [indexer/tests/common/mod.rs](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/indexer/tests/common/mod.rs) - [docker/indexer/Dockerfile](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/commit/748579ab718026efad54afcef4b2a5186fe82662/docker/indexer/Dockerfile) ## Recommended direction - Provision separate runtime, migrator and QA roles with minimum table/schema permissions; keep privileged migration credentials out of the server. - Make host-network workaround explicit opt-in and restrict database listen/firewall policy. Require nondefault deployment credentials without logging values. - Reject production seed/clean before DB connection, and require an explicit isolated QA database identity. Give integration worktrees isolated databases/migration namespaces. ## Acceptance criteria - [ ] Runtime role cannot create roles/databases, alter schema or mutate unrelated applications; migrator/QA permissions are separately verified. - [ ] Default compose retains loopback confinement; opt-in host networking has explicit bounded exposure. - [ ] Prod seed-qa and --clean fail before connect/migrate/write; isolated dev QA still works. - [ ] Parallel worktree integration checks cannot corrupt shared migration history or production data. ## Test plan: supported and failure paths - Provision a fresh test DB and query role attributes/GRANT behavior; run allowed runtime writes and denied DDL/cross-schema operations. - Mock/trace seed prod/dev/unknown modes and database identity, including --help/--clean and missing config. - Compare default/opt-in compose rendered configuration and actual socket reachability from permitted/denied test namespaces; rerun API integration suites. ## Test plan: attack, hack and abuse vectors - Compromised runtime credential tries ALTER ROLE, schema drop, extension/file/program access and cross-database access: deny by real ACL. - Spoof dev mode with a production DB URL or invoke seed cleanup from a reused shell: fail before writes. - Synthetic remote DB connect under host-network override and default credentials must not be accepted under the hardened deployment policy. ## Verification criteria - Source defaults, auto host-network override and seed dispatch were checked; no production role or internet exposure claim is made. - Require actual role/ACL and network receipts plus no-connection production seed tests. Isolated 55/55 API tests passed after bypassing the shared test DB safely. Record revision, UTC time, exact commands, outcomes and evidence scope. Complete runnable checks first. Unavailable signing, deployment, device or infrastructure checks must be explicitly recorded as unverified; they do not block filing or implementation. An executed failure remains FAIL. Never claim deployment acceptance from unit tests or read-only probes. Public receipts must use synthetic identities and omit secrets. ## Related remediation reports [1395: parser-integrity](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1395), [1397: evidence-boundaries](https://git.cl8y.com/code/cl8y-dex-terraclassic/issues/1397). Each report owns its stated acceptance scope.
Author
Owner

Merge sweep 2026-10-05: the two existing October 4 audit reports are being preserved on main with the sanity receipt. They document findings; committing them does not implement remediation.

Remaining implementation: Separate indexer database privileges and prevent production QA mutation. The merge checks use a new isolated test database; production privilege/runtime controls remain to be implemented. This issue stays open for that substantive work, not merely a verification hold.

Merge sweep 2026-10-05: the two existing October 4 audit reports are being preserved on main with the sanity receipt. They document findings; committing them does not implement remediation. Remaining implementation: Separate indexer database privileges and prevent production QA mutation. The merge checks use a new isolated test database; production privilege/runtime controls remain to be implemented. This issue stays open for that substantive work, not merely a verification hold.
Author
Owner

Merged PR #1426 and the integrated sanity corrections. Resolved the Makefile conflict by retaining every verifier. Config library/API fixtures now use isolated empty dotenv files, preserving actual runtime rejection of QA/migration credentials. Disposable ACL probes require the final TCP server, avoiding the temporary PostgreSQL startup socket race. Evidence-index deployment now uses the separate scoped migrator.

Final make verify-issue-1396: 28 PASS, 0 FAIL, 2 explicit host-network skips; 564 library and 43 API-security tests plus real CLI/ACL/database isolation checks repeated. Initial dotenv and readiness failures were corrected and retested. Published-loopback on a custom bridge times out and host IPv6 is disabled; internal confinement and host-mode IPv4 pass. Production role transition, scoped migration job and live ACL/exposure rollout remain actual deployment tasks in #1421.

All four source PRs #1424–#1427 are merged; final receipt published through #1430. Local main is reconciled with both remotes, with no stashes. Hosted CI was skipped by explicit operator instruction; no fake PASS status was posted. Original merge protection is restored. Integrated evidence. Source closure does not claim production deployment.

Merged PR #1426 and the integrated sanity corrections. Resolved the Makefile conflict by retaining every verifier. Config library/API fixtures now use isolated empty dotenv files, preserving actual runtime rejection of QA/migration credentials. Disposable ACL probes require the final TCP server, avoiding the temporary PostgreSQL startup socket race. Evidence-index deployment now uses the separate scoped migrator. Final make verify-issue-1396: 28 PASS, 0 FAIL, 2 explicit host-network skips; 564 library and 43 API-security tests plus real CLI/ACL/database isolation checks repeated. Initial dotenv and readiness failures were corrected and retested. Published-loopback on a custom bridge times out and host IPv6 is disabled; internal confinement and host-mode IPv4 pass. Production role transition, scoped migration job and live ACL/exposure rollout remain actual deployment tasks in #1421. All four source PRs #1424–#1427 are merged; final receipt published through #1430. Local main is reconciled with both remotes, with no stashes. Hosted CI was skipped by explicit operator instruction; no fake PASS status was posted. Original merge protection is restored. [Integrated evidence](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/branch/main/docs/qa/merge-2026-10-06-final/README.md). Source closure does not claim production deployment.
Author
Owner

2026-10-07 reconfirmation. Source closure stands on the existing receipt: 28 PASS, 0 FAIL, 2 explicit host-network skips. This pass did not rebuild that suite.

The production role transition remains the #1385 maintenance receipt: 61 migrations, schema marker 20261006133000, history preserved, and four runtime permission denials. make verify-issue-1396 does not replace that receipt.

Related: #1421, #1385.

2026-10-07 reconfirmation. Source closure stands on the existing receipt: 28 PASS, 0 FAIL, 2 explicit host-network skips. This pass did not rebuild that suite. The production role transition remains the #1385 maintenance receipt: 61 migrations, schema marker 20261006133000, history preserved, and four runtime permission denials. `make verify-issue-1396` does not replace that receipt. Related: #1421, #1385.
Author
Owner

PR #1440 (the 2026-10-07 release-close record) is merged and its head 2b608556 is an ancestor of main.

The branch was behind main, so a normal merge returned 405. Updating it onto main made ci/woodpecker/pr/woodpecker pending. Local scripts/qa/verify-issue-1421.sh then passed all cross-link checks. The hosted status gate was overridden so the already-reviewed record could land; no conflict resolution was required. This does not add a new production execution receipt. The earlier contract PASS with production execution UNVERIFIED, and the planned Bridge-Debt journal, are unchanged.

PR #1440 (the 2026-10-07 release-close record) is merged and its head 2b608556 is an ancestor of main. The branch was behind main, so a normal merge returned 405. Updating it onto main made ci/woodpecker/pr/woodpecker pending. Local scripts/qa/verify-issue-1421.sh then passed all cross-link checks. The hosted status gate was overridden so the already-reviewed record could land; no conflict resolution was required. This does not add a new production execution receipt. The earlier contract PASS with production execution UNVERIFIED, and the planned Bridge-Debt journal, are unchanged.
Author
Owner

Merge sanity for #1447/#1448: the final #1396 run passed 28 checks with zero failures and two explicit host-network/IPv6 skips, including the authenticated runtime-login fixture. Its initial targeted run correctly rejected the disposable cluster's unrelated application-database CONNECT grant; revoking that fixture grant and rerunning passed. Application code and assertions were unchanged.

The initial Compose socket probe was cancelled after internal SQL succeeded but published host port 48437 gave no response; the separate QA cluster's published port worked. Host IPv6 is disabled. These are explicit unavailable coverage, not socket PASS. Local source rendering, database isolation and real fresh ACL checks completed. Follow-up coverage is tracked by #1449; this completed source issue remains closed. Receipt.

Merge sanity for #1447/#1448: the final #1396 run passed 28 checks with zero failures and two explicit host-network/IPv6 skips, including the authenticated runtime-login fixture. Its initial targeted run correctly rejected the disposable cluster's unrelated application-database CONNECT grant; revoking that fixture grant and rerunning passed. Application code and assertions were unchanged. The initial Compose socket probe was cancelled after internal SQL succeeded but published host port 48437 gave no response; the separate QA cluster's published port worked. Host IPv6 is disabled. These are explicit unavailable coverage, not socket PASS. Local source rendering, database isolation and real fresh ACL checks completed. Follow-up coverage is tracked by #1449; this completed source issue remains closed. [Receipt](https://git.cl8y.com/code/cl8y-dex-terraclassic/src/branch/main/docs/qa/merge-2026-10-08/README.md).
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
code/cl8y-dex-terraclassic#1396
No description provided.