GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — mcpx: optional bearer-token auth for /v1 and /mcp (#1975) by dezren39 · Pull Request #2711 · developing-today/code

Conversation

@dezren39

@dezren39 dezren39 commented Oct 30, 2026 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Implements #1975 (triage task 2879 CONFIRMED; queue task 3271).

What

Optional bearer-token auth for the mcpx daemon — a static shared token, deliberately not OAuth (#1950) and not per-server upstream auth (#1926).

  • Setting: transport.bearerToken in the registry (KindString, ScopeDaemon, default unset), env-sourced through the derived MCPX_TRANSPORT_BEARER_TOKEN so the token need not live in a config file. The value is never logged and never appears in an error.
  • Daemon check: a requireBearer middleware sits in both handler chains (startHTTP and Handler(), so the socket, loopback, tsnet, and inline surfaces all pass through it). Token set → every /v1 and /mcp request must carry Authorization: Bearer <token> or gets 401 with WWW-Authenticate: Bearer; comparison is crypto/subtle.ConstantTimeCompare. Token unset → pass-through, behaviour byte-for-byte today's.
  • Startup validation: a set token shorter than 32 characters fails NewServer with an error naming the setting and the minimum length (never the value).
  • First-party callers: cli.Client.authorize resolves the same setting via daemon.BearerToken and attaches the header in open() and the events-stream builder — the CLI path is covered by tests; scripts and the plugin drive the CLI, so they inherit it.

Tests

  • internal/daemon/bearer_test.go: middleware matrix (unset passes with/without stray header; set: missing/wrong/wrong-scheme → 401, correct → 200; 401 carries WWW-Authenticate and never leaks the token) and startup validation (unset/32 ok, short refused with a naming, non-leaking error).
  • internal/cli/bearer_test.go: header attached when configured, absent when not.
  • Verified on the laptop worktree: full internal/daemon and internal/cli suites pass. internal/settings retains only pre-existing failures: the mcpx: three internal/settings guard tests fail on main (compendium chapter + undeclared adapter env) #2697 set, plus script.imports/script.importsOnDynamic effect-coverage gaps that landed with mcpx: resolve a script's import graph statically and prepare missing dependencies #1915 stage 1 (ca3af6b) — not touched here.

Effect guard note

transport.bearerToken is recorded in settings.EffectExemptions (pin 180 → 181, the deliberate-pin path): its with/without behaviour is proven at the daemon HTTP layer by the tests above, but no e2e probe yet starts a token'd daemon and drives a caller against it. Replacing the exemption with that probe is the follow-up.

Refs #1984 (checklist parent), #1950.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • New Features
    • Added optional Bearer-token authentication for daemon requests, configured with a shared token. Tokens shorter than 32 characters are rejected.
    • CLI commands, generated clients, and the OpenCode plugin now include the configured token when connecting to the daemon.
    • Scripts can access the configured token through their environment.
    • When daemon authentication is enabled, the daemon token is not used in place of the upstream provider API key.
  • Documentation
    • Documented the token setting, environment variable, and client behavior.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@dezren39
mcpx: optional bearer-token auth for /v1 and /mcp (#1975)
191aaf3
transport.bearerToken registry setting (env-sourced via the derived MCPX_TRANSPORT_BEARER_TOKEN; value never logged or echoed). Daemon: requireBearer middleware in both handler chains refuses 401 without/with a wrong token, constant-time compare; unset is a pass-through, byte-for-byte today. Tokens under 32 chars are refused at NewServer startup with an error naming the setting and the minimum. First-party callers: cli.Client.authorize attaches the header from the same setting, used by open() and the events stream; scripts and the plugin drive the CLI. Effect guard: exemption recorded for transport.bearerToken (with/without proven at the daemon HTTP layer; an e2e probe should replace it), pin 180 -> 181.
@dezren39
dezren39 requested a review from a team as a code owner October 30, 2026 11:23
@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Review in Change Stack →

Caution

Review failed

The pull request is closed.

Walkthrough

The daemon now supports optional bearer-token authentication. The token setting is exposed to CLI and generated clients, scripts, and the OpenCode plugin. Daemon proxy requests preserve the configured upstream provider key, and takeover requests include the token when configured.

Changes: Daemon bearer-token authentication

Layer / File(s) Summary
Token setting and daemon authentication
pkgs/mcpx/internal/settings/transport.go, pkgs/mcpx/internal/daemon/bearer.go, pkgs/mcpx/internal/daemon/server.go, pkgs/mcpx/internal/daemon/bearer_test.go, pkgs/mcpx/docs/configuration.md, pkgs/mcpx/internal/settings/effect.go
Adds the transport.bearerToken setting and a 32-character minimum for configured tokens. The daemon checks bearer credentials and returns 401 with a Bearer challenge when authentication fails.
CLI token resolution and request coverage
pkgs/mcpx/internal/cli/client.go, pkgs/mcpx/internal/cli/bearer_test.go, pkgs/mcpx/internal/cli/commands.go, pkgs/mcpx/internal/cli/embeddings.go, pkgs/mcpx/internal/cli/exec.go, pkgs/mcpx/internal/cli/feedback.go, pkgs/mcpx/internal/cli/opcmd.go
The CLI resolves the target daemon token and authorizes regular, streaming, and specialized requests. Tests cover token selection, header behavior, and request coverage.
Token propagation to scripts
pkgs/mcpx/internal/daemon/consumer.go, pkgs/mcpx/internal/daemon/routes_exec.go, pkgs/mcpx/internal/execsvc/execsvc.go, pkgs/mcpx/internal/execsvc/bearer_internal_test.go, pkgs/mcpx/internal/cli/commands.go, pkgs/mcpx/docs/environment.md, pkgs/mcpx/internal/settings/scriptenv.go
The CLI and daemon execution service add the configured token to script environments. Explicit environment values retain precedence.
Proxy and takeover request handling
pkgs/mcpx/internal/daemon/routes_proxy.go, pkgs/mcpx/internal/daemon/routes_proxy_test.go, pkgs/mcpx/internal/daemon/takeover.go
When daemon bearer authentication is configured, the proxy does not use the incoming Authorization header as the upstream API key. Takeover requests include the daemon token when configured.
Generated and plugin client authentication
pkgs/mcpx/internal/codegen/emit.go, pkgs/mcpx/plugin/opencode/mcpx/daemon.ts, pkgs/mcpx/plugin/opencode/mcpx/daemon.test.ts, .opencode/plugin/mcpx/daemon.ts
The generated transport and OpenCode plugin add the environment token to requests. Plugin tests cover configured and unset tokens.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant CLIClient
  participant DaemonAuth as requireBearer
  participant DaemonRoutes
  CLIClient->>CLIClient: Add Bearer header when a token is configured
  CLIClient->>DaemonAuth: Send HTTP request
  DaemonAuth->>DaemonAuth: Check Bearer prefix and token match
  DaemonAuth->>DaemonRoutes: Forward accepted request
Loading
Merge Risk: Moderate · up to d02a0

Resolve token lookup and plugin authentication failures, stop unauthorized stream retries, and restrict provider-key destinations before merging. The new script-environment declarations also need correction so settings tests pass.

Finishing Touches
📝 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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
  • X
  • Mastodon
  • Reddit
  • LinkedIn

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

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 ✅ Completed 2026-10-30T20:24:08.226812Z 75cf534 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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dezren39 dezren39 mentioned this pull request Oct 30, 2026
mcpx: optional bearer token for /v1 and /mcp #1975
Closed
4 tasks
chatgpt-codex-connector[bot]
chatgpt-codex-connector Bot reviewed Oct 30, 2026
View reviewed changes

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

Copy link
Copy Markdown

There was a problem hiding this comment.

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: 191aaf3e86

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pkgs/mcpx/internal/cli/client.go Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pkgs/mcpx/internal/daemon/server.go Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pkgs/mcpx/internal/daemon/bearer.go Resolved

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot assigned dezren39 Oct 30, 2026
@dezren39
mcpx: disposition Codex P1+2xP2 on bearer-token auth (#1975)
b3c4ba0
P1: generated script client (TRANSPORT choke point) and the OpenCode
plugin DaemonClient attach Authorization: Bearer from
MCPX_TRANSPORT_BEARER_TOKEN; the CLI runner propagates its resolved
transport.bearerToken into script env so config-file tokens arrive too.
P2: the takeover successor presents the configured token to the
predecessor's gate (takeoverRequest helper, exact-rendering test).
P2: with bearer auth on, the incoming Authorization header no longer
overrides the upstream provider key on /v1/chat/completions.
Unset, every path is byte-for-byte as before.
@dezren39

dezren39 commented Oct 30, 2026

Copy link
Copy Markdown
Member Author

All three Codex findings dispositioned in b3c4ba0 (fixup on this branch):

  • P1 — direct TypeScript clients: the generated script client now wraps TRANSPORT.fetch (single choke point covering /v1/call, /batch, /resource, /artifacts) with the Authorization header from MCPX_TRANSPORT_BEARER_TOKEN; DaemonClient.raw() in plugin/opencode/mcpx/daemon.ts (and the synced dogfood copy under .opencode/) does the same via withDaemonAuth. The CLI runner propagates its resolved transport.bearerToken into script env, so config-file tokens arrive too. Unset, everything is byte-for-byte as before. New tests: daemon.test.ts withDaemonAuth block (3 pass under bun).
  • P2 — takeover: TakeOver() now sends Authorization: Bearer <token> via the new takeoverRequest helper when a token is configured; exact-rendering unit test for set/unset.
  • P2 — proxy/upstream separation: handleChatCompletions no longer lets the incoming Authorization header override the configured upstream key when bearer auth is on (the header is the daemon credential there). Unset behavior unchanged. New test asserts the upstream receives the provider key, not the daemon token.

Local verification: go vet clean; targeted daemon tests pass; full daemon/cli suites show only the pre-existing sandbox failures, byte-identical to the base commit (unix-socket/SSH restrictions of this environment). codegen suite fully green; bun test auth block green.

Not merging: no Actions runs exist on this branch (fleet-wide runner outage #1599 still open), so standing CI criteria cannot be met yet.

@codex review

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dezren39 dezren39 mentioned this pull request Oct 30, 2026
mcpx: /v1/chat/completions panics on schema-built settings (proxy.* paths undeclared) #2726
Closed
chatgpt-codex-connector[bot]
chatgpt-codex-connector Bot reviewed Oct 30, 2026
View reviewed changes

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

Copy link
Copy Markdown

There was a problem hiding this comment.

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: b3c4ba03d4

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pkgs/mcpx/internal/cli/client.go Resolved

Uh oh!

There was an error while loading. Please reload this page.

dezren39 added 2 commits October 30, 2026 07:35
@dezren39
mcpx: authorize the remaining CLI request paths (Codex P2 on #1975)
10e52c4
Client.stream (exec.go), Client.streamOp (opcmd.go) and the direct
requests in feedback.go (3) and embeddings.go (3) built daemon requests
that reached Do() without authorize(), so they 401'd whenever
transport.bearerToken was configured. All eight sites now call the
shared authorize() helper before sending.
TestEveryDaemonRequestIsAuthorized (bearer_test.go) scans the package
and fails if any request-construction site reaches Do() unauthorized
again. go test ./internal/cli/ passes on the laptop.
@dezren39
mcpx: declare MCPX_TRANSPORT_BEARER_TOKEN in ScriptEnv (#1975)
5568182
@dezren39 dezren39 mentioned this pull request Oct 30, 2026
mcpx testing: extended platforms -- which artifacts ship static; alpine, scratch, distroless, flatpak, Fedora, Windows tiers #1987
Closed
chatgpt-codex-connector[bot]
chatgpt-codex-connector Bot reviewed Oct 30, 2026
View reviewed changes

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

Copy link
Copy Markdown

There was a problem hiding this comment.

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: 5568182605

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pkgs/mcpx/internal/codegen/emit.go Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread pkgs/mcpx/internal/daemon/server.go Resolved

Uh oh!

There was an error while loading. Please reload this page.

@dezren39
mcpx: pass the resolved bearer token to daemon-hosted scripts (Codex …
4b73ecb
…P2 on #1975)
chatgpt-codex-connector[bot]
chatgpt-codex-connector Bot reviewed Oct 30, 2026
View reviewed changes

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

Copy link
Copy Markdown

There was a problem hiding this comment.

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: 4b73ecbffd

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pkgs/mcpx/internal/cli/client.go Resolved

Uh oh!

There was an error while loading. Please reload this page.

@dezren39
mcpx: resolve the target daemon's bearer token for record-targeted cl…
d02a018
…ients (Codex P2 on #1975)
chatgpt-codex-connector[bot]
chatgpt-codex-connector Bot reviewed Oct 30, 2026
View reviewed changes

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

Copy link
Copy Markdown

There was a problem hiding this comment.

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: d02a018d6e

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread pkgs/mcpx/internal/cli/client.go Resolved

Uh oh!

There was an error while loading. Please reload this page.

dezren39 added 2 commits October 30, 2026 15:14
@dezren39
mcpx: resolve the target daemon's token through its config chain, not…
663dbf8
… only its nearest file (Codex P2 on #1975)
@dezren39
Merge remote-tracking branch 'origin/main' into queue/3271-1975-beare…
75cf534
…r-token

# Conflicts:
#	pkgs/mcpx/internal/daemon/server.go
@dezren39
dezren39 merged commit 85960a6 into main Oct 30, 2026
1 of 2 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@dezren39
dezren39 deleted the queue/3271-1975-bearer-token branch October 30, 2026 20:22
This was referenced Nov 3, 2026
mcpx: adopt what is useful from codex-connectors-mcp #1984
Closed
mcpx: OAuth authorization for remote servers and for /mcp (61 conformance rows) #1950
Open
mcpx: resolve a script's import graph statically and prepare missing dependencies #1915
Open
@dezren39 dezren39 mentioned this pull request Nov 11, 2026
feat(mcpx): bind server-side authorization rows to the merged bearer gate (#1950) #8512
Merged
This was referenced Nov 21, 2026
Closure audit: every closed issue/PR verified; unmerged branches + unpushed worktrees inventoried #7079
Open
mcpx: the permissive auth interface authorizes everyone — real validation for the conformance rows that require refusal #1972
Closed
AUDIT-7 Lane 4 — MERGED-PR-AUDIT: merged PRs since 2026-10-23 vs their spawning issues #13879
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@chatgpt-codex-connector chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@dezren39 dezren39

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@dezren39
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.