diff --git a/README.md b/README.md index 0a1cb2d..f371e36 100644 --- a/README.md +++ b/README.md @@ -1,83 +1,65 @@ -# Ungleich Account Management Webapp +# ungleich account webapp -This service runs on [account.ungleich.ch](https://account.ungleich.ch/) and -allows customers manage their ungleich account (register, edit mail & password, -...). +This service runs on [account.ungleich.ch](https://account.ungleich.ch/). +Customers use it to manage their ungleich LDAP account: register (with +email confirmation), log in, change their name, email or password, reset a +forgotten password, delete the account, and view their OTP seeds. It also +offers a small API for creating accounts and fetching OTP seeds. -## Status v2 +Django 6.1 on Python 3.15. LDAP access goes through +[ldap3](https://ldap3.readthedocs.io/) only, with no C extensions. -* See below ungleichuser/ -* register view created -* Not solved: - * email verification *before* user is created -* Solved - * Finding highest uid, increasing by 1 +## Development -## Todos for v2: - -* Rewrite/create new app Django 4.0 based (ungleichuser) -* Do not use django-auth-ldap, because it uses python-ldap -* Update the template HTML to bootstrap5 -* Use ldap3 -* Check/verify the ldap registration -* Ensure multiple ldap servers are supported -* Cleanup this readme -* Use the following "captcha" for all forms: - * Extra form field named "random" - * Present the user the following text: -* Create Dockerfile / ensure it works in kubernetes - -## Next steps - -* Override/use custom form to allow captcha - -## Development Setup +You need Docker and [uv](https://docs.astral.sh/uv/) (or any Python 3.15). +Only LDAP (and optionally PostgreSQL) runs in containers. The app runs +natively. +```sh +docker compose -f docker-compose.dev.yml up -d --build # OpenLDAP 2.6 on :3389, PostgreSQL on :5433 +cp dev/env.dev .env # dev-only settings +uv venv -p 3.15 .venv && uv pip install -r requirements.txt +.venv/bin/python manage.py migrate +.venv/bin/python manage.py runserver ``` -python3 -m venv venv -. ./venv/bin/activate -pip install -r requirements.txt -`` -## Functionality +The test LDAP mirrors the production layout (`dc=ungleich,dc=ch`, +`ou=customers`, `ou=users`) and comes with `customer1` / `customerpass` +and `staff1` / `staffpass`. To reset its data: +`docker compose -f docker-compose.dev.yml up -d --force-recreate ldap`. -x Allow user to register in a specific subtree -x Verify that user does not exist in another subtree -x Assign an id -- Allow password reset [via Mail?] -- DB usage: for password reset? +### Tests -## Parameters +```sh +.venv/bin/python manage.py test dal +``` -Via environment variables: +The tests in `dal/tests/` exercise every view over HTTP against the real +test LDAP server, which must be running. Mail and the OTP server are +mocked. Set `DATABASE_HOST=localhost DATABASE_PORT=5433 +DATABASE_PASSWORD=dev-only` to run them on PostgreSQL instead of SQLite. -* LDAPSERVERS=".." -- White space separated list of LDAP-Servers -* ADMIN_DN="" -- we use this DN to connect to LDAP -* ADMIN_PASSWORD="" -- we use this password to connect to LDAP -* SECRET_KEY -* DEBUG -* ALLOWED_HOSTS +## Configuration +Every setting is an environment variable (a `.env` file in development). +[`env.sample`](env.sample) lists each one, with its default and whether it +is a secret. -## Views +## Deployment -### Register view +The [`Dockerfile`](Dockerfile) builds a production image: gunicorn running +as non-root, static files served by WhiteNoise, and logs on stdout. To +deploy on Kubernetes, and to test locally with kind, see +[`deploy/k8s/README.md`](deploy/k8s/README.md). -Form: [get] +## Layout -* username -* password1 -* password2 - -Post receiver: [post] - -* E-Mail verification - -E-Mail verify: [get] - -* Create user - -### Password reset view - -* captcha -* username or email +| Path | Contents | +| --- | --- | +| `dal/views.py` | All views | +| `dal/ungleich_ldap.py` | LDAP writes and searches (`LdapManager`, server pool) | +| `dal/backends.py` | LDAP login backend | +| `dal/health.py` | `/healthz` and `/readyz` | +| `dal/tests/` | End-to-end tests | +| `dev/` | Dev settings and the test OpenLDAP image | +| `deploy/k8s/` | Kubernetes manifests (base and kind dev overlay) |