Skip to content

fix(proxy): make debug CA generation recoverable - #109946

Closed
LiLan0125 wants to merge 1 commit into
openclaw:mainfrom
LiLan0125:fix/109106-proxy-ca-atomic
Closed

LiLan0125 wants to merge 1 commit into
openclaw:mainfrom
LiLan0125:fix/109106-proxy-ca-atomic

Conversation

@LiLan0125

Copy link
Copy Markdown
Contributor

Summary

  • Make debug proxy CA generation publish only complete key/cert pairs by writing OpenSSL output to unique temporary files before promotion.
  • Serialize shared cert-dir generation with a bounded lock and reclaim abandoned lock tokens safely.
  • Clean failed generation output without recursively deleting user-controlled CA output paths.

Refs #109106.

Change Type

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security
  • Chore

Scope

  • Gateway
  • Skills
  • Auth
  • Memory
  • Integrations
  • API
  • UI/UX
  • CI
  • Proxy capture

Verification

  • env PATH=/home/0668001394/.config/nvm/versions/node/v24.16.0/bin:$PATH node scripts/run-vitest.mjs src/proxy-capture/ca.test.ts -> passed 1 Vitest shard.
  • env PATH=/home/0668001394/.config/nvm/versions/node/v24.16.0/bin:$PATH node scripts/run-vitest.mjs src/proxy-capture/proxy-server.test.ts src/proxy-capture/proxy-server.managed-proxy.test.ts -> passed 2 Vitest shards, 11 tests.
  • env PATH=/home/0668001394/.config/nvm/versions/node/v24.16.0/bin:$PATH ./node_modules/.bin/oxfmt --check src/proxy-capture/ca.ts src/proxy-capture/ca.test.ts -> all matched files use the correct format.
  • git diff --check -> passed.

Real behavior proof

Behavior addressed: A stale partial root-ca.pem no longer gets reused, and a successful debug proxy CA generation leaves only a complete reusable root-ca.pem / root-ca-key.pem pair.

Environment tested: Linux workspace, Node 24.16.0, OpenSSL resolved through the production ensureDebugProxyCa path.

Steps run after the patch: Called the actual patched ensureDebugProxyCa source via node --import tsx, starting with a temp cert directory that contained only a stale partial root-ca.pem, then called it again to verify reuse.

Evidence after fix:

{
  "before": [
    "root-ca.pem"
  ],
  "caPair": {
    "certBasename": "root-ca.pem",
    "keyBasename": "root-ca-key.pem",
    "elapsedMs": 205,
    "subject": "CN=OpenClaw Debug Proxy",
    "validTo": "Jul 24 10:54:52 2026 GMT",
    "keyType": "rsa"
  },
  "after": [
    "root-ca-key.pem",
    "root-ca.pem"
  ],
  "tempOrLockFilesAfterGeneration": [],
  "reusedSamePaths": true,
  "afterReuse": [
    "root-ca-key.pem",
    "root-ca.pem"
  ]
}

Observed result: The production function replaced the partial cert-only state with a valid RSA key/cert pair, left no temporary or lock files behind, and reused the same paths on the next call.

Not tested: A live macOS System Keychain trust operation from scripts/proxy-install-ca.mjs; the CA generation path it calls was exercised directly.

Root Cause

  • Root cause: OpenSSL wrote key and certificate outputs directly to the reusable paths, so a timeout or killed child could leave one canonical file behind.
  • Missing guardrail: There was no generation lock, no temporary promotion boundary, and no regression coverage for partial output retry.

Regression Test Plan

  • Added src/proxy-capture/ca.test.ts for reuse, temp-file promotion, retry after failed generation, abandoned lock recovery, active lock waiting, non-recursive cleanup, and same-directory concurrent calls.
  • The focused test is the smallest reliable guardrail because ensureDebugProxyCa is the shared production entry point used by the proxy CLI, proxy server, and CA installer.

User-visible / Behavior Changes

