No description
  • Go 89%
  • Makefile 6.5%
  • Dockerfile 4.5%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-07-30 03:59:40 -04:00
cmd Initial Framework 2026-07-30 03:59:40 -04:00
deploy Initial Framework 2026-07-30 03:59:40 -04:00
docs Initial Framework 2026-07-30 03:59:40 -04:00
internal Initial Framework 2026-07-30 03:59:40 -04:00
pkg/scim Initial Framework 2026-07-30 03:59:40 -04:00
test Initial Framework 2026-07-30 03:59:40 -04:00
.gitignore Initial Framework 2026-07-30 03:59:40 -04:00
go.mod Initial Framework 2026-07-30 03:59:40 -04:00
Makefile Initial Framework 2026-07-30 03:59:40 -04:00
README.md Initial Framework 2026-07-30 03:59:40 -04:00

graytrack-scim

A SCIM 2.0 provisioning server and real-time revocation engine for applications that don't speak SCIM.

Authentik is the identity provider. This service is what happens after the IdP says no.


The problem it solves

Disabling a user in an IdP is a control on authentication. It is not a control on sessions — and the two are not the same thing.

Measured in the lab this was built for (iam-lab/docs/05), a user deactivated in Authentik keeps working:

Application Credential that survives deactivation How long
Forgejo app-local session cookie up to 24 h
Syncthing outpost-minted proxy session up to 24 h
Jellyfin device access token forever

Authentik's own deactivation dialog enumerates nine objects and touches none of these three, because it doesn't own them. This service does: one SCIM event in, a fan-out of app-native revocations out, with elapsed time recorded per target.

Target: p95 under 10 seconds, for all three.


What it is

  • A conformant SCIM 2.0 server — Authentik's SCIM provider is the client
  • A connector layer translating SCIM operations into app-native API calls
  • A revocation fan-out with a context deadline threaded end to end
  • An append-only audit ledger that is the source of the measured numbers

What it isn't

  • Not an IdP. Authentik remains the authority for authentication, MFA, flows, and group membership.
  • Not a replacement for OIDC/LDAP/forward-auth. Those stay the authentication paths; this owns the lifecycle path.
  • Not CAE. Continuous evaluation pushes the check into the resource; this pushes revocation out to it — the achievable half of the same goal.

Architecture in one diagram

flowchart LR
    AK["Authentik<br/>SCIM provider + events"]
    subgraph ENG["graytrack-scim"]
        API["SCIM API + webhook"] --> CORE["normalize → dedupe → resolve<br/>policy → plan"]
        CORE --> Q[("Postgres queue")]
        Q --> W["workers<br/>errgroup + deadline"]
        W --> C["connectors"]
        C --> L[("audit ledger")]
    end
    FG["Forgejo"]
    JF["Jellyfin"]
    AKAPI["Authentik API<br/>(outpost sessions)"]

    AK -->|"SCIM 2.0"| API
    AK -->|"webhook"| API
    C --> FG
    C --> JF
    C --> AKAPI

Full design, phases, and metrics: iam-lab/docs/07. Engineering detail lives in docs/.


Quick start

Requires Go 1.22+ and Postgres 16.

git clone git@github.com:andywitulski/graytrack-scim.git
cd graytrack-scim

cp deploy/env.example .env
chmod 600 .env
$EDITOR .env            # generate secrets: openssl rand -base64 48

make build              # → bin/scimd, bin/workerd, bin/scimctl
make migrate-up         # requires goose and SCIM_DATABASE_URL
./bin/scimd
make check              # vet + race tests — what CI runs
make test-e2e           # full JML against live lab containers (slow)

Container deployment, alongside the Authentik stack:

make docker
docker compose -f deploy/docker-compose.yml up -d

Both services bind loopback only. Caddy terminates TLS for scim.graytrack.net and is the sole ingress, matching the lab's bind policy.


The connector interface is the whole design

Every target implements four methods. The discipline of this shape is what keeps the engine honest:

type Connector interface {
	Key() string
	Probe(ctx context.Context) error                                  // reachable? credentials valid?
	Plan(ctx context.Context, ev core.IdentityEvent) ([]core.Action, error)  // PURE — no side effects
	Apply(ctx context.Context, a core.Action) (Result, error)         // idempotent
	Verify(ctx context.Context, a core.Action) (Verdict, error)       // re-reads state
}

