From 5a2e612faa1d8c1a5d246fed3245f486de5c0803 Mon Sep 17 00:00:00 2001 From: Sajeyks Date: Wed, 11 Nov 2026 21:36:51 +0300 Subject: [PATCH] Replace env.sample with a shorter .env.example It opens with the five required variables, then what production usually sets (proxy header, PostgreSQL, mail relay, OTP), then every optional setting commented out at its default. It lists exactly the 51 variables the code reads. --- .env.example | 100 +++++++++++++++++++++++++++++++++ README.md | 2 +- dal/settings.py | 5 +- deploy/k8s/README.md | 2 +- deploy/k8s/base/configmap.yaml | 2 +- env.sample | 72 ------------------------ 6 files changed, 106 insertions(+), 77 deletions(-) create mode 100644 .env.example delete mode 100644 env.sample diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..a61c190 --- /dev/null +++ b/.env.example @@ -0,0 +1,100 @@ +# Environment for the ungleich account webapp (account.ungleich.ch). +# +# Copy to .env for `docker compose` / `docker run --env-file`, or use it as +# the list of variables to inject in Kubernetes. docker.md explains each one. +# Values marked [secret] belong in a Secret, not a ConfigMap. + + +# --------------------------------------------------------------------------- +# Required (the app refuses to start without these) +# --------------------------------------------------------------------------- + +# [secret] Long random string. Generate one with: +# python3 -c 'import secrets; print(secrets.token_urlsafe(50))' +SECRET_KEY= + +# LDAP server(s), space separated. The first reachable one is used. +LDAPSERVER="ldaps://ldap1.ungleich.ch ldaps://ldap2.ungleich.ch" + +# Account that searches the directory and creates/changes customers. +LDAP_ADMIN_DN= +LDAP_ADMIN_PASSWORD= # [secret] + +# Sender address of activation and password-reset emails. +EMAIL_FROM_ADDRESS= + + +# --------------------------------------------------------------------------- +# Usually set in production +# --------------------------------------------------------------------------- + +# Behind an HTTPS ingress/proxy that sets X-Forwarded-Proto. Makes links in +# emails use https:// and lets Django know requests were secure. +TRUST_X_FORWARDED_PROTO=True + +# PostgreSQL. Required for more than one replica; without DATABASE_HOST the +# app uses SQLite at SQLITE_PATH (one replica, on a persistent volume). +#DATABASE_HOST= +#DATABASE_PORT=5432 +#DATABASE_NAME=ungleich_user +#DATABASE_USER=ungleich_user +#DATABASE_PASSWORD= # [secret] +#DATABASE_SSLMODE=prefer + +# Mail relay (defaults: localhost:25 with STARTTLS). +#EMAIL_HOST=localhost +#EMAIL_PORT=25 +#EMAIL_USE_TLS=True +#EMAIL_HOST_USER= +#EMAIL_HOST_PASSWORD= # [secret] + +# OTP server. Optional: without OTPSERVER new accounts get no OTP seed. +# If OTPSERVER is set, the four variables after it are required too. +#OTPSERVER= +#ADMIN_SEED= # [secret] base32 TOTP seed of ADMIN_NAME +#ADMIN_NAME= +#ADMIN_REALM= +#USER_REALM= # realm for seeds of new users +#ALLOWED_REALMS= # comma separated realms users may request + + +# --------------------------------------------------------------------------- +# Optional, with production defaults (only set to change them) +# --------------------------------------------------------------------------- + +#ALLOWED_HOSTS=account.ungleich.ch # comma separated +#CSRF_TRUSTED_ORIGINS=https://account.ungleich.ch # default: https:// + each allowed host + +# Directory layout. A different tree usually only needs ENTIRE_SEARCH_BASE. +#ENTIRE_SEARCH_BASE=dc=ungleich,dc=ch +#LDAP_CUSTOMER_DN=ou=customer,dc=ungleich,dc=ch # where registrations go +#LDAPSEARCH="ou=customer,dc=ungleich,dc=ch ou=users,dc=ungleich,dc=ch" # where logins are found +#LDAP_CUSTOMER_GROUP_ID=10004 +#LDAP_DEFAULT_START_UID=10000 +#LDAP_USER_OBJECT_CLASSES="inetOrgPerson posixAccount ldapPublicKey" # drop ldapPublicKey without the openssh-lpk schema + +# LDAP TLS +#LDAP_USE_TLS=False # StartTLS, for ldap:// URIs only +#LDAP_TLS_VERIFY=True # verify server certificates +#LDAP_CA_FILE= # CA bundle for a private CA; default: system trust store + +# Security headers +#SESSION_COOKIE_SECURE=True # default: True unless DEBUG +#CSRF_COOKIE_SECURE=True +#SECURE_SSL_REDIRECT=False # usually the ingress redirects to HTTPS +#SECURE_HSTS_SECONDS=0 + +# Runtime +#DEBUG=False +#LOG_LEVEL=INFO +#DJANGO_LOG_LEVEL=INFO +#LDAP3_LOG=False # very verbose ldap3 protocol logging +#SQLITE_PATH=/data/db.sqlite3 +#DATABASE_CONN_MAX_AGE=60 +#EMAIL_TIMEOUT=10 +#OTP_TIMEOUT=10 +#STATIC_ROOT=/app/static +#GUNICORN_WORKERS=2 +#GUNICORN_THREADS=4 +#GUNICORN_TIMEOUT=60 +#GUNICORN_BIND=[::]:8000 diff --git a/README.md b/README.md index 9d3e765..6617f09 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ DATABASE_PASSWORD=dev-only` to run them on PostgreSQL instead of SQLite. ## 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 +[`.env.example`](.env.example) lists each one, with its default and whether it is a secret. ## Deployment diff --git a/dal/settings.py b/dal/settings.py index 3788bfa..c5d7176 100644 --- a/dal/settings.py +++ b/dal/settings.py @@ -2,8 +2,9 @@ Django settings for the ungleich account webapp (dal). All deployment-specific values come from environment variables (or a -.env file in development), read here and nowhere else. See env.sample -for the full list, which ones are required, and which are secrets. +.env file in development), read here and nowhere else. See .env.example +and docker.md for the full list, which ones are required, and which are +secrets. """ import os diff --git a/deploy/k8s/README.md b/deploy/k8s/README.md index b9709e6..0c9a247 100644 --- a/deploy/k8s/README.md +++ b/deploy/k8s/README.md @@ -25,7 +25,7 @@ Ingress, PodDisruptionBudget and ConfigMap. Apply it with 2. Copy `base/` into your environment's overlay (or edit it in place) and set: - `images:` in `kustomization.yaml`: the registry and a pinned tag - - `configmap.yaml`: every value marked `REQUIRED` (`env.sample` lists + - `configmap.yaml`: every value marked `REQUIRED` (`.env.example` lists all settings with their defaults) - `ingress.yaml`: the ingress class and the TLS secret or cert-manager annotations diff --git a/deploy/k8s/base/configmap.yaml b/deploy/k8s/base/configmap.yaml index 1b2d028..dee8b08 100644 --- a/deploy/k8s/base/configmap.yaml +++ b/deploy/k8s/base/configmap.yaml @@ -1,4 +1,4 @@ -# Non-secret settings. See env.sample for every variable and its default. +# Non-secret settings. See .env.example and docker.md for every variable. apiVersion: v1 kind: ConfigMap metadata: diff --git a/env.sample b/env.sample deleted file mode 100644 index 45093e4..0000000 --- a/env.sample +++ /dev/null @@ -1,72 +0,0 @@ -# Configuration for the ungleich account webapp. -# -# Every setting is an environment variable. In development, copy this file -# (or dev/env.dev) to .env in the repository root. In Kubernetes, values -# marked [secret] go in a Secret and the rest in a ConfigMap. -# -# Required unless a default is shown. - -# --- Django ----------------------------------------------------------------- -SECRET_KEY="" # [secret] long random string -ALLOWED_HOSTS="account.ungleich.ch" # comma separated -DEBUG=False -LOG_LEVEL=INFO # root log level; output goes to stdout -#DJANGO_LOG_LEVEL=INFO -#LDAP3_LOG=False # ldap3 protocol logging (very verbose) - -# --- HTTPS / proxy ------------------------------------------------------------ -#TRUST_X_FORWARDED_PROTO=False # True behind a TLS-terminating ingress -#CSRF_TRUSTED_ORIGINS="" # comma separated, e.g. https://account.ungleich.ch -#SESSION_COOKIE_SECURE= # default: True unless DEBUG -#CSRF_COOKIE_SECURE= # default: True unless DEBUG -#SECURE_SSL_REDIRECT=False # usually done by the ingress -#SECURE_HSTS_SECONDS=0 # read Django's HSTS docs before raising - -# --- Database ----------------------------------------------------------------- -# Sessions, reset tokens and pending registrations. Set DATABASE_HOST to use -# PostgreSQL (required for more than one replica); otherwise SQLite is used. -#DATABASE_HOST="" -#DATABASE_PORT=5432 -#DATABASE_NAME=ungleich_user -#DATABASE_USER=ungleich_user -#DATABASE_PASSWORD="" # [secret] -#DATABASE_SSLMODE=prefer -#DATABASE_CONN_MAX_AGE=60 -#SQLITE_PATH=./db.sqlite3 # only without DATABASE_HOST - -# --- LDAP ------------------------------------------------------------------- -# Space separated; the first reachable server is used (failover). -LDAPSERVER="ldaps://ldap1.ungleich.ch ldaps://ldap2.ungleich.ch" -#LDAP_USE_TLS=False # StartTLS on every connection (not with ldaps://) -#LDAP_TLS_VERIFY=True # verify server certificates (ldaps:// and StartTLS) -#LDAP_CA_FILE="" # CA bundle for a private CA; default: system store -LDAP_ADMIN_DN="" # DN with write access to customers -LDAP_ADMIN_PASSWORD="" # [secret] - -# Users log in from any of these (space separated) search bases. -LDAPSEARCH="ou=customer,dc=ungleich,dc=ch ou=users,dc=ungleich,dc=ch" -# Usernames and uidNumbers must be unique below this base. -ENTIRE_SEARCH_BASE="dc=ungleich,dc=ch" -# New registrations are created here. -LDAP_CUSTOMER_DN="ou=customer,dc=ungleich,dc=ch" -LDAP_CUSTOMER_GROUP_ID=10004 # gidNumber for new customers (production: 10004) -LDAP_DEFAULT_START_UID=10000 # new uidNumbers are always above this -#LDAP_USER_OBJECT_CLASSES="inetOrgPerson posixAccount ldapPublicKey" # ldapPublicKey needs openssh-lpk - -# --- Email ------------------------------------------------------------------ -EMAIL_FROM_ADDRESS="" -#EMAIL_HOST=localhost -#EMAIL_PORT=25 -#EMAIL_USE_TLS=True -#EMAIL_HOST_USER="" -#EMAIL_HOST_PASSWORD="" # [secret] -#EMAIL_TIMEOUT=10 - -# --- OTP server ------------------------------------------------------------- -OTPSERVER="" # base URL of the OTP API -ADMIN_NAME="" -ADMIN_REALM="" -ADMIN_SEED="" # [secret] base32 TOTP seed of ADMIN_NAME -USER_REALM="" # realm for seeds of new users -ALLOWED_REALMS="" # comma separated realms users may request -#OTP_TIMEOUT=10 # seconds per request to the OTP server