Skip to content

fix(backup): apply --exclude-secrets to PostgreSQL Git exports - #174698

Merged
steipete merged 3 commits into
mainfrom
pgprep/pg-git-secrets
Oct 17, 2026
Merged

steipete merged 3 commits into
mainfrom
pgprep/pg-git-secrets

Conversation

@steipete

@steipete steipete commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

PostgreSQL Git backup capture returned before applying --exclude-secrets, so an explicitly redacted backup still contained credentials.

User Impact

SQLite and PostgreSQL Git backups now omit the same credential rows, config scopes, and generated model catalog keys and headers. Existing format-2 PostgreSQL exports remain readable; no format or schema migration is required.

Why This Change Was Made

Both export paths use the existing SQLite secret policy. PostgreSQL applies that policy while copying rows into its portable image, retaining provider-required table definitions. Credential bytes never enter the image, and verification compares the redacted rows and hashes. The shared policy also omits web-push delivery receipts whose subscription parents are excluded, preserving foreign-key validity. The actual database family selects the policy even when a retained store uses a generic Git scope.

Related: #174642.

Evidence

Four PostgreSQL 17 regressions compare state and agent exports with SQLite, including generic scopes, raw artifact bytes, omitted-table metadata, config prefixes, generated catalogs, populated web-push deliveries, and ordinary retained rows. Redacted and default format-2 exports are restored into fresh PostgreSQL namespaces and checked for retained data and credential omission. The same tests fail on main because PostgreSQL reports no omissions. Focused SQLite backup/restore tests and an isolated Codex review are included in validation; final CI status is tracked on this PR.

The final Homebrew PostgreSQL 17 redaction/restore suite passed all four cases in 115 seconds of test time (467 seconds wall time including worker preparation). This crosses both storage engines, checks raw artifact bytes, and restores both export profiles through the provider. Core types, SQL architecture/dialect guards, and the isolated review passed. Final exact-head CI is tracked on this PR.

Final CI passed on 47d66e37febbd3e5952569634071cb8b80efdc9b: run 38973598798. PostgreSQL conformance actually ran and passed in 1,478 seconds; all four new parity cases ran, totaling 22.7 seconds of test time. Hosted re-review reports no actionable findings.

