Skip to content

fix(sso): trust mpass identity headers only from traefik and verify the token - #8

Merged
UsamaSadiq merged 5 commits into
foss-sandboxfrom
fix/foss-778-proxy-header-trust
Nov 13, 2026
Merged

UsamaSadiq merged 5 commits into
foss-sandboxfrom
fix/foss-778-proxy-header-trust

Conversation

@UsamaSadiq

@UsamaSadiq UsamaSadiq commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

Description

  • Closes FOSS-778: Zammad now trusts mPass identity headers only on requests that came through Traefik, and verifies the forwarded token's signature before the corporate-ID check. Same contract as the Plane fix (FOSS-776, fix(auth): trust mpass identity headers only from the edge and verify the token plane#58).
  • Do not merge or deploy before the bundle wiring (ZAMMAD_EDGE_SECRET, Traefik set/strip middlewares, x-zammad-env) and the zammad-mcp-server mint change. Without the secret this image ignores every identity header, so SSO and zammad-mcp token minting both stop working.
  • Before: lib/zammad/mpass_proxy_auth.rb accepted X-Auth-Request-* from any caller that reached zammad-nginx or zammad-railsserver on the Docker backend network, and base64-decoded the forwarded token without checking its signature. A forged email header also overrode an API token.
  • lib/zammad/mpass_edge_trust.rb (new): X-Mpass-Edge-Secret compared with MPASS_EDGE_SECRET via ActiveSupport::SecurityUtils.secure_compare. Empty, shorter than 32 characters or a CHANGE_ME_ value trusts nothing.
  • lib/zammad/mpass_proxy_auth.rb (rewritten):
    • Without a matching secret, every HTTP_X_AUTH_REQUEST_* key is deleted from the Rack env before anything reads it, so nothing logs in, creates a user or switches the session. A warning logs the mPass id, path and addresses, never the email.
    • X-Mpass-Edge-Secret is always removed from the env.
    • The corporate gate runs when a session is opened or switched to another user, not on every request, so a briefly expired forwarded token or a JWKS outage does not log out signed-in users. mpass-auth-proxy still enforces the corporate ID on every login and refresh.
    • Refusals log a reason code only. The old line that printed the expected corporate ID is gone.
    • Startup errors when the secret is unusable, and when SMB_CORPORATE_ID is set but no issuer or client id is configured.
  • lib/zammad/mpass_token_verifier.rb (new): RS256 only; exp, iat, iss, token_use required; 60s leeway. Issuers: MPASS_COGNITO_ISSUER_URL (fallback region + pool id) and optional MPASS_TOKEN_ISSUER_URL. Audience: client_id or aud must be MPASS_OIDC_CLIENT_ID or MPASS_MCP_OIDC_CLIENT_ID (zammad-mcp can sign in with its own Cognito client).
  • lib/zammad/mpass_jwks_cache.rb (new): one key set per issuer, 1h cache, 2s timeout, 30s backoff after a failed fetch.
    • The fetch runs outside the lock, with one in-flight fetch per issuer, so login threads don't queue behind it.
    • After a failed refresh the last set is served for up to 24h with a warning; only an issuer never fetched fails with jwks_unavailable.
    • An unknown key id refetches at most once per 30s, so key rotation is picked up.
  • Gemfile: gem 'jwt', '~> 3.2' pinned explicitly. It was already in the lockfile through other gems; the lockfile resolution is unchanged.
  • CI repair (repo-wide, not specific to FOSS-778; every zammad PR and the scheduled foss-main run fail without it since late October):
    • .github/workflows/ci.yaml: pins zammad/zammad-ci to the digest of the last green run (Ruby 3.4.9). The moving latest tag now ships Ruby 4.0.9, which fails bundle install against the Gemfile's 3.4.9. Unpin when Ruby is bumped on the next upstream sync.
    • config/brakeman.ignore: refreshes the existing upstream ignore for the Rails 8.0 end-of-life warning, whose fingerprint changed after 2026-11-07.
  • doc/mpass_sso.md: new env vars and the security section.
  • Log redaction: the existing HttpLog masking already filters both headers; a new request spec proves it.
  • Not affected: API tokens (including zammad-mcp's minted tokens), the /ws websocket process (session cookies), the WhatsApp webhook bypass.

Testing

  • bundle exec rspec spec/lib/zammad/ spec/requests/application_controller/logs_http_access_spec.rb (RAILS_ENV=test CI_SKIP_ASSETS_PRECOMPILE=1 VITE_TEST_MODE=1, throwaway container): 177 examples, 0 failures. Rubocop clean on touched files.
  • Specs cover: forged headers with no secret, a wrong secret, a 32-character prefix of the real one, a short or empty configured secret; correct secret logs in; token-only and cookie sessions pass through; valid, expired, wrong-issuer, wrong-audience, foreign-key, unsigned, tampered, alg=none and HS256 tokens; missing claims; future iat; JWKS failure, non-JSON body, backoff, stale-set grace, concurrent fetches; gate unset means no JWKS fetch.
  • Devstack (fix files bind-mounted into the current zammad:dev 7.1.2 image, scratch override for the secret and middlewares):
    • Forged X-Auth-Request-Email to zammad-nginx:8080 with no secret or a wrong one: 403, no user created.
    • Same request with the correct secret: 200.
    • zammad-mcp-style mint with the secret: token minted. Minted token on /users/me and /tickets: 200. Minted token plus a forged email for another agent: 200 as the token owner.
    • Against the live Cognito JWKS: forged signature, unknown key id, HS256 and foreign issuer all refused.
    • Browser SSO through Traefik: 200. With a dummy SMB_CORPORATE_ID, refused with wrong_organization, reached only after the real token passed signature, issuer and audience checks.

…he token

Honour X-Auth-Request-* only when X-Mpass-Edge-Secret matches
MPASS_EDGE_SECRET, and verify the forwarded token against the issuer
JWKS before the SMB corporate check. FOSS-778
A logged-in session no longer depends on the forwarded token being
fresh or the JWKS being reachable on every request. FOSS-778
…h failure

Declare jwt directly in the Gemfile. FOSS-778
zammad-ci:latest moved to a newer ruby and pre.sh rejects the Gemfile's 3.4.9 pin.
The EOL date passed, which changed the warning's fingerprint and left the existing ignore entry obsolete.
@UsamaSadiq
UsamaSadiq merged commit 9ed57ca into foss-sandbox Nov 13, 2026
2 checks passed
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