The personal finance app for everyone (by everyone)
Ruby
Start Pipelock's MCP listener with Pipelock 3.2 and later (#4947)
Luis Ibanez4c396048f815
diff --git a/.github/workflows/pipelock.yml b/.github/workflows/pipelock.ymlindex 03e518d415..45bd94f098 100644--- a/.github/workflows/pipelock.yml+++ b/.github/workflows/pipelock.yml@@ -127,3 +127,53 @@ jobs:--set pipelock.enabled=false \--set pipelock.requireForExternalAssistant=false \>/dev/null++ # The checks above validate config files; this one starts the pinned image+ # with the exact arguments Compose and Helm deploy, so flag changes in a+ # Pipelock upgrade fail here instead of at a user's first boot.+ - name: Start Pipelock with the deployed arguments+ shell: bash+ env:+ # Only needed to render compose.example.ai.yml; nothing here uses it.+ SECRET_KEY_BASE: ci-validation-placeholder-not-a-real-secret+ run: |+ set -euo pipefail++ start_and_check() {+ local label="$1" config="$2" image="$3"; shift 3+ local name="pipelock-contract-${label}"+ docker run -d --name "${name}" \+ -v "${config}:/etc/pipelock/pipelock.yaml:ro" \+ "${image}" "$@" >/dev/null+ for _ in $(seq 1 30); do+ if docker exec "${name}" /pipelock healthcheck --addr 127.0.0.1:8888 >/dev/null 2>&1; then+ echo "${label}: Pipelock is healthy"+ docker rm -f "${name}" >/dev/null+ return 0+ fi+ if [ "$(docker inspect -f '{{.State.Running}}' "${name}")" != "true" ]; then+ break+ fi+ sleep 1+ done+ echo "::error::${label}: Pipelock did not start with the deployed arguments"+ docker logs "${name}" || true+ docker rm -f "${name}" >/dev/null || true+ return 1+ }++ compose_json="$(docker compose -f compose.example.ai.yml config --format json)"+ compose_image="$(jq -r '.services.pipelock.image' <<<"${compose_json}")"+ mapfile -t compose_args < <(jq -r '.services.pipelock.command[]' <<<"${compose_json}")+ start_and_check compose "${PWD}/pipelock.example.yaml" "${compose_image}" "${compose_args[@]}"++ chart_config="${RUNNER_TEMP}/sure-chart-pipelock.yaml"+ chart_deployment="${RUNNER_TEMP}/sure-chart-pipelock-deployment.yaml"+ helm template sure charts/sure --kube-version 1.25.0 --set pipelock.enabled=true \+ --show-only templates/pipelock-configmap.yaml \+ | awk '/pipelock.yaml: \|/{copy=1; next} copy{sub(/^ /, ""); print}' > "${chart_config}"+ helm template sure charts/sure --kube-version 1.25.0 --set pipelock.enabled=true \+ --show-only templates/pipelock-deployment.yaml > "${chart_deployment}"+ chart_image="$(ruby -ryaml -e 'puts YAML.safe_load_file(ARGV[0]).dig("spec", "template", "spec", "containers", 0, "image")' "${chart_deployment}")"+ mapfile -t chart_args < <(ruby -ryaml -e 'puts YAML.safe_load_file(ARGV[0]).dig("spec", "template", "spec", "containers", 0, "args")' "${chart_deployment}")+ start_and_check helm "${chart_config}" "${chart_image}" "${chart_args[@]}"diff --git a/charts/sure/CHANGELOG.md b/charts/sure/CHANGELOG.mdindex 4f6ff01cd8..7ae60555c5 100644--- a/charts/sure/CHANGELOG.md+++ b/charts/sure/CHANGELOG.md@@ -8,10 +8,10 @@ and chart releases follow Sure’s [calendar versioning](../../docs/releases/ver## [Unreleased]### Changed-- Add here+- Pipelock's MCP listener now starts with Pipelock 3.2+, which refuses a non-loopback listener without auth. It defaults to `pipelock.mcpProxy.allowUnauthenticated: true`; rendering fails with a clear message if neither option is set.### Added-- Add here+- `pipelock.mcpProxy.authTokenSecret`: require a Pipelock listener token from an existing Secret.## [0.7.4] - 2026-08-31diff --git a/charts/sure/README.md b/charts/sure/README.mdindex 81249c58fa..c6ee23f76a 100644--- a/charts/sure/README.md+++ b/charts/sure/README.md@@ -825,6 +825,18 @@ pipelock:Security: The Ingress routes to port `mcp` (8889). Ensure `MCP_API_TOKEN` is set so the MCP endpoint requires authentication. The Ingress itself does not add auth.+By default the listener runs with `pipelock.mcpProxy.allowUnauthenticated: true`, relying on Sure's own token or OAuth. To make Pipelock require a token too, point `authTokenSecret` at a Secret holding it; clients then send it as `Proxy-Authorization: Bearer <token>`:++```yaml+pipelock:+ mcpProxy:+ authTokenSecret:+ name: sure-pipelock-mcp-token+ key: token+```++Keep `podSecurityContext.fsGroup` (1000 by default) so Pipelock can read the mounted Secret. See [docs/hosting/pipelock.md](../../docs/hosting/pipelock.md#mcp-listener-authentication).+### Metrics (Prometheus)Pipelock exposes `/metrics` on the forward proxy port. Enable scraping with a ServiceMonitor:diff --git a/charts/sure/templates/pipelock-deployment.yaml b/charts/sure/templates/pipelock-deployment.yamlindex f1b1ea2231..608a0d8a09 100644--- a/charts/sure/templates/pipelock-deployment.yaml+++ b/charts/sure/templates/pipelock-deployment.yaml@@ -10,6 +10,15 @@{{- end -}}{{- if .Values.pipelock.image -}}{{- $pullPolicy = .Values.pipelock.image.pullPolicy | default "IfNotPresent" -}}+{{- end -}}+{{- $mcpTokenSecret := dict -}}+{{- $mcpAllowUnauthenticated := false -}}+{{- with .Values.pipelock.mcpProxy -}}+{{- $mcpTokenSecret = .authTokenSecret | default dict -}}+{{- $mcpAllowUnauthenticated = .allowUnauthenticated | default false -}}+{{- end -}}+{{- if and (not $mcpTokenSecret.name) (not $mcpAllowUnauthenticated) -}}+{{- fail "pipelock.mcpProxy needs authTokenSecret.name or allowUnauthenticated=true: Pipelock refuses a non-loopback MCP listener without one" -}}{{- end }}apiVersion: apps/v1kind: Deployment@@ -45,6 +54,15 @@ spec:- name: configconfigMap:name: {{ include "sure.fullname" . }}-pipelock+ {{- if $mcpTokenSecret.name }}+ - name: mcp-listener-token+ secret:+ secretName: {{ $mcpTokenSecret.name | quote }}+ items:+ - key: {{ $mcpTokenSecret.key | default "token" | quote }}+ path: mcp-listener.token+ defaultMode: 0400+ {{- end }}{{- with .Values.pipelock.extraVolumes }}{{- toYaml . | nindent 8 }}{{- end }}@@ -62,10 +80,21 @@ spec:- "0.0.0.0:{{ $mcpPort }}"- "--mcp-upstream"- {{ include "sure.pipelockUpstream" . | quote }}+ {{- if $mcpTokenSecret.name }}+ - "--mcp-auth-token-file"+ - "/run/pipelock/mcp-listener.token"+ {{- else }}+ - "--mcp-allow-unauthenticated"+ {{- end }}volumeMounts:- name: configmountPath: /etc/pipelockreadOnly: true+ {{- if $mcpTokenSecret.name }}+ - name: mcp-listener-token+ mountPath: /run/pipelock+ readOnly: true+ {{- end }}{{- with .Values.pipelock.extraVolumeMounts }}{{- toYaml . | nindent 12 }}{{- end }}diff --git a/charts/sure/values.yaml b/charts/sure/values.yamlindex 8e2103232e..35f53b1769 100644--- a/charts/sure/values.yaml+++ b/charts/sure/values.yaml@@ -530,6 +530,12 @@ pipelock:port: 8889# Auto-computed when empty: http://<fullname>:<service.port>/mcpupstream: ""+ # Listener auth Pipelock requires; the Secret wins if both are set.+ # See docs/hosting/pipelock.md.+ authTokenSecret:+ name: ""+ key: token+ allowUnauthenticated: true# WebSocket proxy: bidirectional frame scanning for ws/wss connections.# Runs on the same listener as the forward proxy at /ws?url=<ws-url>.websocketProxy:diff --git a/compose.example.ai.yml b/compose.example.ai.ymlindex 0085142514..a1eb25b378 100644--- a/compose.example.ai.yml+++ b/compose.example.ai.yml@@ -190,6 +190,9 @@ services:- "0.0.0.0:8889"- "--mcp-upstream"- "http://web:3000/mcp"+ # Pipelock needs a listener token or this flag; Sure's /mcp still requires+ # its own token. To use a listener token, see docs/hosting/pipelock.md.+ - "--mcp-allow-unauthenticated"ports:# MCP reverse proxy — external AI assistants connect here- "${MCP_PROXY_PORT:-8889}:8889"diff --git a/docs/hosting/pipelock.md b/docs/hosting/pipelock.mdindex 982b7c1df5..c464338e1f 100644--- a/docs/hosting/pipelock.md+++ b/docs/hosting/pipelock.md@@ -94,6 +94,22 @@ MCP_API_TOKEN=generate-a-random-token```+### MCP listener authentication++Pipelock 3.2 and later refuse to start a non-loopback MCP listener unless it has a listener token or the `--mcp-allow-unauthenticated` acknowledgement. The example uses the acknowledgement: Sure's `/mcp` still requires its own token, `/mcp` is already reachable on port 3000, and OAuth-only MCP clients can't send the extra header a listener token needs.++To require a listener token in Docker Compose:++1. Generate it so that only its owner can read it (Pipelock rejects world-readable token files): `(umask 077; openssl rand -hex 32 > pipelock-mcp-listener.token)`+2. Pipelock runs as uid/gid 1000 and must be able to read the file. On Linux, if your user isn't 1000, set `PIPELOCK_UID` and `PIPELOCK_GID` in `.env` to the numbers `id -u` and `id -g` print.+3. Mount it on the `pipelock` service: `- ./pipelock-mcp-listener.token:/run/pipelock/mcp-listener.token:ro`+4. Replace `--mcp-allow-unauthenticated` with `--mcp-auth-token-file` and `/run/pipelock/mcp-listener.token`.+5. Recreate Pipelock so the new user, mount and flag take effect: `docker compose -f compose.ai.yml up -d pipelock`++In Helm, set `pipelock.mcpProxy.authTokenSecret.name` to a Secret holding the token (key `token`, or set `authTokenSecret.key`). The pod's `fsGroup` (1000 by default) is what lets Pipelock read the mounted Secret; keep it if you override `podSecurityContext`.++Clients then send `Proxy-Authorization: Bearer <listener token>` alongside their usual `Authorization: Bearer <MCP_API_TOKEN>` for Sure. Without the listener token Pipelock answers `407 Proxy Authentication Required`.+### Running without PipelockTo use `compose.example.ai.yml` without Pipelock, remove the `pipelock` service and its `depends_on` entries from `web` and `worker`, then unset the proxy env vars (`HTTPS_PROXY`, `HTTP_PROXY`).@@ -285,6 +301,8 @@ Common issues:- Missing `pipelock.example.yaml` file- YAML syntax errors in config- Port conflicts (8888 or 8889 already in use)+- `non-loopback MCP listener ... requires an auth token file`: Pipelock 3.2+ needs `--mcp-allow-unauthenticated` or `--mcp-auth-token-file`. See [MCP listener authentication](#mcp-listener-authentication).+- `has insecure permissions` or `permission denied` reading the listener token: see the file steps in [MCP listener authentication](#mcp-listener-authentication).### LLM calls failing with proxy errors