Share the SQLite redaction policy with portable PostgreSQL exports without changing their format. Remove credential rows, generated catalog keys and headers, and credential-derived hashes before publication.
@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: M labels Oct 16, 2026
@steipete
steipete marked this pull request as ready for review October 16, 2026 21:30
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T22:08:49.701902Z 47d66e3 New commits
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5d43b6eb7c

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/snapshot/git-backup-sanitizer.ts Outdated
Comment on lines +88 to +89
for (const table of redaction.excludedTables) {
database.prepare(`DELETE FROM ${quote(table)}`).run();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Badge Cascade dependent rows when clearing secret tables

When a state database contains a web_push_approval_deliveries row, deleting every row from the excluded web_push_subscriptions table leaves that retained row referencing a missing subscription because this snapshot connection does not enable foreign-key cascades. The subsequent publication validation runs PRAGMA foreign_key_check, so backup git create --exclude-secrets aborts for installations with pending web-push approval deliveries; clear dependent rows or perform these deletions with cascade enforcement.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 16, 2026
@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Applies the existing Git backup secret-exclusion policy to PostgreSQL exports before credentials enter the portable image.

Example: A PostgreSQL agent store contains the synthetic credential synthetic-secret-must-not-appear-in-export.

  • Before: A Git backup created with --exclude-secrets still contains that credential.
  • After: The credential is absent from the exported image, while ordinary rows remain restorable.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, source-verified fix with useful real-database integration coverage; confidence is limited by harness-level evidence and unfinished exact-head CI.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; supplied PostgreSQL 17 evidence covers the changed export owner, artifact contents, and fresh-namespace restore through an in-process harness.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A PostgreSQL Git backup explicitly requested without secrets still contains credential material.
Reason: The maintainer-authored change restores the existing exclusion contract and preserves ordinary backup and updater behavior.

Merge readiness

✅ Ready for maintainer review

Keep this PR: it fixes a current credential-export defect, resolves both prior findings, and introduces no remaining actionable defect found in this review; required CI is still pending.

Priority: P1
Reviewed head: 47d66e37febbd3e5952569634071cb8b80efdc9b

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence exercises real PostgreSQL export and restore through an in-process worker harness, rather than a recorded shipped CLI invocation.
Agent review details

How this fits together

The Git backup codec sends PostgreSQL stores through an offline backup worker, which copies admitted database rows into a verified portable image and publishes its manifests.

flowchart TD
  A[Git backup command] --> B[Git backup codec]
  B --> C[Offline PostgreSQL backup worker]
  C --> D[Shared secret exclusion policy]
  D --> E[Portable image materialization]
  E --> F[Verified image and manifests]
  F --> G[Fresh namespace restore]
Loading

Technical review

Best possible solution:

Land the shared pre-materialization redaction fix once the existing required CI gates pass.

Do we have a high-confidence way to reproduce the issue?

Current-main source conclusively bypasses secret exclusion for PostgreSQL capture, and the maintainer reports matching PostgreSQL 17 baseline failures; no reproduction was executed during this read-only review.

Is this the best way to solve the issue?

Sharing the existing policy and filtering before insertion fixes the owning export boundary without introducing a second credential policy or changing backup formats.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against a1506c240aba.

Provenance checked

  • PostgreSQL backup capture keeps the original intent (d0ea7ea: Provide matched PostgreSQL images and anchors for user backups while keeping exact updater recovery separate.)
  • Git backup secret policy and config prefixes keeps the original intent (37b4fc8: Allow operators to exclude credential-bearing content from durable Git history; later singleton consolidation retained secret config-prefix exclusions.)
  • Generated model-catalog redaction keeps the original intent (e0d16ec: Remove complete API-key and header properties, including malformed containers, without changing live credentials or unrelated catalog rows.)
  • Verified database materialization keeps the original intent (cd32ddc: Copy bounded batches and verify canonical typed-cell hashes, allocation facts, and destination integrity before publication.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Current main still exports credentials: Current main's PostgreSQL capture accepts no excludeSecrets option, exports the ordinary user-backup image, and records empty exclusion lists. (src/snapshot/database-backup.ts:304, a1506c240aba)
  • Introduced patch verified: The introduced changes pass the existing exclusion choice into capture and apply the shared row transform before hashing and insertion; the default and exact updater paths retain their existing behavior. (src/snapshot/database-backup-core.worker.ts:71, 47d66e37febb)
  • Prior findings resolved: The follow-up removes the sanitizer's ordinary raw SQL queries and excludes web_push_approval_deliveries together with its subscription parents; populated delivery fixtures now cover this case. (src/state/secret-state-tables.ts:19, 47d66e37febb)
  • Integrity-scan concern disproved: The author's discussion response matches source: capture admits the PostgreSQL descriptor first, and its activeFragments array makes subsequent admission return immediately rather than execute inspectSqlitePortSchema and its integrity scan. (src/infra/database-engine/port-descriptor.ts:92, 47d66e37febb)
  • Database boundary coverage: Four state/agent and standard/generic cases inspect exclusion metadata, actual exported rows and raw image bytes; standard cases restore both redacted and default exports into fresh PostgreSQL namespaces. The maintainer reports these passing on PostgreSQL 17 and failing on main; this review ran no target code. (src/infra/database-engine/git-backup-secrets.postgres.test.ts:177, 47d66e37febb)
  • Exact-head CI remains pending: The current head has PostgreSQL conformance and type checks in progress; the CI gate is pending, while dependency and security-sensitive review statuses are successful. (47d66e37febb)

Likely related people:

  • Peter Steinberger: Raw commit d0ea7ea adds src/snapshot/database-backup.ts:156 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: d0ea7eae7ead; files: src/snapshot/database-backup.ts)

PR surface

Source +110, Tests +282, Docs +3. Total +395 across 9 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 6 163 53 +110
Tests 1 282 0 +282
Docs 2 6 3 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 451 56 +395

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: Current PostgreSQL Git backups can expose credentials despite the operator explicitly selecting --exclude-secrets.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-16T21:47:23.078Z sha 5d43b6e :: blocked before merge. :: [P2] Remove dependent delivery rows when redacting subscriptions | [P2] Use Kysely for the sanitizer's ordinary row queries

Reviewed October 16, 2026, 6:16 PM ET / 22:16 UTC (Revision 2).

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 47d66e37febbd3e5952569634071cb8b80efdc9b
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/state/secret-state-tables.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The follow-up at 47d66e37febbd3e5952569634071cb8b80efdc9b filters rows before portable-image materialization, removing the sanitizer's added raw SQL. The shared exclusion policy also omits dependent web-push delivery receipts.

The populated subscription/delivery fixture reproduced the reported foreign-key failure before that policy correction. All four state/agent and standard/generic parity cases now pass on PostgreSQL 17. The standard-scope cases also restore redacted and default format-2 exports into fresh namespaces and check retained data and credential omission. The follow-up isolated review found no actionable P0–P2 findings. Exact-head CI is running.

@clawsweeper

clawsweeper Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 16, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 47d66e37fe

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

if (params.gitIdentity) {
// Publish hashes of redacted rows, never fingerprints of omitted credentials.
verification.tables = (
await inspectDatabasePort({ engine: "sqlite", db }, descriptor)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 Badge Avoid repeating the SQLite integrity scan during hash refresh

For every PostgreSQL Git backup using --exclude-secrets, this calls inspectDatabasePort merely to recompute table hashes, but SQLite admission inside that helper runs a full assertSqliteIntegrity; createVerifiedSqliteSnapshot then performs another full integrity check when publishing the same staged database. On large installations this adds a redundant whole-database scan to each redacted backup. Refresh the hashes through a scan that trusts the already-owned staging database and leave integrity validation to the publication boundary.

AGENTS.md reference: AGENTS.md:L69-L69

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This path already supplies an admitted descriptor. capturePostgresBackupInWorker calls admitDatabasePortDescriptor on the PostgreSQL source before passing descriptor to exportPostgresBackup. That descriptor carries activeFragments (including an empty array when appropriate).

inspectDatabasePort forwards that descriptor to admitDatabasePortDescriptor, whose descriptor.activeFragments ? descriptor : ... branch returns it directly. It does not call inspectSqlitePortSchema or its assertSqliteIntegrity here. The subsequent table scan refreshes the hashes after transient-state sanitation; output integrity remains at the snapshot publication boundary. I am keeping the existing path because the reported additional integrity scan is not executed.

@clawsweeper clawsweeper Bot added the rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. label Oct 16, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 16, 2026
@steipete
steipete merged commit b0ab440 into main Oct 17, 2026
162 of 164 checks passed
@steipete
steipete deleted the pgprep/pg-git-secrets branch October 17, 2026 00:50
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 17, 2026
…law#174698)

Apply the existing SQLite secret policy to PostgreSQL Git exports without changing format 2. Redact credential rows, secret config scopes, and generated model catalog credentials before materializing portable images; preserve provider-required schemas and consistent verification hashes.

Four cross-engine regression cases cover state/agent families and generic identities, raw artifact secret omission, default exports, and restores. Exact-head CI run 38973598798 passed, including PostgreSQL conformance (24m38s).
RomneyDa added a commit that referenced this pull request Oct 30, 2026
Apply the existing SQLite secret policy to PostgreSQL Git exports without changing format 2. Redact credential rows, secret config scopes, and generated model catalog credentials before materializing portable images; preserve provider-required schemas and consistent verification hashes.

Four cross-engine regression cases cover state/agent families and generic identities, raw artifact secret omission, default exports, and restores. Exact-head CI run 38973598798 passed, including PostgreSQL conformance (24m38s).

(cherry picked from commit b0ab440)
Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. security-sensitive-changed size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant