# API

# API

Drillmark exposes a REST API on `${API_PUBLIC_URL}` (port 8080 inside the container). The frontend is the primary consumer; third-party integrations go through the same endpoints.

## Auth

Every `/api/*` endpoint except the three public ones requires a Bunyip-issued bearer token on `Authorization: Bearer <token>`. Verification runs against the OIDC JWKS declared by `OIDC_ISSUER` / `OIDC_JWKS_URL`. API tokens prefixed `dmrc_` are an alternate credential plane for machine clients, issued from the api-tokens screen in the frontend.

## Public (no auth)

| Method | Path | Purpose |
|---|---|---|
| GET | `/health` | Liveness. Returns `{status, service}`. |
| GET | `/health/db` | Readiness. Executes `SELECT 1` against Postgres. |
| GET | `/api/info` | Build metadata: service name, version, git hash, build date. |

An unauthenticated provider-status endpoint also lives under `/api/admin/providers/status/public-summary` (names and fixed literals only; no secrets).

## Authenticated

Grouped by concern. Mount order comes from `src/routes/mod.rs`.

### Session

- `GET /api/auth/me` - Caller profile and tenant assignment.
- `/api/protected/*` - Authenticated echo surface used by the frontend.
- `/api/oauth/*` - OIDC callback and account-link paths.

### Data sources and processing

- `/api/data-sources/*` - CRUD for the mailboxes Drillmark polls.
- `/api/jobs/*` - Job runs history, per-source and per-run status, manual kick.
- `/api/upload/*` - Manual report upload path for one-off ingestion outside the scheduled pipeline.

### Analytics

- `/api/domains/*` - Monitored domains and per-domain rollups.
- `/api/subdomains/*` - Subdomain discovery for a parent domain.
- `/api/records/*` - Parsed DMARC records with filtering.
- `/api/senders/*` - Sender rollups grouped by source IP, SPF, and DKIM results.
- `/api/countries/*` - Country rollups (requires geolocation enrichment).
- `/api/analytics/*` - Top-level analytics widgets.
- `/api/dashboard-layout/*` - Per-user dashboard layout state.
- `/api/tls-analytics/*` - TLS-RPT rollups.

### Alerts and reports

- `/api/alerts/*` - Fired alerts and their history.
- `/api/alert-config/*` - Alert channels and rules.
- `/api/dns-health/*` - DNS posture for a monitored domain (SPF, DKIM, DMARC record health).
- `/api/spf-analyze/*` - SPF record analysis helper.
- `/api/policy-advisor/*` - DMARC policy recommendations.
- `/api/export/*` - CSV / JSON exports of parsed data.

### User and account

- `/api/user-settings/*` - Per-user preferences.
- `/api/api-tokens/*` - Create, list, revoke machine tokens.
- `/api/geolocation/*` - Admin view into the geolocation enrichment job.

### Admin

- `/api/admin/*` - Super-admin screens.
- `/api/admin/providers/status` - Provider-status aggregator. The unauthenticated `.../public-summary` lives under the same prefix.
- `/api/debug/*` - Diagnostic endpoints. Enabled in all builds; bearer-protected like the rest.

### Local tenancy (feature-flagged)

Off by default (`FEATURE_LOCAL_USER_MANAGEMENT=false`): the following endpoints answer 410 Gone. Flip the flag on only when the Bunyip per-RP tenant work is wired through.

- `/api/invitations/*`
- `/api/organizations/*`
- `/api/users/*`

### Webhooks

- `/webhooks/*` - Mokosh server-to-server webhooks (back-channel logout, lifecycle events). Active when `OIDC_ISSUER` is set; the handlers 404 otherwise.

## CORS

The api's CORS middleware allows one browser origin: `CORS_ORIGIN` (falls back to `FRONTEND_URL`). Set both to the SPA's public URL.

## Rate limiting

Per-client-IP, keyed by the socket peer unless `TRUSTED_PROXY_CIDRS` is configured. See [configuration](/docs/drillmark/configuration).
