Repository navigation
gateway: log bearer-token auth state at startup - #255
Conversation
Adds a single LogInfo at the end of TGatewayServer.Start that summarises
the bearer-token auth state without revealing the token. Four cases:
ENABLED (source=env, token len=N, prefix=ab12...)
ENABLED (source=config.json, token len=N, prefix=ab12...)
MISCONFIGURED -- token field is unresolved template '${VAR_NAME}'; ...
DISABLED -- no token configured (every /v1/* route open)
The MISCONFIGURED branch is the motivating case: operators who misspell
PASCLAW_GATEWAY_TOKEN as PASCAL_GATEWAY_TOKEN (no W) in the platform's
env-var UI never trigger the substitution in ExpandEnvVarsInJSON, the
literal `${PASCLAW_GATEWAY_TOKEN}` survives into Cfg.Gateway.Token, and
every client bearer comparison loses against the literal template
string -- producing an "always 401" symptom that's invisible from the
deploy logs without console access to the container. This line surfaces
the typo on the next restart.
The prefix is the first 4 chars + `...` for tokens >= 8 chars (16 bits
of brute-force surface against a hex token); shorter tokens log
prefix=<short> instead of leaking too high a fraction of the secret.
DescribeGatewayAuthState lives next to GetEffectiveGatewayToken in
PasClaw.Config so it has natural access to GEnvGatewayToken without
adding a Gateway -> Auth -> Config dep cycle.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a178c2f404
ℹ️ 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".
| Result := 'gateway: bearer-token auth DISABLED -- ' + | ||
| 'no token configured (every /v1/* route open)'; |
There was a problem hiding this comment.
Include MCP in unauthenticated startup log
When no token is configured, CheckGatewayAuth short-circuits before route checks, and the main listener still dispatches POST /mcp and /v1/mcp/rpc later in PasClaw.Gateway.Server.pas (with --mcp-allow-write, that can expose mutating tools unauthenticated too). This startup message says only /v1/* is open, so operators reading deploy logs can miss that the MCP surface, including a dedicated MCP listener sharing the same config, is also unauthenticated; please make the disabled message cover MCP/all protected routes.
Useful? React with 👍 / 👎.
When no token is configured, the dedicated MCP companion listener
(--mcp-port) and the /v1/mcp/rpc in-main-port path are unauthenticated
alongside the /v1/* surfaces. Old message ("every /v1/* route open")
understated the exposure -- operators reading the log could miss that
the MCP JSON-RPC endpoint is also reachable by any caller. Codex P2.
Summary
Adds one
LogInfoat the end ofTGatewayServer.Startthat summarises the bearer-token auth state, so the typical misconfigurations are visible in the deploy logs without needing toexecinto the container. Surfaces four cases:Motivation
The
MISCONFIGUREDbranch is the case that motivated this PR. The typo trap:PASCAL_GATEWAY_TOKEN(no W) in the platform's env-var UI.ExpandEnvVarsInJSONsees noPASCLAW_GATEWAY_TOKEN, so the literal${PASCLAW_GATEWAY_TOKEN}survives intoCfg.Gateway.Token.GetEffectiveGatewayTokenreturns the literal template string.${PASCLAW_GATEWAY_TOKEN}(the literal characters) — guaranteed mismatch, infinite 401 loop.Without this log line you can only diagnose by
printenv-ing inside the container or grepping the on-diskconfig.jsonfor the unresolved marker. With it, one redeploy shows the operator exactly what's wrong on App Platform / Docker Hub / k8s — wherever the runtime logs are aggregated.Token-safety notes
prefix=<first 4 chars>...for tokens >= 8 chars (~16 bits of brute-force surface against a hex token) andprefix=<short>for shorter tokens (a 4-byte prefix of a 6-byte token leaks too much).MISCONFIGUREDbranch reveals the unresolved template string verbatim — that's a config marker, not a secret.Files
src/pkg/config/PasClaw.Config.pas— newDescribeGatewayAuthState(C: TConfig): stringhelper next toGetEffectiveGatewayToken. Lives inConfigso it can readGEnvGatewayTokenwithout forcing aGateway -> Auth -> Configdep cycle.src/pkg/gateway/PasClaw.Gateway.Server.pas—TGatewayServer.Startnow callsLogInfo('%s', [DescribeGatewayAuthState(FCfg)])right after the existing "gateway: listening on" line. Suppressed whenFMCPOnlyis set so the optional/mcpcompanion listener doesn't double-log.Test plan
Verified each branch against a real gateway boot with a scratch
$PASCLAW_HOME:bearer-token auth DISABLED -- no token configured (every /v1/* route open)gateway.token: "abcdef0123456789ZZ"(18 chars):ENABLED (source=config.json, token len=18, prefix=abcd...)PASCLAW_GATEWAY_TOKEN=<64-char hex>:ENABLED (source=env, token len=64, prefix=cafe...)gateway.token: "${PASCLAW_GATEWAY_TOKEN}"with the env var unset:MISCONFIGURED -- token field is unresolved template '${PASCLAW_GATEWAY_TOKEN}'; env var not set, so no client token will matchprefix=<short>(no leak of a token where 4 chars would reveal most of it)makeclean (FPC 3.2.2)https://claude.ai/code/session_01TBcLtmpj7dqA5tyFbGnQon
Generated by Claude Code