@cabane/companion 0.6.228 → 0.6.229

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -158,7 +158,7 @@ An operator-managed sandbox can use the host-side `@cabane/companion/credential-
158
158
 
159
159
  Run the broker and its credential files under a host identity outside every sandbox UID mapping. Hold an exclusive process lock for the entire service lifetime, including shutdown: there must be exactly one renewal owner for each account file. The parent of an account file must be owned by that identity with mode `0700`; the file must be a regular, single-link `0600` file. Stop the service before importing or changing login state. `fileCredentialStore(path)` and `openBrokerCredentials(store)` read that state; share the resulting owner between every grant using the account. Renewal writes and fsyncs a replacement before releasing it. A failed persistence write refuses further use until the operator recovers the stored account.
160
160
 
161
- The account format is `{ mode, accessToken, refreshToken?, idToken?, expiresAt?, accountId? }`. `mode` is `claude-setup`, `claude-oauth`, `codex-oauth` or `github`. OAuth modes require a refresh token and an expiry in epoch milliseconds. A setup token never renews. Normal Claude OAuth renews inside the broker before expiry, or on one upstream 401; Codex renewal returns fresh placeholders to its client. Never place the real account file, a credential-store bind, or an alternate harness login inside the sandbox. Real OAuth compatibility must be verified with the installed harness and login mode; a successful setup-token turn proves nothing about OAuth renewal.
161
+ The account format is `{ mode, accessToken, refreshToken?, idToken?, expiresAt?, accountId? }`. `mode` is `claude-setup`, `claude-oauth`, `codex-oauth` or `github`. OAuth modes require a refresh token and an expiry in epoch milliseconds. A setup token never renews. Normal Claude OAuth renews inside the broker before expiry, or on one upstream 401; Codex renewal returns fresh placeholders to its client. After a failed exchange the owner refuses renewal for a backoff window, 30 seconds doubling to 15 minutes, rather than retrying upstream on every request; a successful renewal clears it. Never place the real account file, a credential-store bind, or an alternate harness login inside the sandbox. Real OAuth compatibility must be verified with the installed harness and login mode; a successful setup-token turn proves nothing about OAuth renewal.
162
162
 
163
163
  Create the broker with `createCredentialBroker({ resolveIdentity, audit? })`. Its `server` handles model and git routes; bind it only to host loopback. Git's HTTP proxy requests are accepted only for the exact `http://github.com/` authority, then forwarded to fixed HTTPS GitHub upstreams. Arbitrary proxy destinations and CONNECT tunnels are refused. Its `githubServer` handles gh's `http_unix_socket` transport; authenticate that socket's peer too. Neither exposes a management endpoint. Call `grant({ identity, credentials, expiresAt })` only from the trusted host adapter. `credentials` maps `claude`, `codex` and `github` to their corresponding credential owners. The returned `token` is disposable; `revoke()` aborts active requests and removes its aliases. Teardown calls `revokeIdentity(identity)`; service shutdown calls `revokeAll()` and closes both servers. A restart creates fresh grants, so old placeholders stop working.
164
164
 
@@ -166,7 +166,7 @@ Scope the GitHub token on GitHub's side; the broker imposes no repository, branc
166
166
 
167
167
  Set `runner.brokeredCredentials: true` beside `runner.command` in the Companion config. This removes provider and GitHub credential variables from the launcher's environment, secret-store payload and device-grant payload before the wrapper receives them. The wrapper supplies `brokerClientConfiguration({ baseUrl, placeholder, githubSocket, codexConfig })`'s environment and generated configuration to the isolated home, and writes `await grant.codexAuth()` as its placeholder-only Codex `auth.json`. The helper preserves the supplied Codex settings while selecting the broker provider and HTTP Responses transport. Include its git configuration in the sandbox's global config and use its gh configuration there. For a GitHub-enabled box, provide `githubSocket`. The helper sets `GH_TOKEN` and preserves `github.com` in git's expanded remote so gh can resolve a tracked branch, without setting `GH_REPO`. The generated git config rewrites HTTPS URLs to an HTTP GitHub URL carrying only a placeholder, and sends that origin through the loopback broker using Git's per-origin `http.proxy`; the broker's upstream hop remains HTTPS. Install the entire generated config, replacing the previous generated file, rather than retaining an older rewrite. Do not bypass this proxy with `NO_PROXY` or a per-remote proxy override. For a model-only box, omit `githubSocket` or pass `null`; no GitHub environment is emitted and both git/gh config strings are empty, so an adapter can clear any previous generated routing. The wrapper must remove old credential mounts and alternate authentication helpers; this switch cannot inspect or secure an operator's filesystem mounts.
168
168
 
