- TypeScript 97.7%
- Shell 2.3%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
|
||
| .forgejo/workflows | ||
| .githooks | ||
| deploy | ||
| scripts | ||
| src | ||
| tests | ||
| .gitignore | ||
| deno.json | ||
| deno.lock | ||
| LICENSE.md | ||
| README.md | ||
limedoc-sites-gate
OIDC login in front of the protected (oidc) websites of one Limedoc Sites
deployment target. Caddy asks it on a Unix socket before serving a page; it
keeps no site content and has no listening port.
Source-available under FSL-1.1-ALv2 (LICENSE.md).
Flow
- Caddy (
forward_auth, snippetgatein the deployer's main Caddyfile) asksGET /verify?site=<host>. A valid__Host-sgcookie for exactly this host whose claims satisfy the site's audience → 200, the page is served. - Otherwise the gate answers 302 to
https://auth.<domain>/login?return=https://<host><path>&n=<nonce>and sets the nonce as__Host-sgnon the site host. A signed-in visitor whose account does not qualify gets a 403 page with "sign in with another account" instead. /loginonauth.<domain>accepts onlyhttps://<host>returns whose host is listed in the deployer'saccess.json(no port, no user info: no open redirect). With an SSO session (__Host-sgaonauth.) it skips the IdP; otherwise authorization code + PKCE (S256) withstatebound to a__Host-sgtxcookie and an ID tokennonce./callbackchecks state and binding, exchanges the code (client_secret_basic), verifies the ID token against the JWKS (RS256, ES256, EdDSA;iss,aud/azp,exp,iat,nonce) and creates the SSO session.- A one-time ticket (60 s, in memory) goes to
https://<host>/.sites-gate/callback?ticket=…. It is only accepted on its host and together with the__Host-sgnnonce cookie set in step 2, so a ticket cannot be planted in someone else's browser. The answer sets__Host-sg(HttpOnly, Secure, SameSite=Lax, Path=/, 8 h, never past the end of the SSO session it came from) and returns to the page.
The site cookie is HMAC-signed and holds the host, a hash of issuer + sub, the
claims of the visitor the site's audience names (nothing else) and the expiry —
no names or e-mail addresses. Rules come from access.json, re-read when the
file changes, so a changed audience, a removed visitor or a takedown applies to
existing cookies. Claims are the union of realm_access.roles, roles and
groups (claimPaths), as in Limedoc.
A site admits a visitor when any of these holds (ADR 0007):
- an audience claim matches:
{school: […]},{course: […]},{private: […]}(the teacher claims of the site's space) or{authenticated: true}; - the visitor is the site's owner;
- the visitor is a listed visitor and still holds one of the site's school claims (a site without school claims, as in general targets, admits a listed visitor by subject alone);
- the visitor is a guardian of the owner and the site admits guardians.
A guardian's login is admitted by rule 4 alone: never as "any account"
(authenticated), by claims, as owner or as visitor.
Owner and visitors are subject hashes,
base64url(sha256(issuer + "\n" + sub))[0..22], computed by Limedoc. They only
match when the gate sees the same sub as Limedoc: with Aivopod, register the
gate with subject_from limedoc (below). access.json format 1
({host: audience}) is still read; the deployer writes format 2
({host: {audience, people?}}).
Guardians. Aivopod's guardian sessions sign in only at clients flagged for
guardians; their ID token carries roles: ["aivopod:guardian"],
aivopod_guardian_of (the children's subs), the gate's login group and no
school claims. A login is a guardian's when its roles (or claimPaths) hold
guardianRole (default aivopod:guardian) or its token carries
guardianClaimPath at all (default aivopod_guardian_of; a guardian without
children there admits nowhere). The gate keeps the hashes of those subs (g in
the cookie, only the owner's), marks the cookie as a guardian's (k) and gives
guardians shorter sessions (guardianSessionHours, default 2): a site cookie
never outlives the SSO session it was issued from, so revoking a guardian link
in Aivopod acts within that time. https://auth.<domain>/family lists the live
sites of a guardian's children that admit guardians; Aivopod's guardian portal
links there. Set guardianClaimPath to "" to ignore guardian claims, and
guardianRole to "" not to look at roles.
Gate 0.2.2 signs site cookies under a new purpose: cookies of 0.2.1 and older are no longer accepted, so everyone signs in once more after the update.
/.sites-gate/logout on a site host drops its cookie; /logout on auth. ends
the SSO session. Sessions, tickets and login transactions are in memory: a
restart only means signing in again. Logs are JSON lines without IP addresses or
names (a prefix of the subject hash); the login line names no site, so the log
does not say who opened which site.
Install
-
The binary. Every release (tag
v<version>) carries the gate compiled for Linux x86_64 (amd64), its SHA-256 and the license. No Deno needed on the server:v=0.2.2 # the newest release base=https://git.belowtoxic.cloud/limedoc/limedoc-sites-gate/releases/download/v$v curl -fLO "$base/sites-gate-linux-amd64" -fLO "$base/sites-gate-linux-amd64.sha256" sha256sum -c sites-gate-linux-amd64.sha256 sudo install -m 0755 sites-gate-linux-amd64 /usr/local/bin/sites-gateOther architectures (e.g. aarch64), or building from source: with Deno 2,
deno task compile→dist/sites-gatefor the machine it runs on, or for another targetdeno compile --allow-read --allow-write --allow-net \ --allow-env=SITES_GATE_CONFIG --target aarch64-unknown-linux-gnu \ --output dist/sites-gate src/main.tsand copy it to
/usr/local/bin/sites-gate. -
One gate per target that allows sign-in protected (
oidc) sites;<domain>is the target's site domain (e.g.aivopod-sites.eu), not the IdP's or Limedoc's. Sites live on ever new subdomains and an IdP accepts no wildcard redirect URIs, so every sign-in returns to the one fixedhttps://auth.<domain>/callbackand a one-time ticket hands it to the site's host. Register the gate as its own confidential client with that redirect URI. With Aivopod 0.83 or newer and apcmd 0.19 or newer:sudo apcmd idp client add --id sites-gate-schule --label "Websites" \ --redirect-uri https://auth.aivopod-sites.eu/callback \ --school "Schule am See" --links-from limedocNo logout, back-channel or event URIs. Issuer
https://<Aivopod app host>/oidc, scopeopenid aivopod(thegroups, no names:profileis not requested),claimPaths: ["groups"], ID tokens ES256,subpairwise per client. Aivopod sends a school claimaivopod:school:<id>for every school the gate's client serves. Course and workspace claims only come for courses connected to a client:--links-from limedocmakes the courses teachers connected to Limedoc count for the gate too (schools, superadmins and events stay the gate's own). Without it the gate admits school audiences, while a course audience admits nobody (it fails closed). An existing gate client:sudo apcmd idp client links-from set --id sites-gate-schule --links-from limedoc. On Aivopod 0.82 and older there is no such option: use school audiences only.Owner, visitor and guardian rules (private sites) also need the gate to see Limedoc's subjects:
subject_from limedocon the gate's client (Aivopod 0.86.0, amendment L29:apcmd idp client subject-from set --id <gate> --subject-from limedoc, apcmd 0.20.0). Until it is set the Limedoc target leavesoidc.sameSubjectsoff, and the Sites pack offers no private sites, visitors or guardian access on it. Guardian access also needs guardians allowed on the gate's client (Aivopod 0.88.0, amendments L30–L32, apcmd 0.21.0:apcmd idp client guardians --id <gate> --portal-uri https://auth.<domain>/family); Aivopod's guardian portal then links/familyunder "Weitere Seiten" with the client's label. Each school switches guardian links on in Aivopod once its AVV covers them. -
/etc/sites-gate/<target>.json(seedeploy/config.example.json), the client secret inclientSecretFile(0640 root:sites-gate). In Limedoc (Sites pack 0.6.0 or newer) the target's form holds the gate'sissuerandclientId(section "Sign-in at the gate"; the issuer must be the same here and there, and Limedoc's ownOIDC_ISSUERfor private sites, visitors and guardians), and Connect deployer / Deployer setup on the target shows this file ready to copy with the apcmd commands. The client secret comes from the IdP (Aivopod prints it onclient add) and is never entered in Limedoc. The cookie key is created on first start (keyFile, 0600); deleting it signs everyone out. -
A user
sites-gate-<target>with primary groupsites-gate; Caddy's user insites-gate;deploy/sites-gate.tmpfiles.confas/etc/tmpfiles.d/sites-gate.conf;systemctl enable --now sites-gate@<target>(unit). -
The deployer config's
gateSocketand theauth.<domain>block of the main Caddyfile name the same socket (/run/sites-gate/<target>.sock).
Development
deno task check # fmt, lint, types
deno task test # flows against a mock OIDC provider on 127.0.0.1
deno task compile
After clone: git config core.hooksPath .githooks (fmt + lint before push).
Releasing: bump version in deno.json, merge, push the tag v<version>.
release.yml checks, tests, compiles for
Linux x86_64 and attaches the binary to the release of that tag (run it by hand
with tag to release an existing tag).