Skip to content

The MCP gateway refuses to start without a token, and lore-api refuses a short git-credential token - #4896

Merged
gedaiu merged 1 commit into
mainfrom
gateway-token-hardening
Nov 18, 2026
Merged

gedaiu merged 1 commit into
mainfrom
gateway-token-hardening

Conversation

@gedaiu

@gedaiu gedaiu commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

Two shared bearer tokens guard routes that are reachable from outside the cluster, and both had a way to be weaker than they look. Found by a security read of the rendered client install chart.

The MCP gateway turned its authentication off when its token was empty. The check on /mcp was !opts.authToken || …, so a gateway started with no LORE_MCP_AUTH_TOKEN answered every caller. It now refuses to start in HTTP mode without one. /healthz and /skills/* stay open on purpose. The local dev stack gives the gateway a fixed local-only token, the same value it already uses for the ingest token.

Token comparison leaked the token's length. secretEquals compared lengths before the constant-time compare. It now compares sha256 digests, so equal-size buffers are always compared. The gateway's bearer check goes through it too (it was a plain ===); the floor git-credential route already did.

lore-api accepted a git-credential token of any length. POST /api/floor/git-credential is public and mints GitHub installation tokens for whoever holds FLOOR_GIT_CREDENTIAL_TOKEN. lore-api now refuses to boot when that token, or either token of a rotation pair, is shorter than 32 characters. Unset is still allowed: the route then answers 503.

Our own cluster: the deployed git-credential token is 65 characters and the gateway reads its token from the lore-ingest-token Secret, so both guards pass on the next deploy. I read the length and the Secret name from the cluster, not the values.

Checked: vitest for apps/mcp-server (406), apps/lore-api (2349), libs/shared (4682) and the scripts/dev tests (62) pass; tsc --noEmit clean in the three packages; eslint clean on the touched files. The two start-up refusals were seen failing with the production line reverted. The constant-time change has no test that fails on the old code, since timing is not observable from a test.

Not checked: a deployed gateway pod. One known leftover: with an empty token the gateway's metrics port opens for a moment before the process exits.

Related: re-cinq/floor#86, re-cinq/utopia#73, re-cinq/ai-agent-subsystem#392

🤖 Generated with Claude Code

… without a floor git-credential token of 32 characters
@lore-agent

lore-agent Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Lore is reviewing this PR — c22633ae-2f00-4194-ad98-515876720cb7.

Submit a review that requests changes to have Lore push a fix for it. Comment @lore review to re-run the review.

@lore-agent

lore-agent Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Nothing blocks this PR from merging now. Lore updates this comment when the reason changes.

@github-actions

Copy link
Copy Markdown
Contributor

🔍 Lore Spec Impact — advisory

This PR touches 11 statement(s) across 2 spec(s), and 8 of them have validating tests this PR does not change.

Feature Specification: Lore — Shared Context Infrastructure · 10 statement(s)

specs/1-lore-platform/spec.md

Background — Usage Scenarios
✓ this PR also changes the tests that validate it

The gateway reads each request body defensively: it JSON-parses the body (an empty body carries no payload), caps it at…

validated by apps/mcp-server/src/transport/http-transport.test.ts:234
via changed file apps/mcp-server/src/transport/http-transport.ts

Background — Usage Scenarios
✓ this PR also changes the tests that validate it

The gateway's top-level router tries /healthz, then /skills/*, before falling through to /mcp: a non-/mcp path …

validated by apps/mcp-server/src/transport/http-transport.test.ts:234
via changed file apps/mcp-server/src/transport/http-transport.ts

Background — Usage Scenarios
✓ this PR also changes the tests that validate it

A gateway restart forgets every in-memory session, so a request carrying a session id the gateway does not know answers…

validated by apps/mcp-server/src/transport/http-transport.test.ts:234
via changed file apps/mcp-server/src/transport/http-transport.ts

FR-19: Task Detail UI (Phase 1)
⚠ the tests that validate it are not touched by this PR

only its test links changed — the statement text itself is unchanged

FR-19.23: lore-api serves the two spend/analytics screens whole — GET /api/analytics/spend-window (the interval-scope…

validated by apps/lore-api/src/transport/routes/analytics/spend-window.test.ts:252, apps/lore-api/src/transport/routes/analytics/spend.test.ts:46

FR-19: Task Detail UI (Phase 1)
⚠ the tests that validate it are not touched by this PR

only its test links changed — the statement text itself is unchanged

FR-19.27: Retired 2026-09-09. The operator-recorded Anthropic credit balance is gone: POST /api/spend/credits no long…

validated by apps/lore-api/src/transport/routes/analytics/spend-window.test.ts:252

FR-19: Task Detail UI (Phase 1)
⚠ the tests that validate it are not touched by this PR

only its test links changed — the statement text itself is unchanged

FR-19.29: /spend attributes Lore-computed spend to the execution cluster that ran each call, so a satellite cluster's…

validated by apps/web-ui/src/app/spend/SpendView.test.tsx:213, apps/lore-api/src/transport/routes/analytics/spend-window.test.ts:252

FR-19: Task Detail UI (Phase 1)
⚠ the tests that validate it are not touched by this PR

only its test links changed — the statement text itself is unchanged

FR-19f — Interval-scoped spend, with the Kubernetes half (added 2026-09-02). The spend page carries a date-interv…

validated by apps/web-ui/src/app/spend/SpendView.test.tsx:213, apps/web-ui/src/app/spend/SpendWindowPanel.test.tsx:195, apps/web-ui/src/app/spend/spend-window-presets.test.ts:34, apps/lore-api/src/transport/routes/analytics/spend-window.test.ts:252, +1 more

FR-19: Task Detail UI (Phase 1)
⚠ the tests that validate it are not touched by this PR

only its test links changed — the statement text itself is unchanged

FR-19g — Whose invoice, and what a run costs (added 2026-09-03). pipeline.llm_calls prices every model call Lor…

validated by apps/web-ui/src/app/spend/SpendView.test.tsx:213, apps/lore-api/src/transport/routes/analytics/spend-window.test.ts:252, libs/shared/src/outbound/llm/model-vendor.test.ts:31, apps/lore-api/src/work/analytics/vendor-split.test.ts:25

FR-19: Task Detail UI (Phase 1)
⚠ the tests that validate it are not touched by this PR

only its test links changed — the statement text itself is unchanged

FR-19h — Reading the spend page at a glance (added 2026-09-09). The page groups its figures into three labelled b…

validated by apps/web-ui/src/app/spend/SpendView.test.tsx:213, apps/lore-api/src/transport/routes/analytics/spend-window.test.ts:252, apps/web-ui/src/app/spend/SpendSection.test.tsx:36, apps/web-ui/src/app/spend/SpendCompareBars.test.tsx:39, +2 more

FR-19: Task Detail UI (Phase 1)
⚠ the tests that validate it are not touched by this PR

only its test links changed — the statement text itself is unchanged

FR-19h.1 — Billing mode from the recorded column (added 2026-10-19). When pipeline.llm_calls carries a `billing…

validated by apps/lore-api/src/transport/routes/analytics/spend-window.test.ts:252, apps/lore-api/src/transport/routes/analytics/spend-window-billing.acceptance.test.ts:59, apps/web-ui/src/app/spend/SpendBillingSource.acceptance.test.tsx:7

…and 1 more statement(s).

9 new statement(s) have no test link yet.

Deterministic · graph @ e33f822 (projected 2026-11-18) · 1 file(s) skipped: changed since the graph last saw them, so their line numbers no longer line up · no tests run by this check

@lore-agent lore-agent 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.

Lore review — Approved

Enforces required MCP gateway bearer token, minimum 32-char floor git-credential token at boot, and constant-time SHA-256 digest comparison.

Must fix (0) · Consider (0) · Nits (0)

Reviewed by gemini-4-argon

Submit a review that requests changes to have Lore push a fix for it. Comment @lore review to re-run the review.

Posted by floor, visit 7fad39fc-d47a-4a0e-808c-1f05fbdba8d6.

@gedaiu
gedaiu merged commit 4acd241 into main Nov 18, 2026
39 checks passed
gedaiu added a commit that referenced this pull request Nov 18, 2026
…ss, in-cluster databases, own Secrets, node selectors, hardened pods (#4901)

A client's platform engineer read `lore-install` 1.0.5 and declined to
apply it. His points were fair: the guide assumed ingress-nginx (retired
upstream), the chart read as if it needed External Secrets and Google,
storage classes and database passwords had to be supplied, and no pod
could be placed on a node pool. A security read of the rendered chart
then found more, including one blocker: off GKE the `lore-ui`
ServiceAccount was never rendered, so its pods could not be created.

This PR is the chart half of the answer. The tutorials that replace
`docs/INSTALL.md` follow in a PR of their own.

## What an installer gets

- **Only GitHub is mandatory.** A new `values.minimal.example.yaml`
holds a GitHub App, a GitHub OAuth app, hostnames and one model key.
Utopia is off by default; tracing, embeddings, cost syncs and Dgraph
telemetry make no outbound call unless configured. A check renders that
file and fails on any Google, Azure or Slack host.
- **Any ingress controller.** No annotation is required. The webhook
rewrite is gone: GitHub posts to `https://<api
host>/api/webhook/github`, so an install needs three hostnames, not
four. cert-manager, external-dns and the ingress class are rendered only
when set.
- **Databases in the cluster.** New chart `deploy/databases`
(`lore-databases`): two CloudNativePG clusters, for Lore (with pgvector)
and for the floor, no cloud assumption, optional backup to any object
store. It generates the passwords and writes the Secrets the install
reads. A managed Postgres still works by setting the host and password.
- **Your own Secrets, or none to think about.** Per credential group:
set the values and the chart writes the Secret, or leave them empty and
create the Secret yourself, and the chart leaves it alone. Tokens nobody
needs to choose are generated once and survive upgrades. A leftover
`CHANGE-ME` or a token under 32 characters stops the install.
`deploy/install/README.md` lists every Secret with its namespace and
keys.
- **Scheduling and identity through plain values.**
`global.nodeSelector` and `global.tolerations` reach every workload of
all bundled charts. `podLabels`, `podAnnotations` and
`serviceAccount.annotations` on every workload replace the
Google-specific wiring, so Azure Workload Identity and GKE Workload
Identity are both just values.
- **One identity-provider block.** `global.oidc` and `secrets.oidc`,
generic OpenID Connect, used by Utopia today. The AKS example shows
Microsoft Entra.
- **Hardened by default in the install.** Non-root, read-only root
filesystem, no privilege escalation, all capabilities dropped, no
mounted ServiceAccount token, images pinned by digest, NetworkPolicies
per namespace, Pod Security `restricted` on the Lore namespaces. The MCP
gateway gets its own inbound token, so agent pods no longer hold the
admin ingest token.
- Example values for AKS, GKE, a local trial and the minimal case. Pins:
floor 0.5.6, Utopia re.37.

## What changes on our own cluster when this merges

Argo CD applies `deploy/chart`. Hardening that could stop one of our
pods is opt-in and stays off for us (`hardened`, NetworkPolicies, Pod
Security labels). What does change, from a render of
`internal-cluster.values.yaml` before and after:

- The four PodDisruptionBudgets stay: `specs/1-lore-platform` requires
Dgraph's, because a restart can strand its disk on the old node. The
client install switches them off by value, since a budget of
`minAvailable: 1` on one replica makes a node drain wait forever.
- New ServiceAccounts for the MCP gateway, Dgraph, the courier CronJobs
and the migrate Job; `automountServiceAccountToken: false` on every pod
but the ownership reconciler.
- `imagePullPolicy` goes from `Always` to `IfNotPresent`.
- Dgraph runs non-root with a read-only root (checked against the real
image locally); its schema Job uses a pinned curl image instead of
`alpine` plus `apk add` as root.
- Courier CronJobs: curl 8.11.1 → 8.23.0, with seccomp. The migrate
Job's Postgres client image is pinned by digest.
- The Workload Identity annotations are now set in our values file; the
rendered ServiceAccounts are unchanged.

Every pod template changes, so every workload restarts once, Dgraph
included.

## How it was checked

- Render assertions in `scripts/check-lore-platform-render.sh`,
`scripts/check-charts.sh` and `scripts/ci/package-install-chart.sh`, on
helm v3.19.0 and v4.2.2.
- **Installed twice on a three-node kind cluster** with CloudNativePG
and Traefik. All pods ready and both migrations completed; UI, API
health, the webhook route and the live WebSocket reachable through
Traefik; the gateway refuses the ingest token and accepts its own;
NetworkPolicies block outsiders and allow the needed paths; every pod
follows `global.nodeSelector` to a labelled node; an upgrade with
unchanged values keeps all 36 Secrets byte-identical and recreates no
database; Pod Security `restricted` raises nothing; a hand-made Secret
is left untouched across four upgrades; under a deny-all egress policy
the four Lore apps logged no attempt to reach a service nobody
configured.
- The first install found five bugs that renders could not: pgvector
created in the wrong database, a wrong format for Utopia's secret key,
the floor left empty because `lore-api` seeds it once at boot (it now
waits for the floor), the live-socket route losing to the UI route on
Traefik, and no way to render an Ingress without TLS.

## Not checked

- A real AKS or GKE cluster, TLS through cert-manager, backups, Workload
Identity, Microsoft Entra.
- Anything that needs real credentials: GitHub sign-in, webhook
delivery, model calls, an agent run. Agent pods were not run under
`restricted`.
- The kind installs used Utopia re.36 (patched by hand, then off); re.37
is pinned and renders, but was not installed.
- The `hardened` setting on `lore-api`, `lore-mcp` and `lore-ui` started
cleanly with the real images; a full day of use is unproven.

## Known leftovers

- `external-secrets.io/v1beta1` is kept in the ExternalSecret template:
I could not see which version our cluster's operator serves.
- Two defaults in the app still name Google and need app changes: the
task-log bucket falls back to `lore-task-logs`, and context building
looks up the npm registry on demand.
- `lore-api` seeding the floor once without retry is worked around with
an init container; a retry in `seed-floor.ts` is the proper fix.
- Dgraph keeps `v24.0.0`, pinned by digest: it is being removed.
- `docs/INSTALL.md` is only patched where a renamed value would mislead;
the tutorials PR deletes it.

Related: #4896, re-cinq/floor#86, re-cinq/utopia#73, re-cinq/utopia#74,
re-cinq/utopia#75, re-cinq/ai-agent-subsystem#392

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant