Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
API: the first profile on an empty instance becomes its admin, FIRST_USER_ADMIN=0 turns it off (#328)
Duarte Santos1dd825e04cf2
diff --git a/.env.example b/.env.exampleindex 6e7cf5569..fab0f2234 100644--- a/.env.example+++ b/.env.example@@ -20,17 +20,28 @@ RP_NAME=openGym# (Point your proxy at the web container's WEB_PORT. See docs/SELF_HOSTING.md.)# ── Admin dashboard & invite-only signup (optional) ────────────────────────-# Both off by default — a fresh instance has open signup and no admin.+# A fresh instance has open signup, and the FIRST profile created on it becomes+# its admin. Admins get an "Admin dashboard" link in Settings to see users,+# disable accounts, generate invite codes and view workout history.#-# Make yourself an admin: register your own passkey profile first, find your-# user id in ./data/db.json ("users"[].id), then list it here (comma-separated-# for several admins). Admins get an "Admin dashboard" link in Settings to see-# users, disable accounts, generate invite codes and view workout history.+# "First" means: the instance had no profiles at all when it registered. An+# instance that already has profiles promotes nobody when you upgrade, and an+# instance whose profiles were all deleted counts as fresh again. Register your+# own profile before you share the address. To turn it off:+#+# FIRST_USER_ADMIN=0+#+# More admins, or admins on an instance that existed before this setting: find+# the user id in Settings -> Account -> Account ID (or ./data/db.json,+# "users"[].id) and list it here, comma-separated. A first-user admin is marked+# "admin": true on its entry in ./data/db.json; delete that line to undo it.## ADMIN_UIDS=youruserid,anotheradmin## Require an invite code to create new profiles (existing accounts keep working;-# generate the codes from the admin dashboard):+# generate the codes from the admin dashboard). Create your own profile first:+# with no profiles and no admin yet, nobody could generate the first code.+### INVITE_ONLY=1#diff --git a/README.md b/README.mdindex 0a7fd8872..1986d083d 100644--- a/README.md+++ b/README.md@@ -150,6 +150,7 @@ Traefik and nginx, and there are separate guides for| `RP_NAME` | Name shown in the passkey prompt | `openGym` || `SESSION_DAYS` | How long a sign-in lasts, in days | `90` || `ADMIN_UIDS` | User ids that get the admin dashboard, comma-separated | *(none)* |+| `FIRST_USER_ADMIN` | The first profile created on an empty instance becomes its admin; `0` turns it off | *(on)* || `INVITE_ONLY` | Require an invite code to create a profile | *(off)* || `ALLOW_GUEST` | Offer "Continue without account"; `0` requires a profile | *(on)* || `PASSWORD_LOGIN` | Offer name-and-password sign-in next to passkeys | *(off)* |diff --git a/api/openapi.yaml b/api/openapi.yamlindex f9c64b0a8..84251fb48 100644--- a/api/openapi.yaml+++ b/api/openapi.yaml@@ -75,6 +75,9 @@ info:this API at all).- `ADMIN_UIDS=<uid>,<uid>` — user ids treated as admins (a `"admin": true` flag onthe user record in `db.json` works too). Admins get the `/api/admin/*` routes.+ - `FIRST_USER_ADMIN` (default on; `0` turns it off) — the first profile registered+ on an instance with no profiles gets that `"admin": true` flag. Decided at+ registration only, never applied to an instance that already has profiles.- `AUDIT_LOG` (default on), `AUDIT_MAX` (default 5000 events), `AUDIT_DAYS`(default 90), `AUDIT_IP` (`off` | `net` | `full`, default off) — shape the auditlog served by `GET /api/admin/audit`.diff --git a/api/server.js b/api/server.jsindex debdd4840..98e0a43db 100644--- a/api/server.js+++ b/api/server.js@@ -37,10 +37,24 @@ const DATA = process.env.DATA_DIR || '/data';const RP_ID = process.env.RP_ID || 'localhost';const ORIGIN = process.env.ORIGIN || 'http://localhost:8080';const RP_NAME = process.env.RP_NAME || 'openGym';-// Admin dashboard (issue): admins are matched by uid; INVITE_ONLY gates new signups behind a-// code the admin generates. Both default off so a fresh self-hosted instance stays open.+// Admin dashboard (issue): admins are matched by uid (or the admin flag FIRST_USER_ADMIN sets);+// INVITE_ONLY gates new signups behind a code the admin generates. Off by default, so a fresh+// self-hosted instance stays open.const ADMIN_UIDS = (process.env.ADMIN_UIDS || '').split(',').map(s => s.trim()).filter(Boolean);const INVITE_ONLY = /^(1|true|yes|on)$/i.test(process.env.INVITE_ONLY || '');+// The first profile made on an instance with no profiles at all becomes its admin (#328), so a+// fresh install has someone who can open the admin dashboard without editing ADMIN_UIDS and+// restarting. Stored on the user record (user.admin), which isAdmin already honours. It is+// decided at the moment of registration only: an instance that already has profiles changes+// nothing on upgrade. Default ON; FIRST_USER_ADMIN=0 turns it off.+const FIRST_USER_ADMIN = !/^(0|false|no|off)$/i.test(process.env.FIRST_USER_ADMIN || '');+// Checked synchronously right before db.users.push, with no await in between, so two+// registrations racing each other cannot both see an empty instance.+function claimFirstAdmin(req, user) {+ if (!FIRST_USER_ADMIN || db.users.length !== 0) return;+ user.admin = true;+ audit(req, 'admin.first-user', { user });+}// Guest mode ("Continue without account") keeps everything in the browser and never touches this// server — but on an instance meant for a known set of people, an entrance nobody can walk back// out of is still the wrong front door (#42). Default ON, so existing instances are unchanged;@@ -1181,6 +1195,7 @@ const passwordRoutes = {const created = new Date().toISOString();const user = { id: crypto.randomBytes(12).toString('base64url'), name, created, pw: { h, set: created }, ...(email ? { email } : {}) };if (inv) { user.invitedBy = inv.code; inv.usedBy = user.id; inv.usedAt = created; }+ claimFirstAdmin(req, user);db.users.push(user);saveDb();audit(req, 'auth.register.ok', { user, msg: inv ? inv.code + ' · password' : 'password' });@@ -1842,6 +1857,7 @@ const routes = {}const user = { id: c.uid, name: c.name, created: new Date().toISOString() };if (invite) { user.invitedBy = invite.code; invite.usedBy = user.id; invite.usedAt = user.created; }+ claimFirstAdmin(req, user);db.users.push(user);db.creds.push({id: credential.id, userId: user.id,diff --git a/api/test/server-first-user-admin.test.js b/api/test/server-first-user-admin.test.jsnew file mode 100644index 000000000..988604818--- /dev/null+++ b/api/test/server-first-user-admin.test.js@@ -0,0 +1,182 @@+/* FIRST_USER_ADMIN (#328): the first profile made on an instance with no profiles becomes its+ admin, through either way of registering. Never retroactive — an instance that already has+ profiles changes nothing — and FIRST_USER_ADMIN=0 turns it off. Real server.js in a child, the+ same harness as server-passkeys.test.js. */+import { test, before } from 'node:test';+import assert from 'node:assert/strict';+import crypto from 'node:crypto';+import fs from 'node:fs';+import os from 'node:os';+import path from 'node:path';+import { spawn } from 'node:child_process';+import { fileURLToPath } from 'node:url';+import { hashPassword } from '../password.js';+import { boundPort } from './helpers.mjs';++const API = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');+const SECRET = crypto.randomBytes(32).toString('hex');+const ORIGIN = 'http://localhost:8080';+const b64u = b => Buffer.from(b).toString('base64url');+const sha = b => crypto.createHash('sha256').update(b).digest();++const mintSession = (uid, sv = 0) => {+ const payload = `${uid}:${Date.now() + 86400000}:${sv}`;+ return 'gymsid=' + payload + '.' + crypto.createHmac('sha256', SECRET).update(payload).digest('base64url');+};++// Just enough CBOR for an attestation object: a map of text keys to text, bytes or an empty map.+const cborHead = (major, n) => n < 24 ? Buffer.from([(major << 5) | n])+ : n < 256 ? Buffer.from([(major << 5) | 24, n]) : Buffer.from([(major << 5) | 25, n >> 8, n & 255]);+const cborText = s => Buffer.concat([cborHead(3, Buffer.byteLength(s)), Buffer.from(s)]);+const cborBytes = b => Buffer.concat([cborHead(2, b.length), b]);++function softPasskey() {+ const { privateKey, publicKey } = crypto.generateKeyPairSync('ec', { namedCurve: 'P-256' });+ const jwk = publicKey.export({ format: 'jwk' });+ const cose = Buffer.concat([+ Buffer.from([0xa5, 0x01, 0x02, 0x03, 0x26, 0x20, 0x01, 0x21, 0x58, 0x20]), Buffer.from(jwk.x, 'base64url'),+ Buffer.from([0x22, 0x58, 0x20]), Buffer.from(jwk.y, 'base64url')+ ]);+ const raw = crypto.randomBytes(16);+ const id = b64u(raw);+ let counter = 0;+ return {+ id,+ row: (userId, extra = {}) => ({ id, userId, publicKey: cose.toString('base64url'), counter: 0, transports: ['internal'], ...extra }),+ // What navigator.credentials.create() hands back, serialised the way lib/api.js does.+ attestation(challenge, { origin = ORIGIN } = {}) {+ const clientDataJSON = Buffer.from(JSON.stringify({ type: 'webauthn.create', challenge, origin, crossOrigin: false }));+ const len = Buffer.from([raw.length >> 8, raw.length & 255]);+ const authData = Buffer.concat([sha('localhost'), Buffer.from([0x45]), Buffer.alloc(4), Buffer.alloc(16), len, raw, cose]);+ const attestationObject = Buffer.concat([+ Buffer.from([0xa3]), cborText('fmt'), cborText('none'), cborText('attStmt'), Buffer.from([0xa0]),+ cborText('authData'), cborBytes(authData)+ ]);+ return {+ id, rawId: id, type: 'public-key', clientExtensionResults: {}, authenticatorAttachment: 'platform',+ response: { clientDataJSON: b64u(clientDataJSON), attestationObject: b64u(attestationObject), transports: ['internal', 'hybrid'] }+ };+ },+ assertion(challenge) {+ const clientDataJSON = Buffer.from(JSON.stringify({ type: 'webauthn.get', challenge, origin: ORIGIN, crossOrigin: false }));+ const c = Buffer.alloc(4); c.writeUInt32BE(++counter);+ const authData = Buffer.concat([sha('localhost'), Buffer.from([0x05]), c]);+ const signature = crypto.sign('sha256', Buffer.concat([authData, sha(clientDataJSON)]), privateKey);+ return {+ id, rawId: id, type: 'public-key', clientExtensionResults: {}, authenticatorAttachment: 'platform',+ response: { clientDataJSON: b64u(clientDataJSON), authenticatorData: b64u(authData), signature: b64u(signature), userHandle: null }+ };+ }+ };+}++const GOOD = 'correct horse battery staple';+let pwHash;+// Made before any test runs: withPassword() reads it while a test's arguments to startServer are+// still being built, so a test run on its own would otherwise give its user no hash at all.+before(async () => { pwHash ??= await hashPassword(GOOD); });++async function startServer(t, { env = {}, users = [], creds = [], deviceLinks } = {}) {+ pwHash ??= await hashPassword(GOOD);+ const dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'gym-fa-'));+ fs.writeFileSync(path.join(dataDir, 'secret'), SECRET, { mode: 0o600 });+ fs.writeFileSync(path.join(dataDir, 'db.json'), JSON.stringify({ users, creds, subs: [], invites: [], ...(deviceLinks ? { deviceLinks } : {}) }));+ const child = spawn(process.execPath, ['server.js'], {+ cwd: API, stdio: ['ignore', 'pipe', 'pipe'],+ env: {+ ...process.env, PORT: '0', DATA_DIR: dataDir, ORIGIN, RP_ID: 'localhost',+ PASSWORD_LOGIN: '1', TRUST_PROXY: '1', INVITE_ONLY: '', ADMIN_UIDS: '', AUDIT_LOG: '1', ...env+ }+ });+ const h = { api: '', log: '', dataDir };+ child.stdout.on('data', d => h.log += d);+ child.stderr.on('data', d => h.log += d);+ t.after(() => { child.kill('SIGKILL'); fs.rmSync(dataDir, { recursive: true, force: true }); });+ h.api = `http://127.0.0.1:${await boundPort(child, () => h.log)}`;+ h.req = async (method, p, { body, cookie, ip = '198.51.100.1', headers = {} } = {}) => {+ const r = await fetch(`${h.api}${p}`, {+ method,+ headers: { 'Content-Type': 'application/json', 'Sec-Fetch-Site': 'same-origin', 'X-Forwarded-For': ip, ...(cookie ? { Cookie: cookie } : {}), ...headers },+ body: body === undefined ? undefined : JSON.stringify(body)+ });+ const setCookie = r.headers.getSetCookie().find(c => c.startsWith('gymsid=') && !c.startsWith('gymsid=;'));+ return { status: r.status, body: await r.json(), headers: r.headers, cookie: setCookie ? setCookie.split(';')[0] : null };+ };+ h.db = () => JSON.parse(fs.readFileSync(path.join(dataDir, 'db.json'), 'utf8'));+ h.audit = () => { try { return fs.readFileSync(path.join(dataDir, 'audit.log'), 'utf8').trim().split('\n').map(l => JSON.parse(l)); } catch { return []; } };+ // A passkey assertion made for this request, the way Settings confirms before adding.+ h.stepUp = async (key, ip) => {+ const { cid, options } = (await h.req('POST', '/api/login/options', { body: {}, ip })).body;+ return { cid, credential: key.assertion(options.challenge) };+ };+ return h;+}+const user = (id, name, extra = {}) => ({ id, name, created: new Date().toISOString(), ...extra });+const withPassword = (id, name) => user(id, name, { pw: { h: pwHash, set: new Date().toISOString() } });+++const registerPassword = (h, name, ip) => h.req('POST', '/api/register/password', { body: { name, password: GOOD }, ip });+async function registerPasskey(h, name, ip) {+ const opt = await h.req('POST', '/api/register/options', { body: { name }, ip });+ assert.equal(opt.status, 200);+ return h.req('POST', '/api/register/verify', { body: { cid: opt.body.cid, credential: softPasskey().attestation(opt.body.options.challenge) }, ip });+}+const stored = (h, id) => h.db().users.find(u => u.id === id);++test('the first password registration on an empty instance is the admin, the second is not', async t => {+ const h = await startServer(t);+ const first = await registerPassword(h, 'Ana', '198.51.100.10');+ assert.equal(first.status, 200);+ assert.equal(first.body.user.admin, true);+ assert.equal(stored(h, first.body.user.id).admin, true);+ assert.equal((await h.req('GET', '/api/admin/users', { cookie: first.cookie })).status, 200);+ assert.ok(h.audit().some(e => e.ev === 'admin.first-user' && e.uid === first.body.user.id));++ const second = await registerPassword(h, 'Bea', '198.51.100.11');+ assert.equal(second.status, 200);+ assert.equal(second.body.user.admin, false);+ assert.equal('admin' in stored(h, second.body.user.id), false);+ assert.equal((await h.req('GET', '/api/admin/users', { cookie: second.cookie })).status, 403);+});++test('the first passkey registration on an empty instance is the admin, the second is not', async t => {+ const h = await startServer(t);+ const first = await registerPasskey(h, 'Ana', '198.51.100.20');+ assert.equal(first.status, 200);+ assert.equal(first.body.user.admin, true);+ assert.equal(stored(h, first.body.user.id).admin, true);+ const second = await registerPasskey(h, 'Bea', '198.51.100.21');+ assert.equal(second.status, 200);+ assert.equal(second.body.user.admin, false);+ assert.equal('admin' in stored(h, second.body.user.id), false);+});++test('FIRST_USER_ADMIN=0 leaves the first profile an ordinary one', async t => {+ for (const off of ['0', 'false', 'off']) {+ const h = await startServer(t, { env: { FIRST_USER_ADMIN: off } });+ const r = await registerPassword(h, 'Ana', '198.51.100.30');+ assert.equal(r.status, 200);+ assert.equal(r.body.user.admin, false, off);+ assert.equal('admin' in stored(h, r.body.user.id), false, off);+ const k = await registerPasskey(h, 'Bea', '198.51.100.31');+ assert.equal(k.body.user.admin, false, off);+ }+});++test('an instance that already has profiles promotes nobody on upgrade or on a new registration', async t => {+ const h = await startServer(t, { users: [user('u1', 'Old'), user('u2', 'Older')] });+ assert.equal(stored(h, 'u1').admin, undefined);+ const r = await registerPassword(h, 'New', '198.51.100.40');+ assert.equal(r.status, 200);+ assert.equal(r.body.user.admin, false);+ const k = await registerPasskey(h, 'Newer', '198.51.100.41');+ assert.equal(k.body.user.admin, false);+ assert.equal(h.db().users.filter(u => u.admin === true).length, 0);+});++test('an ADMIN_UIDS admin stays an admin, and does not make the next profile one', async t => {+ const h = await startServer(t, { env: { ADMIN_UIDS: 'u1' }, users: [user('u1', 'Owner')] });+ assert.equal((await h.req('GET', '/api/admin/users', { cookie: mintSession('u1') })).status, 200);+ const r = await registerPassword(h, 'Guest', '198.51.100.50');+ assert.equal(r.body.user.admin, false);+});diff --git a/docs/SELF_HOSTING.md b/docs/SELF_HOSTING.mdindex 8907b4516..9925a9013 100644--- a/docs/SELF_HOSTING.md+++ b/docs/SELF_HOSTING.md@@ -132,20 +132,31 @@ Visit `https://gym.example.com`, create your profile, and add it to your home sc## 4. Multiple usersAnyone who can reach the URL can create their own profile — each gets isolated data. That's the-default: open signup, no admin.+default: open signup, and **the first profile created on the instance is its admin**+(`FIRST_USER_ADMIN`, on by default). So register your own profile before you share the address.-If you'd rather control who gets in, three optional settings in `.env` turn that around:+"First" is decided at the moment of registration: the instance had no profiles at all. It is+never applied after the fact — an instance that already has profiles promotes nobody when it is+upgraded — and an instance whose profiles were all deleted counts as fresh again. The flag is+stored as `"admin": true` on that profile's entry in `./data/db.json`; delete that line (with the+stack stopped) to take it back.++If you'd rather control who gets in, these optional settings in `.env` turn that around:```bash-ADMIN_UIDS=youruserid # comma-separated; these users get the admin dashboard+ADMIN_UIDS=youruserid # comma-separated; these users get the admin dashboard tooINVITE_ONLY=1 # new profiles need an invite codeALLOW_GUEST=0 # remove "Continue without account"+FIRST_USER_ADMIN=0 # the first profile is an ordinary one; admins only via ADMIN_UIDS```-Register your own passkey profile first, then copy your id from **Settings → Account → Account-ID** (tap it to copy; it is also in `./data/db.json` under `users[].id`) and put it in-`ADMIN_UIDS`. The same row is how anyone on your instance tells you which account is theirs when-they need help. You'll get an **Admin dashboard** link in Settings: who's training+Create your own profile before you switch `INVITE_ONLY` on: with no profile and no admin yet,+nobody could generate the first code.++For more admins (or on an instance that existed before `FIRST_USER_ADMIN`), copy the id from+**Settings → Account → Account ID** (tap it to copy; it is also in `./data/db.json` under+`users[].id`) and put it in `ADMIN_UIDS`. The same row is how anyone on your instance tells you+which account is theirs when they need help. Admins get an **Admin dashboard** link in Settings: who's trainingright now, each user's workout history and body weight, the ability to disable an account (signedout and locked out everywhere until you re-enable it), and — with `INVITE_ONLY=1` — generating andrevoking invite codes. Existing accounts keep working when you switch invite-only on. Admin accessdiff --git a/kubernetes/deployment.yaml b/kubernetes/deployment.yamlindex fde1b6032..4694c9dc4 100644--- a/kubernetes/deployment.yaml+++ b/kubernetes/deployment.yaml@@ -56,8 +56,10 @@ spec:value: opengym.example.com- name: ORIGINvalue: https://opengym.example.com- # Everything else in .env.example (INVITE_ONLY, ADMIN_UIDS, ALLOW_GUEST,- # DEFAULT_LANG, PASSWORD_LOGIN, the push keys, ...) goes here the same way.+ # Everything else in .env.example (INVITE_ONLY, ADMIN_UIDS, FIRST_USER_ADMIN,+ # ALLOW_GUEST, DEFAULT_LANG, PASSWORD_LOGIN, the push keys, ...) goes here the+ # same way. FIRST_USER_ADMIN is on unless set to "0": the first profile created on+ # an empty instance becomes its admin.# TRUST_PROXY is left off on purpose: the web container overwrites X-Forwarded-For# with the address it was reached from, which here is the gateway's pod, so turning# it on changes nothing for the sign-in throttle — while any pod in the cluster thatdiff --git a/website/api.html b/website/api.htmlindex 9eb7a86e3..39c0c2862 100644--- a/website/api.html+++ b/website/api.html@@ -275,7 +275,7 @@ main.api-main .lead { color: var(--fg-2); max-width: 58ch; margin: 14px 0 0; fon</div><div class="ov"><h3>Environment-dependent behavior</h3>-<ul><li><code>INVITE_ONLY=1</code> — registration requires a valid invite code (minted by an admin).</li><li><code>ALLOW_GUEST=0</code> — hides the client-side "continue without account" mode; the server merely reports the flag via <code>GET /api/config</code> (guest mode never talks to this API at all).</li><li><code>ADMIN_UIDS=<uid>,<uid></code> — user ids treated as admins (a <code>"admin": true</code> flag on the user record in <code>db.json</code> works too). Admins get the <code>/api/admin/*</code> routes.</li><li><code>AUDIT_LOG</code> (default on), <code>AUDIT_MAX</code> (default 5000 events), <code>AUDIT_DAYS</code> (default 90), <code>AUDIT_IP</code> (<code>off</code> | <code>net</code> | <code>full</code>, default off) — shape the audit log served by <code>GET /api/admin/audit</code>.</li><li><code>PASSWORD_LOGIN=1</code> — adds the <code>password</code> routes and <code>password_login: true</code> in <code>GET /api/config</code>. Off by default.</li><li><code>DEFAULT_LANG</code> (e.g. <code>pt-BR</code>; unset by default) — <code>default_lang</code> in <code>GET /api/config</code>, the language of the sign-in screen and of every profile that never picked one.</li><li><code>TRUST_PROXY=1</code> — the throttle reads the client address from proxy headers (set by the bundled <code>docker-compose.yml</code>, where only the web container can reach the API).</li><li><code>MEDIA_UPLOADS</code> (default on; <code>0</code> removes the <code>media</code> routes and the <code>media</code> block of <code>GET /api/config</code>), <code>MEDIA_QUOTA_MB</code> (200 per profile, <code>0</code> = no cap), <code>MEDIA_IMAGE_MAX_MB</code> (2), <code>MEDIA_GIF_MAX_MB</code> (8), <code>MEDIA_VIDEO_MAX_MB</code> (40), <code>MEDIA_VIDEO_MAX_SEC</code> (60), <code>MEDIA_GC_GRACE_DAYS</code> (14), <code>MEDIA_UPLOADS_PER_HOUR</code> (600 per profile), <code>MEDIA_MIN_FREE_MB</code> (512, <code>0</code> = no floor) — photos and videos of custom exercises (tag <code>media</code>). Every MB here is 2^20 bytes.</li></ul>+<ul><li><code>INVITE_ONLY=1</code> — registration requires a valid invite code (minted by an admin).</li><li><code>ALLOW_GUEST=0</code> — hides the client-side "continue without account" mode; the server merely reports the flag via <code>GET /api/config</code> (guest mode never talks to this API at all).</li><li><code>ADMIN_UIDS=<uid>,<uid></code> — user ids treated as admins (a <code>"admin": true</code> flag on the user record in <code>db.json</code> works too). Admins get the <code>/api/admin/*</code> routes.</li><li><code>FIRST_USER_ADMIN</code> (default on; <code>0</code> turns it off) — the first profile registered on an instance with no profiles gets that <code>"admin": true</code> flag. Decided at registration only, never applied to an instance that already has profiles.</li><li><code>AUDIT_LOG</code> (default on), <code>AUDIT_MAX</code> (default 5000 events), <code>AUDIT_DAYS</code> (default 90), <code>AUDIT_IP</code> (<code>off</code> | <code>net</code> | <code>full</code>, default off) — shape the audit log served by <code>GET /api/admin/audit</code>.</li><li><code>PASSWORD_LOGIN=1</code> — adds the <code>password</code> routes and <code>password_login: true</code> in <code>GET /api/config</code>. Off by default.</li><li><code>DEFAULT_LANG</code> (e.g. <code>pt-BR</code>; unset by default) — <code>default_lang</code> in <code>GET /api/config</code>, the language of the sign-in screen and of every profile that never picked one.</li><li><code>TRUST_PROXY=1</code> — the throttle reads the client address from proxy headers (set by the bundled <code>docker-compose.yml</code>, where only the web container can reach the API).</li><li><code>MEDIA_UPLOADS</code> (default on; <code>0</code> removes the <code>media</code> routes and the <code>media</code> block of <code>GET /api/config</code>), <code>MEDIA_QUOTA_MB</code> (200 per profile, <code>0</code> = no cap), <code>MEDIA_IMAGE_MAX_MB</code> (2), <code>MEDIA_GIF_MAX_MB</code> (8), <code>MEDIA_VIDEO_MAX_MB</code> (40), <code>MEDIA_VIDEO_MAX_SEC</code> (60), <code>MEDIA_GC_GRACE_DAYS</code> (14), <code>MEDIA_UPLOADS_PER_HOUR</code> (600 per profile), <code>MEDIA_MIN_FREE_MB</code> (512, <code>0</code> = no floor) — photos and videos of custom exercises (tag <code>media</code>). Every MB here is 2^20 bytes.</li></ul></div><div class="ov"><h3>Conventions</h3>