Skip to content

Fix #36: Add Authelia as core IAM service for shards#86

Open
ClaydeCode wants to merge 1 commit into
mainfrom
clayde/issue-36-authelia-yaml-backend
Open

Fix #36: Add Authelia as core IAM service for shards#86
ClaydeCode wants to merge 1 commit into
mainfrom
clayde/issue-36-authelia-yaml-backend

Conversation

@ClaydeCode
Copy link
Copy Markdown
Contributor

Summary

Closes #36

Adds Authelia as a permanent core IAM service in every shard, providing single-sign-on across all apps via forward-auth and OIDC, with a file-based user backend that hot-reloads without container restarts.

  • Authelia service (authelia/authelia:4.38) added to docker-compose.yml, mounting ${FREESHARD_DIR}/core/authelia as /config
  • Jinja2 config templates (data/authelia/) rendered at startup: configuration.yml (session, storage, OIDC, file-backend with watch: true) and an initial empty users_database.yml
  • Secrets bootstrap via shard_core/service/authelia.py: JWT secret, session secret, storage encryption key, OIDC HMAC secret, and RSA-4096 OIDC private key are generated once and persisted in the kv_store; the config is re-rendered on every startup so it stays in sync with the shard domain
  • Argon2id password hashing (OWASP best practice, Authelia's native format) for all user passwords — plain-text passwords never touch disk
  • User management REST API at GET|POST /protected/authelia/users and GET|PATCH|DELETE /protected/authelia/users/{username} — writes atomically via temp-file-then-rename, protected by a threading lock
  • Traefik integration: authelia-forwardauth middleware added (calls http://authelia:9091/api/authz/forward-auth), app routers switched from the old internal auth middleware to authelia-forwardauth, and a public router added for auth.<shard-domain> so the Authelia login portal is reachable

Recommended reading order

  1. data/authelia/configuration.yml.j2 — the Authelia config template (single source of truth for what Authelia does)
  2. shard_core/service/authelia.py — secrets management, config rendering, user CRUD, password hashing
  3. shard_core/service/traefik_dynamic_config.py — Traefik middleware/service/router additions
  4. shard_core/app_factory.py — two new lines wiring Authelia into the startup lifespan
  5. shard_core/web/protected/authelia_users.py + shard_core/web/protected/__init__.py — the REST API layer
  6. tests/test_authelia_users.py + tests/test_traefik_dyn_spec.py — tests

Test plan

  • Service-layer CRUD tests (test_authelia_users.py): create, get, list, update, delete, duplicate-create raises 409, delete-missing raises 404
  • Password hashing: PHC format verified, different salts per call
  • API endpoint tests via app_client (no Traefik, auth bypassed at FastAPI level): all CRUD operations return correct status codes
  • Traefik spec test (test_traefik_dyn_spec.py): authelia-forwardauth middleware, authelia service and router are present; app routers now use authelia-forwardauth
  • Manual: start stack, check auth.<shard-domain> serves Authelia login portal; create user via API, verify Authelia accepts credentials

🤖 Generated with Claude Code

Authelia is added as a permanent core service in every shard, providing
forward-auth (via Traefik middleware) and OIDC (for OAuth clients) with
a file-based user backend that hot-reloads on change.

Key changes:
- docker-compose.yml: Add authelia/authelia:4.38 service, mounting
  ${FREESHARD_DIR}/core/authelia as /config
- data/authelia/: Jinja2 templates for configuration.yml and the
  initial users_database.yml rendered at shard startup
- shard_core/service/authelia.py: Secrets bootstrap (stored in kv_store,
  generated once), config rendering, and CRUD service layer for the YAML
  user database with argon2id password hashing
- shard_core/web/protected/authelia_users.py: REST endpoints at
  /protected/authelia/users (list, get, create, update, delete)
- shard_core/service/traefik_dynamic_config.py: Add authelia-forwardauth
  middleware (http://authelia:9091/api/authz/forward-auth), authelia
  service, and auth.<shard-domain> public router; switch app routers
  from the old auth middleware to authelia-forwardauth
- shard_core/app_factory.py: Call ensure_authelia_secrets and
  render_authelia_config during startup lifespan
- tests/: Update traefik dyn spec test, add authelia user CRUD tests

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Enhanced Support for Lightweight Multi-Instance Deployments ("Sharding") via Dynamic YAML Backends

1 participant