Gate for limedoc based static sites
  • TypeScript 97.7%
  • Shell 2.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-12-02 01:55:20 +01:00
.forgejo/workflows Release: take the release script from the workflow's commit, so an older tag can be released by hand. 2026-11-29 21:05:15 +01:00
.githooks Sites gate 0.1.0: OIDC login for protected sites of one target. 2026-11-20 11:28:28 +01:00
deploy A guardian gets in by the guardian rule alone; no site cookie outlives its SSO session. Release 0.2.2. 2026-11-25 09:40:39 +01:00
scripts Release the gate compiled for Linux x86_64 with each tag; README installs it by default. 2026-11-29 21:00:23 +01:00
src A guardian gets in by the guardian rule alone; no site cookie outlives its SSO session. Release 0.2.2. 2026-11-25 09:40:39 +01:00
tests A guardian gets in by the guardian rule alone; no site cookie outlives its SSO session. Release 0.2.2. 2026-11-25 09:40:39 +01:00
.gitignore Initial commit: license. 2026-11-20 11:28:27 +01:00
deno.json Release the gate compiled for Linux x86_64 with each tag; README installs it by default. 2026-11-29 21:00:23 +01:00
deno.lock Sites gate 0.1.0: OIDC login for protected sites of one target. 2026-11-20 11:28:28 +01:00
LICENSE.md Initial commit: license. 2026-11-20 11:28:27 +01:00
README.md README: where issuer and clientId come from in Limedoc (Sites 0.6.0 target form, Connect deployer shows the gate config); the client secret stays in clientSecretFile. 2026-12-02 01:38:02 +01:00

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

  1. Caddy (forward_auth, snippet gate in the deployer's main Caddyfile) asks GET /verify?site=<host>. A valid __Host-sg cookie for exactly this host whose claims satisfy the site's audience → 200, the page is served.
  2. Otherwise the gate answers 302 to https://auth.<domain>/login?return=https://<host><path>&n=<nonce> and sets the nonce as __Host-sgn on the site host. A signed-in visitor whose account does not qualify gets a 403 page with "sign in with another account" instead.
  3. /login on auth.<domain> accepts only https://<host> returns whose host is listed in the deployer's access.json (no port, no user info: no open redirect). With an SSO session (__Host-sga on auth.) it skips the IdP; otherwise authorization code + PKCE (S256) with state bound to a __Host-sgtx cookie and an ID token nonce.
  4. /callback checks 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.
  5. 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-sgn nonce 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):

  1. an audience claim matches: {school: […]}, {course: […]}, {private: […]} (the teacher claims of the site's space) or {authenticated: true};
  2. the visitor is the site's owner;
  3. 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);
  4. 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-gate
    

    Other architectures (e.g. aarch64), or building from source: with Deno 2, deno task compile → dist/sites-gate for the machine it runs on, or for another target

    deno compile --allow-read --allow-write --allow-net \
      --allow-env=SITES_GATE_CONFIG --target aarch64-unknown-linux-gnu \
      --output dist/sites-gate src/main.ts
    

    and 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 fixed https://auth.<domain>/callback and 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 limedoc
    

    No logout, back-channel or event URIs. Issuer https://<Aivopod app host>/oidc, scope openid aivopod (the groups, no names: profile is not requested), claimPaths: ["groups"], ID tokens ES256, sub pairwise per client. Aivopod sends a school claim aivopod:school:<id> for every school the gate's client serves. Course and workspace claims only come for courses connected to a client: --links-from limedoc makes 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 limedoc on 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 leaves oidc.sameSubjects off, 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 /family under "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 (see deploy/config.example.json), the client secret in clientSecretFile (0640 root:sites-gate). In Limedoc (Sites pack 0.6.0 or newer) the target's form holds the gate's issuer and clientId (section "Sign-in at the gate"; the issuer must be the same here and there, and Limedoc's own OIDC_ISSUER for 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 on client 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 group sites-gate; Caddy's user in sites-gate; deploy/sites-gate.tmpfiles.conf as /etc/tmpfiles.d/sites-gate.conf; systemctl enable --now sites-gate@<target> (unit).

  • The deployer config's gateSocket and the auth.<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).