Repository navigation
fix: require bearer tokens for org config, docs and audit API routes (#59) - #127
Merged
Merged
Conversation
PUT /orgs/{org}/config (tenant credentials), the config status, the
org docs routes and /audit were reachable by anyone who could reach
the API port (#59).
New api/api_auth.py gates all eight routes:
- API_ADMIN_TOKEN: platform operator token, valid for every org
- API_ORG_TOKENS: org=token pairs, each valid only for its own org;
a token for another org gets 403
- missing/unknown/non-Bearer token: 401 with WWW-Authenticate
- neither configured: 503 (fail closed); API_AUTH_DISABLED=true is an
explicit local-development opt-out and logs a warning at startup
Tokens are compared in constant time. Webhooks keep their signature
checks and /health stays open.
CI's integration job now asserts /audit is 401 without a token and 200
with one. Docs and curl examples send the token; SECURITY_GUARANTEES
no longer says the API is unauthenticated.
The MCP configure_org_credentials gap is tracked separately in #116.
Fixes #59
Co-Authored-By: Claude Opus 5.5 <[email protected]>
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Fixes #59 for the HTTP API. The MCP part of #59 (
configure_org_credentialsover SSE/HTTP) needs a different mechanism and is tracked in detail in #116.Anyone who could reach the API port could write any tenant's credentials (
PUT /orgs/{org}/config), read which integrations each org has configured, upload, read or delete runbooks, and read the full incident audit trail.New
api/api_auth.pygates all eight routes:/audit,/orgs/{org}/config,/orgs/{org}/config/status, and the five/orgs/{org}/docs*routes.API_ADMIN_TOKENAPI_ORG_TOKENS=acme=tok1,globex=tok2API_AUTH_DISABLED=trueis an explicit opt-out for local dev and logs a warning at startupBearerWWW-Authenticate: BearerTokens are compared in constant time (reusing
_signatures_equal), and every org token is compared so timing doesn't reveal which org matched. For/auditthe org is?org_id=orORG_ID. Webhooks keep their own signature auth, and/healthstays open for probes.After upgrading, the org config, docs and audit routes return 503 until
API_ADMIN_TOKENorAPI_ORG_TOKENSis set. This is deliberate: failing open would leave existing deployments exposed. Webhooks, Slack and/healthare unaffected..env.exampledocuments the new variables.Type of Change
Testing
tests/test_api_auth.py(64 tests). Every protected route × missing token, unknown token,Basicscheme, admin token on any org, org token on its own org, org token on another org (403), not configured (503), explicit disable. Also: a rejected credential write stores nothing,/auditauthorizes againstORG_IDwhenorg_idis omitted, the multipart upload route,API_ORG_TOKENSparsing, and webhooks//healthunaffected.server.py, 38 of the 64 fail: every rejection case. The 26 that pass are the "authorized request succeeds" cases, which old and new both allow.test_api.py,test_basic.py, andtest_agent.py, which callsget_auditdirectly)./auditmust return 401 without a token and 200 with one.-ll: clean.mkdocs build --strictplus link check: 0 errors.Docs
docs/API_REFERENCE.md: auth table plus a new "Management API tokens" section.README.mdBYOK section explains$API_TOKEN.curlexamples for these routes across the docs now send-H "Authorization: Bearer $API_TOKEN".SECURITY_GUARANTEES.md: the statements that the API has no authentication (true until now, per docs: correct the unbacked claims left in SECURITY_GUARANTEES.md #113) are updated.🤖 Generated with Claude Code