CJVT updates August and September 2026

This commit is contained in:
Luka Romih
2026-10-01 00:49:26 +02:00
parent fd02e25719
commit 83f73aeb58
135 changed files with 6146 additions and 1970 deletions
+157
View File
@@ -0,0 +1,157 @@
# Authentik — throwaway local OIDC Identity Provider
This directory holds a throwaway [Authentik](https://goauthentik.io/) instance, added to the dev
Docker Compose stack purely for **local testing of SSO/OIDC login**. It stands in for the single
real external identity federation the portal integrates with — the **University of Ljubljana**
(itself backed by Microsoft Entra ID) — which in the portal's schema is the one non-`local` value
of the `auth_provider` enum: `uni_lj`.
This is infrastructure/dev-setup only. For the bigger picture of running the portal locally, see
the main [README](../../README.md). **Wiring the express app itself up as an OIDC client against
this (or the real University of Ljubljana) is a separate, later task** — nothing here touches
`express/`.
> **Note:** This Authentik instance, its database, and every seeded user are throwaway. Nothing
> here is meant to be backed up, migrated, or taken into production.
## What's here
- `blueprints/uni-lj-stand-in.yaml` — a declarative [Authentik blueprint](https://docs.goauthentik.io/customize/blueprints/)
that, on every startup, seeds: one OIDC Provider + Application
(`Univerza v Ljubljani (test stand-in)`), two custom claim (scope) mappings restricted to the
business-relevant claims the University of Ljubljana/Entra actually sends — `email`, `name`,
`preferred_username` on the ID token, `given_name`, `family_name`, `picture` via `/userinfo`
(plus `sub`, which authentik always includes automatically) — and three test users (see below).
## Bringing it up
This is behind the `develop-idp` Docker Compose profile, so it's off by default:
docker compose --profile develop-idp up -d
(Combine with other profiles as needed, e.g. `docker compose --profile develop-idp --profile develop-concordancer up -d --build` if you're also working on the concordancer.)
First startup takes a little longer than the rest of the stack: Authentik runs its own database
migrations and then applies the blueprint in `blueprints/`. Watch it with:
docker compose logs -f authentik-server authentik-worker
> **Note:** the blueprint is re-applied automatically roughly every 60 minutes, on container
> restart, and whenever the blueprint file changes — so if you ever poke at a seeded provider,
> application, mapping, or user through the admin UI, expect your changes to be silently reverted.
> Treat that as a feature: it's the reset mechanism (see _Resetting test data_ below).
## Reaching the admin UI
Once up, the Authentik admin UI is at `http://localhost:${AUTHENTIK_LISTEN_PORT}` (default
`9000`, from the root `.env`) — e.g. `http://localhost:9000/if/admin/`.
Log in with the bootstrap admin account, created automatically on first startup from the root
`.env`:
| | value (from `.env`) |
| -------- | ------------------------------------------------------------------------ |
| Email | `AUTHENTIK_BOOTSTRAP_EMAIL` (default `admin@authentik.test`) |
| Password | `AUTHENTIK_BOOTSTRAP_PASSWORD` (default `weak_authentik_admin_password`) |
This account is Authentik's own superuser — unrelated to the portal's own
`PORTAL_ADMIN_INITIAL_EMAIL`/`PORTAL_ADMIN_INITIAL_PASSWORD` admin account, which is a completely
separate application.
## The registered test application
- **Application slug:** `uni-lj-test`
- **Redirect URI:** `http://localhost:${EXPRESS_LISTEN_PORT}/users/oidc/callback` (the portal's
planned generic OIDC callback route — provider selection is carried via session, not the URL)
- **Client ID / secret:** `AUTHENTIK_OIDC_CLIENT_ID` / `AUTHENTIK_OIDC_CLIENT_SECRET` in `.env`
(fixed, non-secret dev defaults — safe to commit, same pattern as `EXPRESS_SECRET`)
- **Scopes to request:** `openid email profile`
- **Discovery document:**
- from your host/browser: `http://localhost:${AUTHENTIK_LISTEN_PORT}/application/o/uni-lj-test/.well-known/openid-configuration`
- from inside another container on the compose network (e.g. the future express OIDC client):
`http://authentik-server:9000/application/o/uni-lj-test/.well-known/openid-configuration`
These are two different hosts on purpose: the authorization/redirect legs happen in the user's
browser (needs the `localhost` URL), while token/JWKS/userinfo calls happen server-to-server
(can use the internal `authentik-server` compose hostname). The future express-side OIDC client
task will need to account for this split.
Only one provider/application is registered, matching the single `uni_lj` value in the
portal's `auth_provider` enum — this is not meant to model multiple external IdPs.
## Test users
All seeded users share the password **`IdpTest123!`** (log in with it on Authentik's own login
page during the OIDC redirect flow — this is _not_ a portal password).
| Authentik username | Claims sent (ID token) / userinfo | Portal-side scenario it exercises |
| ------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ana.novak` | `name="Novak, Ana"`, `email=ana.novak@ff.uni-lj.si`, `preferred_username=novaka@ff.uni-lj.si` / userinfo: `given_name=Ana`, `family_name=Novak`, `picture=<Graph API constant>` | **(A) Brand new user, all claims present.** No pre-existing local account needed — log in via SSO, review the read-only data on `/users/create-profile`, and confirm to create the new portal account exactly as shown (nothing on that page is editable). |
| `berta.kolar.idp` | `name="Kolar, Berta"`, `email=berta.kolar@fri.uni-lj.si`, `preferred_username=kolarb@fri.uni-lj.si` / userinfo: `given_name=Berta`, `family_name=Kolar`, `picture=<Graph API constant>` | **(B) Email matches an existing LOCAL account → account conversion.** See below — you must register a matching local account first. Confirming with that account's password permanently overwrites its username/first/last name with the IdP data and removes its password — sign-in from then on is SSO-only. |
| `brez.imena` | `email=brez.imena@fri.uni-lj.si`, `preferred_username=brez.imena@fri.uni-lj.si` — **`given_name`/`family_name`/`name` absent** | **(C) Missing given_name/family_name claims → account creation/conversion is refused.** The claims are entirely absent from the ID token/userinfo response (not blank strings) — since there's nothing to review or persist, the portal shows a clear error and never renders a create/convert page. |
> **Note on claim placement:** the real University of Ljubljana/Entra ID token never carries
> `given_name`/`family_name`/`picture` — only the `/userinfo` endpoint does (`name` and
> `preferred_username`, by contrast, _are_ on the real ID token). Authentik has no per-field way to
> split claims between the ID token and userinfo response — a single provider-level toggle either
> includes everything in both, or restricts the ID token to bare-minimum standard fields (which
> would also strip `email`/`preferred_username`, breaking parity there). This blueprint leaves that
> toggle at its default (`include_claims_in_id_token: true`), so Authentik's ID token ends up a
> harmless superset of the real one — it also carries `given_name`/`family_name`/`picture`. This is
> intentional and documented, not a bug: the app code (`express/middleware/auth.js`) only ever reads
> `given_name`/`family_name` from the `/userinfo` response, never from ID-token claims, so the extra
> keys in Authentik's ID token are inert.
> **Note:** there is no seeded/default local user in this app's dev DB — registration is always
> manual, via the normal `/register` flow. So for scenario B, before testing SSO login as
> `berta.kolar.idp`, first manually register a local portal account with email exactly
> `berta.kolar@fri.uni-lj.si` (any other field can be anything you like), then log in via SSO as
> `berta.kolar.idp` and confirm the portal lands on `/users/convert-account`, showing that local
> account's current username alongside the (locked) IdP-derived data. Confirming with that local
> account's password converts it: username/first/last name are overwritten with the IdP data, its
> password is removed, and a subsequent local-password login attempt should fail with the usual
> "created via University of Ljubljana, no password" message.
## Troubleshooting
> **Note:** On a genuinely first-ever startup (empty `authentik-postgres-data` volume), the custom
> blueprint's very first apply attempt can race against Authentik's own built-in self-signed
> certificate being created (the blueprint's OIDC provider references that certificate as its
> signing key) — if the blueprint applies first, that one attempt fails and the provider ends up
> without a working configuration. Authentik retries blueprints roughly every 60 minutes on its
> own, but you don't need to wait: just re-apply it manually once, which always succeeds once the
> certificate exists (by then, well under a minute after startup):
>
> docker compose --profile develop-idp exec authentik-worker ak apply_blueprint /blueprints/custom/uni-lj-stand-in.yaml
>
> You can confirm whether this happened via the admin UI (System → Blueprints) or the API:
>
> curl -s -H "Authorization: Bearer ${AUTHENTIK_BOOTSTRAP_TOKEN}" \
> "http://localhost:${AUTHENTIK_LISTEN_PORT}/api/v3/managed/blueprints/?search=Ljubljana" \
> | grep -o '"status": *"[a-z]*"'
>
> A `"successful"` status means it's fine; `"error"` means run the manual re-apply above.
## Resetting test data
Because the blueprint uses `state: present`, Authentik reconciles all of the above back to these
exact values automatically (on restart, on blueprint file changes, and roughly every 60 minutes
regardless). So for most purposes, just wait or restart:
docker compose --profile develop-idp restart authentik-server authentik-worker
For a full wipe (new admin bootstrap, fresh database, blueprint re-applied from scratch):
docker compose --profile develop-idp down
docker volume rm terminoloski_portal_authentik-postgres-data terminoloski_portal_authentik-data
docker compose --profile develop-idp up -d
(Adjust the volume name prefix if your Compose project name differs from the directory name.)
## Tearing it down
docker compose --profile develop-idp down
This only stops/removes the `authentik-postgres`, `authentik-server` and `authentik-worker`
containers — it never touches the portal's own `postgres`/`express`/etc. services or data.
@@ -0,0 +1,166 @@
version: 1
metadata:
name: University of Ljubljana test stand-in - provider, application, claim mappings and test users
labels:
blueprints.goauthentik.io/description: |
Throwaway local Identity Provider setup for the Terminoloski portal's dev stack. Registers
ONE OIDC provider + application standing in for the single real University of Ljubljana/
Entra ID federation (the portal's `auth_provider` enum only ever has one external value:
'uni_lj'), whose claim set is deliberately restricted to the business-relevant fields the
University of Ljubljana actually sends: sub, email, name, preferred_username (ID token) and
given_name, family_name, picture (userinfo) - deliberately NOT Microsoft/Entra-proprietary
protocol claims (rh, aud, exp, iat, iss, nbf, oid, sid, tid, uti, ver), which app code never
reads and which authentik already has its own standard-OIDC equivalents for. authentik has
no way to split claims between the ID token and userinfo per-field, so (with
include_claims_in_id_token left at its default true) authentik's ID token ends up a harmless
superset of the real Entra one (it also carries given_name/family_name/picture) - see
dev/authentik/README.md. See dev/authentik/README.md for what each seeded test user is for.
entries:
# --- Claim (scope) mappings -------------------------------------------------------------
# authentik's own built-in "email"/"profile" scopes emit extra claims (email_verified,
# nickname, groups) that the real University of Ljubljana/Entra federation does NOT send in
# this combination. These two replace them for this provider only, so dev testing matches
# production claims exactly. (name and picture ARE now included deliberately, in real-Entra
# shape - see below - unlike authentik's own defaults, which format them differently.)
- model: authentik_providers_oauth2.scopemapping
id: uni-lj-scope-email
state: present
identifiers:
name: "Univerza v Ljubljani test mapping: email"
attrs:
name: "Univerza v Ljubljani test mapping: email"
scope_name: email
description: "Only 'email' - no email_verified (the University of Ljubljana/Entra doesn't send it either)."
expression: |
return {
"email": request.user.email,
}
- model: authentik_providers_oauth2.scopemapping
id: uni-lj-scope-profile
state: present
identifiers:
name: "Univerza v Ljubljani test mapping: profile"
attrs:
name: "Univerza v Ljubljani test mapping: profile"
scope_name: profile
description: >
given_name, family_name, name, preferred_username, picture - no nickname/groups. Mirrors
the real University of Ljubljana/Entra shape: given_name/family_name come from the user's
own attributes with NO fallback (delete_none_values() drops them entirely when unset, so a
test user can simulate the IdP omitting those claims); name is derived from those same two
attributes as "<family_name>, <given_name>" (also dropped, not just blank, when either is
missing - real Entra's ID token has no given_name/family_name at all, but DOES have name in
that exact format); preferred_username comes from a dedicated "preferred_username"
attribute (NOT request.user.username, which must stay the authentik login name) in the real
IdP's UPN-style "<lastname><first-letter-of-firstname>@<domain>" format; picture is the
fixed, non-user-specific Graph API URL every real account was observed to return.
expression: |
given_name = ak_obj_attr(request.user, "given_name")
family_name = ak_obj_attr(request.user, "family_name")
name = f"{family_name}, {given_name}" if given_name and family_name else None
return delete_none_values({
"given_name": given_name,
"family_name": family_name,
"name": name,
"preferred_username": ak_obj_attr(request.user, "preferred_username"),
"picture": "https://graph.microsoft.com/v1.0/me/photo/$value",
})
# --- Provider + Application --------------------------------------------------------------
- model: authentik_providers_oauth2.oauth2provider
id: uni-lj-provider
state: present
identifiers:
name: "Univerza v Ljubljani (test stand-in)"
attrs:
name: "Univerza v Ljubljani (test stand-in)"
authorization_flow: !Find [authentik_flows.flow, [slug, default-provider-authorization-implicit-consent]]
invalidation_flow: !Find [authentik_flows.flow, [slug, default-provider-invalidation-flow]]
client_type: confidential
client_id: !Env AUTHENTIK_OIDC_CLIENT_ID
client_secret: !Env AUTHENTIK_OIDC_CLIENT_SECRET
# Not populated by any default when created via blueprint - without it the authorization
# endpoint rejects every request with "Invalid grant_type for provider" (verified locally).
grant_types:
- authorization_code
- refresh_token
redirect_uris:
- url: !Format ["http://localhost:%s/users/oidc/callback", !Env [IDP_REDIRECT_PORT, "3000"]]
matching_mode: strict
signing_key: !Find [authentik_crypto.certificatekeypair, [name, "authentik Self-signed Certificate"]]
property_mappings:
- !Find [authentik_providers_oauth2.scopemapping, [managed, "goauthentik.io/providers/oauth2/scope-openid"]]
- !KeyOf uni-lj-scope-email
- !KeyOf uni-lj-scope-profile
- model: authentik_core.application
id: uni-lj-application
state: present
identifiers:
slug: uni-lj-test
attrs:
name: "Univerza v Ljubljani (test stand-in)"
slug: uni-lj-test
provider: !KeyOf uni-lj-provider
policy_engine_mode: any
meta_description: >
Throwaway local test application standing in for the single real University of Ljubljana
OIDC federation. Not a real IdP - dev/testing use only.
# --- Test users --------------------------------------------------------------------------
# All seeded users share the same fixed password so a tester can log in without hunting for
# per-user credentials. See dev/authentik/README.md for what portal-side scenario each covers,
# and for the exact local-account value scenario B requires you to register first.
# (A) Brand new user via IdP only, every claim present.
- model: authentik_core.user
id: uni-lj-user-full
state: present
identifiers:
username: ana.novak
attrs:
name: "Ana Novak"
email: ana.novak@ff.uni-lj.si
is_active: true
attributes:
given_name: Ana
family_name: Novak
preferred_username: novaka@ff.uni-lj.si
password: "IdpTest123!"
# (B) email claim matches a pre-existing LOCAL portal account -> account-conversion test.
- model: authentik_core.user
id: uni-lj-user-email-match
state: present
identifiers:
username: berta.kolar.idp
attrs:
name: "Berta Kolar"
email: berta.kolar@fri.uni-lj.si
is_active: true
attributes:
given_name: Berta
family_name: Kolar
preferred_username: kolarb@fri.uni-lj.si
password: "IdpTest123!"
# (C) given_name/family_name attributes deliberately left unset -> those claims (and the derived
# `name`) are entirely absent from the ID token/userinfo response (not blank strings) -> the
# portal refuses to create/convert an account without a name (nothing to review or persist),
# with a clear error message rather than a blank editable form. No real first/last name
# exists to build a proper email/preferred_username from, so both deliberately reuse the same
# "brez.imena" placeholder local-part (only the domain suffix is updated for consistency).
- model: authentik_core.user
id: uni-lj-user-missing-name
state: present
identifiers:
username: brez.imena
attrs:
name: "Brez imena (missing given_name/family_name claims)"
email: brez.imena@fri.uni-lj.si
is_active: true
attributes:
preferred_username: brez.imena@fri.uni-lj.si
password: "IdpTest123!"