169
- The fixed upstream hosts are `api.anthropic.com`, `chatgpt.com`, `api.github.com` and `github.com`. Paths and request bodies pass through without a workflow policy, except for known credential-minting, credential-registering or disclosure endpoints: Claude CLI API-key creation and OAuth token exchange, ChatGPT session/token disclosure, and GitHub app-manifest conversion, installation/application token endpoints, legacy authorizations, SSH user/deploy-key registration, runner registration/removal/JIT credentials and OAuth/device token endpoints. These return new secrets the echo filter cannot know in advance, or register box-chosen credentials that would outlive the grant. This deny-list must be revisited when providers add credential-returning or credential-registering routes; it is not a guarantee against unknown endpoints or arbitrary encodings. Redirects are refused and responses are filtered for known credential echoes. Credential-free injection is restricted to Codex's designated `/backend-api/ps/mcp` route. Each upstream exchange is capped at ten minutes, and request bodies at 64 MiB.
169
+ The fixed upstream hosts are `api.anthropic.com`, `chatgpt.com`, `api.github.com` and `github.com`. Paths and request bodies pass through without a workflow policy, except for known credential-minting, credential-registering or disclosure endpoints: Claude CLI API-key creation and OAuth token exchange, ChatGPT session/token disclosure, and GitHub app-manifest conversion, installation/application token endpoints, legacy authorizations, SSH user/deploy-key registration, runner registration/removal/JIT credentials and OAuth/device token endpoints. These return new secrets the echo filter cannot know in advance, or register box-chosen credentials that would outlive the grant. This deny-list must be revisited when providers add credential-returning or credential-registering routes; it is not a guarantee against unknown endpoints or arbitrary encodings. Redirects are refused and responses are filtered for known credential echoes. Credential-free injection is restricted to Codex's designated `/backend-api/ps/mcp` route. Each upstream exchange, streams included, is capped at ten minutes by default (`requestTimeoutMs` on `createCredentialBroker`), and request bodies at 64 MiB.
170
170
 
171
171
  Arbitrary room secrets and other MCP credentials still follow their existing delivery contract. This API does not protect SSH keys or offer general secret injection into arbitrary HTTP destinations. Claude's feature flags fall back to defaults when their direct requests use placeholders. Before enabling a sandbox deployment, verify actual socket ownership, PID/namespace reuse, service UID separation, grant revocation, concurrent renewal and restart, required client operations, and a canary extraction attempt from inside the real sandbox. A successful unit test or package installation does not establish that host boundary.
172
172
 
@@ -176,6 +176,7 @@ function refuse(res, route, body, status = 403) {
176
176
  function createCredentialBroker(options) {
177
177
  const now = options.now ?? Date.now;
178
178
  const upstream = options.fetch ?? fetch;
179
+ const requestTimeoutMs = options.requestTimeoutMs ?? 6e5;
179
180
  const grants = /* @__PURE__ */ new Set();
180
181
  const byToken = /* @__PURE__ */ new Map();
181
182
  function revoke(grant) {
@@ -233,7 +234,7 @@ function createCredentialBroker(options) {
233
234
  grant.active.add(abort);
234
235
  const signal = AbortSignal.any([
235
236
  abort.signal,
236
- AbortSignal.timeout(Math.max(1, Math.min(6e5, grant.expiresAt - now())))
237
+ AbortSignal.timeout(Math.max(1, Math.min(requestTimeoutMs, grant.expiresAt - now())))
237
238
  ]);
238
239
  res.once("close", () => abort?.abort());
239
240
  body ??= await readBody(req);
@@ -490,6 +491,8 @@ var OAUTH = {
490
491
  clientId: "app_EMoamEEZ73f0CkXaXp7hrann"
491
492
  }
492
493
  };
494
+ var REFRESH_BACKOFF_MS = 3e4;
495
+ var REFRESH_BACKOFF_MAX_MS = 9e5;
493
496
  async function openBrokerCredentials(store, ports = {}) {
494
497
  let account;
495
498
  try {
@@ -501,6 +504,8 @@ async function openBrokerCredentials(store, ports = {}) {
501
504
  const now = ports.now ?? Date.now;
502
505
  let pending;
503
506
  let poisoned = false;
507
+ let failures = 0;
508
+ let retryAt = 0;
504
509
  const secrets = /* @__PURE__ */ new Set();
505
510
  function remember(value) {
506
511
  for (const secret of [value.accessToken, value.refreshToken, value.idToken]) {
@@ -568,9 +573,12 @@ async function openBrokerCredentials(store, ports = {}) {
568
573
  throw new BrokerError("persistence_failed");
569
574
  }
570
575
  account = next;
576
+ failures = 0;
577
+ retryAt = 0;
571
578
  return account;
572
579
  } catch (error) {
573
580
  if (error instanceof BrokerError) throw error;
581
+ retryAt = now() + Math.min(REFRESH_BACKOFF_MAX_MS, REFRESH_BACKOFF_MS * 2 ** failures++);
574
582
  throw new BrokerError("refresh_failed");
575
583
  }
576
584
  }
@@ -584,6 +592,7 @@ async function openBrokerCredentials(store, ports = {}) {
584
592
  if (!account.mode.endsWith("-oauth") || rejectedAccessToken !== void 0 && rejectedAccessToken !== account.accessToken || rejectedAccessToken === void 0 && (account.expiresAt ?? 0) > now() + 6e4) {
585
593
  return account;
586
594
  }
595
+ if (now() < retryAt) throw new BrokerError("refresh_failed");
587
596
  pending = renew();
588
597
  try {
589
598
  return await pending;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cabane/companion",
3
- "version": "0.6.228",
3
+ "version": "0.6.229",
4
4
  "type": "module",
5
5
  "description": "The Cabane Companion (headless): connect an agent on your machine to your Cabane workspace as a responder — drive work against your own codebase, files, and MCP servers without putting any of it in Cabane.",
6
6
  "license": "UNLICENSED",