Three properties do the work:

  • Plan is pure. Dry-run is exactly "call Plan, render the actions, stop." That's why it can be trusted.
  • Verify is separate from Apply. An HTTP 204 means the API accepted the request, not that the credential is dead. Only a re-read is evidence.
  • Outcome distinguishes AlreadyDone from Changed. Replay safety becomes observable in the ledger rather than assumed.

Writing a new connector: docs/connectors.md.


Repository layout

cmd/scimd      HTTP server: SCIM API, webhook receiver, status page
cmd/workerd    queue drainer; separate process so a wedged connector
               cannot make the SCIM endpoint unresponsive to Authentik
cmd/scimctl    operator CLI: probe, plan, replay, reconcile, ledger

internal/api/scim    the untyped edge — map[string]any lives here and only here
internal/core        typed domain: IdentityEvent, Action, normalize seam, policy
internal/connector   the interface + one package per target
internal/queue       Postgres queue, SELECT ... FOR UPDATE SKIP LOCKED
internal/audit       append-only ledger, time-to-revoke metrics
internal/recon       scheduled intended-vs-actual drift detection
internal/store       pgx queries, embedded migrations

pkg/scim       exported: SCIM types, filter parser, PATCH applier
test/          conformance | golden (recorded app responses) | e2e (live)
deploy/        Dockerfile, compose, env.example
docs/          engineering docs and ADRs

Design rules worth knowing before reading the code

SCIM is the contract, webhooks are the accelerator. Two inbound paths: Authentik's SCIM provider is authoritative, structured, and replayable; the event webhook is faster but carries less. Deduped by identity + intent. If webhooks die, the system still converges. If SCIM dies, the system is broken and says so.

Keep the SCIM edge untyped, type everything inward. SCIM PATCH is path-expression-driven mutation on a document, which static types hate. map[string]any in internal/api/scim, converted exactly once at internal/core/normalize.go. Nothing past that seam sees an untyped map. (ADR 0002)

Revoke before deactivate. If deactivation succeeds and revocation fails, the account is disabled while the session stays alive — the exact failure this project exists to eliminate, now with a green checkmark on it. Enforced by Action.Rank() and covered by a test.

Deadlines are architecture, not tuning. The p95 objective is a context.Context budget threaded from event acceptance to the last HTTP call. Fan-out is an errgroup with per-target child deadlines; workers record outcomes rather than returning errors, because first-error cancellation would abandon in-flight revocations on other targets.

Break-glass is a column, not a convention. Each lab service keeps one local admin for IdP-down scenarios. An automation able to deactivate those turns a partial outage into a total lockout, so exclusion is enforced in the policy stage with its own test.

New targets start in dry-run. SCIM_DRY_RUN_DEFAULT=true, flipped per target in the target table after its plan output has been read by a human.


Status

Pre-phase-0. The scaffold compiles, tests run, nothing is implemented. Phases:

Phase Exit criterion
☐ 0 Scaffold /status green through Caddy, no port beyond loopback, scimctl probe works
☐ 1 SCIM surface Authentik's provider syncs with zero errors; repeat sync → all already_done
☐ 2 Forgejo connector Full JML; deactivation confirmed by Verify, not by Apply
☐ 3 Revocation fan-out Every row of the table at the top of this README drops to seconds
☐ 4 Jellyfin + Authentik The two credentials Authentik cannot see are dead in budget
☐ 5 Reconciliation Rogue account and missing account both named before either is corrected
☐ 6 Hardening Scoped tokens, HMAC, rate limits, DLQ alerting, restore rehearsed
☐ 7 Write-up Before/after numbers from ledger queries, failure modes, limitations

Honest limitations

  • Single instance. Authentication survives an engine outage; deprovisioning does not.
  • Real-time only for reachable targets. A target that's down when the leaver event fires stays stale until retry or reconciliation. DLQ depth is the honest counterpart to the p95 number and belongs beside it in any report.
  • Push model. It cannot revoke a credential the application exposes no API for — and it cannot revoke a credential nobody documented. Discovery of what credentials exist stays manual, which is Authentik's nine-object gap moved one layer out.
  • No approval workflow, access review, or attestation. That's the IGA layer above this; naming it isn't building it.

License

TBD — add before the repository goes public.