Repository navigation
Extending Authenticator
An
Authenticatordecides who may call the HTTP server: it maps a request's headers to a role,readeroradmin, or toNonefor "not authenticated". The shippedBearerTokenschecksAuthorization: Bearer <token>against a token map; write your own to use your identity provider, an API gateway header or mTLS details. Pass it ascreate_app(guru, authenticator=...)orserve(guru, authenticator=...).
schemaguru.server.Authenticator:
class Authenticator(Protocol):
def authenticate(self, headers: Mapping[str, str]) -> str | None:
"""The caller's role, or None when the request is not authenticated."""Roles are "reader" (every route except /refresh) and "admin" (all routes). None makes
the server answer 401 (SG805) with a WWW-Authenticate: Bearer challenge; a reader on an admin
route gets 403 (SG806). /healthz never asks. Header names arrive as the server received them;
look them up case-insensitively.
Behind an API gateway that has already authenticated the caller and sets X-Auth-Groups:
from collections.abc import Mapping
from schemaguru.server import BearerTokens, serve
class GatewayGroups:
"""Role from the gateway's group header; falls back to bearer tokens."""
def __init__(self, fallback: BearerTokens) -> None:
self.fallback = fallback
def authenticate(self, headers: Mapping[str, str]) -> str | None:
groups = {g.strip() for g in (headers.get("x-auth-groups") or "").split(",")}
if "schemaguru-admins" in groups:
return "admin"
if "analysts" in groups:
return "reader"
return self.fallback.authenticate(headers)
serve(guru, authenticator=GatewayGroups(BearerTokens({"<long-break-glass-token>": "admin"})))Only trust such a header when the gateway strips it from incoming requests; otherwise anyone can
send it. Rules for any authenticator: never log or echo credentials, compare secrets in constant
time (hmac.compare_digest, as BearerTokens does over SHA-256 digests), and return None
rather than raising for bad input.
from starlette.testclient import TestClient
from schemaguru.server import BearerTokens, create_app
def test_roles(guru):
app = create_app(guru, authenticator=GatewayGroups(BearerTokens({"t" * 20: "admin"})))
c = TestClient(app)
assert c.get("/search", params={"q": "orders"}).status_code == 401 # nobody
assert c.get("/search", params={"q": "orders"},
headers={"X-Auth-Groups": "analysts"}).status_code == 200
assert c.post("/refresh", json={}, headers={"X-Auth-Groups": "analysts"}).status_code == 403Pass the object in. An installed package can also declare it in the entry-point group
schemaguru.authenticators; schemaguru.plugins.get("authenticators", name) returns it (a
plugin that fails to load is skipped with SG108).
SchemaGuru is open source under the MIT License, Copyright (c) 2026 Rupak Chakraborty · Repository · Issues · This wiki is generated from docs/wiki/; edit it there, not here.
Start here
Components
- Catalog and Crawl
- Store
- Measurement
- Sampling
- Join Graph
- Path Search and Hub Guard
- Waypoint Rules
- Drafting
- PII and Sampling Policy
- Overlays
- Scoping
- Rendering
- Refresh and Drift
- Feedback and Guard
- Server
- Agent Integration
Using it
Warehouses
- BigQuery
- Snowflake
- Redshift
- Databricks
- PostgreSQL
- DuckDB
- ClickHouse
- SQL Server / Synapse
- Oracle
- Trino
- MySQL / MariaDB
Extending
- CatalogReader
- Store
- Retriever and Embedder
- TokenCounter
- LLMProvider
- PII Detector
- FailureClassifier
- FactKind
- Profile and Format
- ChangeClassifier
- JoinCandidateSource (planned)
- Authenticator
Project