Skip to content

Authentication

Reads are public. Writes need a session for a GitHub account that is on an allow-list. Sign-in uses the OAuth 2.0 authorization-code flow and a stateless signed session cookie. It needs no database and no extra service.

What is gated

Action Anonymous Signed in and allow-listed
Topology, metrics, anomalies, question router, SPARQL SELECT and ASK allowed allowed
POST /api/v1/observations 401 allowed
POST /api/v1/demo/metric 401 allowed

A signed-in account that is not on the allow-list receives 403.

The browser UI has no sign-in control yet. Start the flow by opening /auth/github/login on the same origin as the API.

1. Create a GitHub OAuth App

In GitHub, open Settings, Developer settings, OAuth Apps, New OAuth App:

  • Homepage URL: your deployment, for example https://blackfox.example.org
  • Authorization callback URL: https://blackfox.example.org/auth/github/callback

Copy the client ID and generate a client secret.

For local development use http://localhost:7860 and http://localhost:7860/auth/github/callback.

2. Configure Black Fox

Set these as environment variables or platform secrets. Never commit them.

GITHUB_OAUTH_CLIENT_ID=<client id from GitHub>
GITHUB_OAUTH_CLIENT_SECRET=<client secret from GitHub>
SESSION_SECRET=<random string of 32 or more characters>
AUTH_ALLOWLIST=eoinjordan,teammate-2
# OAUTH_REDIRECT_BASE=https://blackfox.example.org   # optional, else derived from the request

SESSION_SECRET must stay the same across restarts, or every session ends at each restart. Generate one with:

python -c "import secrets; print(secrets.token_urlsafe(48))"

3. Endpoints

Route Purpose
GET /auth/me Current session: authenticated, user, loginConfigured, devLogin, allowlistConfigured
GET /auth/github/login Begin sign-in. Redirects to GitHub.
GET /auth/github/callback OAuth callback. Sets the session cookie.
POST /auth/logout Clear the session
POST /auth/dev-login Development login. Returns 404 unless AUTH_DEV_LOGIN=true.

Development login

For local work without a GitHub round trip:

AUTH_DEV_LOGIN=true AUTH_ALLOWLIST=dev-user blackfox serve

POST /auth/dev-login then issues a session for the first name on the allow-list, with no check of who is asking. The bundled collectors use it when run with --dev-login. Never enable it on a server that other people can reach.

Collectors

Collectors have no credential of their own yet. They can write through the development login only. Token authentication for collectors is not implemented.

Security notes

  • The session cookie is HttpOnly, SameSite=Lax, and Secure on HTTPS.
  • The OAuth state value is checked against a short-lived cookie.
  • Sessions are HMAC-signed and expire after SESSION_TTL_SECONDS, eight hours by default.
  • Sign-in is same-origin with the API. A static frontend on another origin cannot carry the session cookie.
  • Put GITHUB_OAUTH_CLIENT_SECRET and SESSION_SECRET in the secret store of your platform. Do not pass them through third parties.