Commit ff2dfac
authored
fix(portal): wire ADMIN_PASS through env_file; treat empty pass as unset (#47)
## Problem
The multitenant compose file
(`infra/docker-compose-multitenant-nats.yml`) documents `ADMIN_PASS` as
settable "via env var or `.env` file", but the `portal` service has **no
`env_file`** and no inline `ADMIN_PASS` reference. Compose's
project-level `.env` is **interpolation-only** and never reaches the
container, so a deployer's `infra/.env` `ADMIN_PASS` is silently ignored
— the portal mints a **fresh random admin password on every rebuild**,
breaking the existing admin login.
In practice operators work around this with an untracked local edit
(`ADMIN_PASS: ${ADMIN_PASS}`) that is easily lost on `git
pull`/`checkout` during an upgrade.
There's a second, nastier trap in the config logic:
```python
ADMIN_PASS = os.environ.get("ADMIN_PASS") or secrets.token_urlsafe(16)
ADMIN_PASS_GENERATED = "ADMIN_PASS" not in os.environ
```
If `ADMIN_PASS=""` (set but empty), the value path generates a random
password (because `""` is falsy), but `ADMIN_PASS_GENERATED` is `False`
— so it **generates a password and never logs it**, locking the operator
out with no recovery.
## Fix
1. **compose** — add an optional `env_file` (`infra/.env`) to the
`portal` service so `ADMIN_PASS` and other deploy secrets actually reach
the container. `required: false` keeps the inline-env-var usage
(`DC_TENANTS=... docker compose up`) working when no `.env` exists.
2. **config.py** — treat an empty `ADMIN_PASS` the same as unset:
generate **and** log. Closes the silent-lockout path regardless of how
the env is provided.
3. **docs** — document `ADMIN_USER`/`ADMIN_PASS` in
`.env.multitenant.example`.
## Notes
- `env_file` paths in this compose file resolve relative to the compose
file's dir (`infra/`), matching the existing `build.context: ../../..`
convention, so `path: .env` → `infra/.env`.
- `environment:` still wins over `env_file` for keys it sets (e.g.
`ADMIN_USER`), so no precedence surprises.
- No version bump included.1 parent 5ea5d30 commit ff2dfac
4 files changed
Lines changed: 92 additions & 4 deletions
File tree
- packages/device-connect-server
- device_connect_server/portal
- infra
- tests/device_connect_server
Lines changed: 7 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
40 | 44 | | |
41 | | - | |
42 | | - | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
43 | 48 | | |
44 | 49 | | |
45 | 50 | | |
| |||
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
Lines changed: 14 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
110 | 110 | | |
111 | 111 | | |
112 | 112 | | |
113 | | - | |
114 | | - | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
115 | 118 | | |
116 | 119 | | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
117 | 129 | | |
118 | 130 | | |
119 | 131 | | |
| |||
Lines changed: 63 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
0 commit comments