Debug proxy startup and CA installation can recover from interrupted CA generation instead of reusing incomplete CA files or requiring manual cleanup of partial outputs.

Security Impact

  • New permissions? No.
  • Secrets handling changed? No.
  • New network calls? No.
  • CA output cleanup now avoids recursively deleting directories at user-configurable output paths.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. labels Jul 17, 2026
@clawsweeper

clawsweeper Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

This PR addresses the same debug-proxy CA timeout and interrupted-generation failure already owned by the earlier, proof-positive #109106. That branch provides broader integrity safeguards and production-path timeout evidence, so retaining a second locking and publication design would split review and create maintenance drift.

Root-cause cluster
Relationship: duplicate
Canonical: #109106
Summary: Both PRs repair the same ensureDebugProxyCa interruption, timeout, partial-publication, locking, and retry root cause; the earlier PR is the proof-positive viable landing candidate.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Canonical path: Review and land the single canonical implementation in #109106, preserving its certificate integrity checks, bounded OpenSSL termination, deterministic CA properties, safe publication, and focused recovery coverage.

So I’m closing this here and keeping the remaining discussion on #109106.

Review details

Best possible solution:

Review and land the single canonical implementation in #109106, preserving its certificate integrity checks, bounded OpenSSL termination, deterministic CA properties, safe publication, and focused recovery coverage.

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

Yes at source level: interrupted direct OpenSSL output can leave an incomplete reusable CA state, and both PRs target that same current helper path. This review did not independently execute the reproduction.

Is this the best way to solve the issue?

No for this branch as the landing path: the earlier canonical PR provides a single ownership point, stronger generated-pair validation, and more complete timeout and process-cleanup proof.

Security review:

Security review cleared: The branch adds no dependency, workflow, permission, secret, or network surface; consolidating on the canonical branch with explicit key and certificate validation is the safer landing path.

AGENTS.md: found and applied where relevant.

What I checked:

  • Canonical open PR: fix(proxy): bound debug CA generation #109106 predates this PR, remains open, carries proof-sufficient and ready-for-maintainer-look signals, and addresses the same OpenSSL timeout, partial-pair recovery, serialization, and retry behavior. (src/proxy-capture/ca.ts, 5446b8da419e)
  • Explicit overlap: This PR explicitly references the earlier PR and modifies the same ensureDebugProxyCa entry point for the same interrupted-generation failure without identifying distinct remaining product behavior. (src/proxy-capture/ca.ts:20, 5ba7eddfbf86)
  • Stronger canonical safeguards: The earlier branch additionally verifies that the certificate is a CA and matches its private key, applies explicit file modes and CA extensions, and demonstrates bounded termination, orphan-process cleanup, and successful retry through the real OpenSSL production path. (src/proxy-capture/ca.test.ts:1, 5446b8da419e)
  • Feature provenance: The proxy-capture CA and installer surface appears to originate in the merged proxy-capture stack introduction at commit 958c34e. (git.mineracks.com) (src/proxy-capture/ca.ts:1, 958c34e82c)
  • Inspection limitation: The local read-only shell failed before command execution because its sandbox could not initialize loopback networking; the full root AGENTS.md supplied in the prompt and the hydrated GitHub context were still sufficient for the duplicate decision.

Likely related people:

  • Tak Hoffman: Authored the merged proxy-capture stack introduction containing the central CA generation and installer surface. (role: introduced behavior; confidence: high; commits: 958c34e82c; files: src/proxy-capture/ca.ts, scripts/proxy-install-ca.mjs)

Codex review notes: model internal, reasoning high; reviewed against e316e1c44049.

@steipete

Copy link
Copy Markdown
Contributor

Closing per ClawSweeper review verdict duplicate_or_superseded (decision packet 2026-07-17T11:10:59.876Z). This item was part of the audited close backlog (openclaw/clawsweeper#920) stranded by an apply-lane defect, drained manually after re-verification. If this is wrong, reopen and ClawSweeper will re-review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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.

2 participants