CARE in a box: care-box.rithviknishad.dev on lumine
lumine is a Raspberry Pi 5 (2 GB RAM, 4 cores) running CARE on its own: the same configuration as avocado, minus everything TeleICU. The branches differ: lumine tracks its own backend and care_fe refs (below), not avocado’s (see Currently deployed). Unlike the rest of this repo it is not NixOS and not k8s. It runs Raspberry Pi OS (Debian 13 trixie) with plain systemd units, all configured from lumine/. avocado (or the Mac) is its control plane: the box-* recipes run there, from this repo, and drive lumine over SSH + sudo. The Pi itself has no repo checkout, no sops and no agent tooling; it only runs CARE.
The build-out plan, the decisions behind it and a dated status log live in lumine/PLAN.md. This page documents what actually exists.
| Public URL | https://care-box.rithviknishad.dev (lumine’s own Cloudflare tunnel lumine) |
| Tailnet URL | https://care-box.orthrus-bass.ts.net, the Tailscale Service svc:care-box (Tailnet) |
| Access | ssh rithviknishad@lumine (tailnet, 100.67.15.72) or lumine.local (LAN) |
| OS | Raspberry Pi OS (Debian 13 trixie, arm64), booted from a 128 GB NVMe SSD in a USB enclosure (sda); the SD card is out (Moving to an SSD) |
| Control plane | this repo on avocado or the Mac (in the devshell): just box-* ssh to rithviknishad@lumine. Scripts and config are shipped to a root-owned /usr/local/lib/care-box on the box (just box-sync, run by every recipe that needs it) |
flowchart LR
user["browser / ABDM gateway"] -->|HTTPS| cf[Cloudflare edge]
cf -->|tunnel lumine| cfd[cloudflared]
cfd --> nginx["nginx 127.0.0.1:80"]
tsuser["tailnet browser"] -->|"HTTPS, svc:care-box VIP"| tsd[tailscaled]
tsd --> nginxts["nginx 127.0.0.1:8080 (rewrites origin)"]
nginx & nginxts -->|"/api/"| api["care-api: gunicorn :9000"]
nginx & nginxts -->|"/care-uploads/, /care-facility/"| vgw["VersityGW :7070"]
nginx & nginxts -->|"/mfe-plugs/abdm/"| mfe["/opt/care/abdm-fe"]
nginx & nginxts -->|"/"| spa["/opt/care/fe"]
api & worker[care-worker] & beat["care-beat (migrates)"] --> pg[(postgres 17)] & redis[(redis 8)]
api --> vgw
worker -->|"SMTP over the tailnet"| mailpit[avocado Mailpit]
Bring-up on a fresh box, in order, from avocado (everything is idempotent):
just box-provision # packages, users, units, nginx sites, tunnel config, svc:care-box
just box-secrets-render # decrypt here, render there; starts versitygw + the tunnel
just box-deploy # build the backend, migrate, start care.target
just box-buckets # buckets + the care-facility policy
just box-fe # ON AVOCADO: build + ship the SPA and the ABDM MFE
just box-seed-demo # demo fixtures, then admin's password from the sops file
just box-register-abdm # plug_config for the ABDM MFE
Control plane
Nothing about care-box is operated from the Pi itself. The recipes run where this repo is (avocado or the Mac), and reach the box as rithviknishad@lumine over the tailnet (passwordless sudo there):
- Scripts and config (
lumine/minusPLAN.mdand the build-onlycare_fe/overlay, plus avocado’sk8s/care/additional-plugs.jsonand aSYSTEMS_NIX_REVISIONstamp) are rsynced to/usr/local/lib/care-box, root-owned and read-only to everyone else, byjust box-sync. Every recipe that runs a script there syncs first, so the box always runs this checkout’s version, likejust deploydoes for avocado. It’s deliberately not under/opt/care: thecareuser owns that, and must not be able to rewrite what root runs. - Secrets are decrypted on the control plane with its own age key and streamed to the box over SSH stdin, never argv or a temp file (
box-secrets-render,box-seed-demo). lumine isn’t a sops recipient, so the Pi holds only the rendered files it runs on and can’t open anything insecrets/. - Host key: avocado pins lumine’s SSH host key system-wide (
modules/care-box.nix). On the Mac it’s trust-on-first-use.
| Recipe | What |
|---|---|
just box-status | units, running revisions (backend, SPA, MFE, ops scripts), tailscale serve status, memory, disk, temperature + throttling |
just box-health | every unit active and none failed, postgres/redis/VersityGW/gunicorn/both nginx servers (incl. the tailnet server’s origin rewrite) on the box, then the public URL and the tailnet URL end to end. Non-zero exit on any failure |
just box-start / box-stop / box-restart | the backend (care.target: beat, API, worker). Start/restart wait for beat’s migrations and then for gunicorn to answer. Postgres, redis, VersityGW, nginx and the tunnel keep running |
just box-offline / box-online | stop/start the tunnel: the public URL goes down (Cloudflare’s 530 page) while the box stays up |
just box-logs [unit] | follow care-* (or any unit’s) journal |
just box-manage <cmd> [args] | manage.py as care with the units’ env (pty when interactive) |
just box-deploy [ref] [repo] | build + roll out the backend |
just box-fe [ref] [repo] | build + ship the SPA and the ABDM MFE (on avocado) |
just box-provision / box-upgrade | converge the base system / apt full-upgrade |
just box-secrets / box-secrets-render | edit the sops file / render it onto the box |
just box-ssh | a shell on lumine |
just box-backup / box-backups | pull a backup to avocado now / list the snapshots (Backups) |
Stops and box-offline aren’t persistent: the units are enabled, so a reboot brings everything back.
Base system
just box-provision (lumine/provision.sh) converges the box. It’s idempotent: every step compares against the current state, so re-running it is a no-op unless something under lumine/ changed, and that’s how such changes get applied.
- Packages:
postgresql-17,redis-server(8.0),nginx,cloudflared(from Cloudflare’s apt repo; the signing-key fingerprint is pinned in the script),awscli, plus CARE’s build deps (the same set as the builder stage of upstream’sdocker/prod.Dockerfile, plus Debian’s split-outpython3-venv/python3-dev) and runtime libs (gettext, libmagic, pango/harfbuzz for weasyprint PDFs). - Pinned release binary in
/usr/local/bin: VersityGW 1.8.0 (the image tag ink8s/care/care.yaml). Its sha256 is pinned in the script, not fetched next to the download. (sops andjustwere used while the box ran its own recipes; provisioning now removes them.) - Users and paths: system user
care(home/opt/care). Code and venv go in/opt/care, data in/var/lib/care, and the rendered env file with decrypted secrets in/etc/care(root,0700). - Postgres is tuned for 2 GB in
lumine/postgresql/care-box.conf(shared_buffers=128MB,max_connections=30,jit=off, …). The rolecareowns the databasecareand connects with peer auth over the unix socket, so no database password exists anywhere. It is not a superuser; as the owner it can still createpg_trgm, the only (trusted) extension CARE’s migrations need. - systemd units from
lumine/systemd/. A changed unit is installed, daemon-reloaded and restarted if it was running. - Nothing listens beyond loopback except sshd, tailscaled and the metrics exporters, and the exporters’ ports are tailnet-only (Metrics). Debian’s catch-all nginx welcome site is disabled.
just box-upgrade runs apt full-upgrade. It’s deliberately separate from provisioning. Kernel and firmware updates take effect on the next reboot, and rpi-eeprom-update.service only auto-flashes the bootloader when it’s older than the package’s critical minimum. Check before rebooting with sudo rpi-eeprom-update.
Moving to an SSD
just box-clone-ssd <disk> (lumine/clone-to-ssd.sh) copies the running SD-card system onto an SSD, so the box can boot from it:
- Recreates the SD’s layout (MBR, 512 MiB FAT32
bootfsat 8 MiB, ext4rootfsfilling the rest) with a new disk id. The SSD’scmdline.txtroot=and/etc/fstabare rewritten to its ownPARTUUIDs. The SD card is left untouched as a working fallback, and the two never clash when both are plugged in. - File-level, not
dd:rsync -aHAXxcopies only used space (xattrs included: VersityGW keeps S3 metadata in them). The first pass is live; a second, short one runs with postgres, redis, VersityGW and CARE stopped (nginx and the tunnel stay up, so the site briefly errors), so their data is consistent./var/swapisn’t copied: it’s recreated the wayrpi-swapmakes it (fallocate+mkswap --label origin:rpi-swap). Both filesystems arefscked at the end. - Refuses a disk with partitions or signatures unless given
--force, and a mounted one always. If it fails half-way, the services are started again. --poweroffpowers the box off after the copy instead of restarting the services, so nothing is written to the SD afterwards. Use it for the real switch-over: anything written after a plain clone stays behind on the SD.
The bootloader’s BOOT_ORDER=0xf461 already tries SD, then NVMe, then USB (the EEPROM default). So pulling the SD card is the switch; putting it back switches back. A clone made over USB also boots from the M.2 HAT once that links up, since it’s the same disk. After the switch, the dashboard’s SD-card I/O panels (device="mmcblk0") and rpi_sd_card_info go empty.
First clone (2026-10-13): a 128 GB NVMe in a JMicron USB enclosure (sda, on a USB 2 port at 480 Mbit/s). 4.5 GB copied in 3m44s, services down 36 s, VersityGW xattrs identical. The same day the SD card was pulled and the box booted from the SSD (/ = sda2, /boot/firmware = sda1, disk id 1cb25ccf); box-health 18/18. The old SD card then went into a Pi 4 and was turned into a separate host, ephy (not managed by this repo): CARE and the tunnel disabled, the tunnel credentials deleted, and a new hostname, machine-id, SSH host keys and Tailscale node. A clone keeps all of lumine’s identities, so running both would put two boxes on the same tunnel (requests split between two databases) and the same Tailscale node. Do the same to any future clone that boots elsewhere. Wipe /var/lib/tailscale/tailscaled.state rather than running tailscale logout: logout revokes the node key, which lumine shares.
Still to do: move the enclosure to a blue USB 3 port (it’s on USB 2, 480 Mbit/s), and get the Seeed M.2 HAT working (still link down on pcie@1000110000; power comes through its pogo pins; see lumine/PLAN.md), then move the SSD onto it.
Backend
Three systemd units run one release of the backend, grouped by care.target so they’re always restarted together:
| Unit | What | Mirrors upstream’s |
|---|---|---|
care-beat | migrate → sync_permissions_roles → sync_valueset (as ExecStartPre=), then celery beat | scripts/celery_beat.sh |
care-api | gunicorn on 127.0.0.1:9000, 2 workers, --preload | scripts/start.sh |
care-worker | celery worker, concurrency 1, --max-tasks-per-child=6 | scripts/celery_worker.sh |
Beat owns migrations, as on avocado. The API and worker are ordered after beat’s start job, which only completes once its ExecStartPre= steps are done. So unlike on k8s, the API never serves an unmigrated schema, and systemctl restart care.target blocks until the migrations finish. A failing migration makes beat crash-loop (Restart=always) the way a pod would. collectstatic and compilemessages run once per build, not on every start: STATIC_ROOT lives inside the release.
Releases
/opt/care/backend/<sha12>-<cfg8>/ checkout + .venv + staticfiles + REVISION + build.env
/opt/care/backend/current -> the release the units run
just box-deploy (lumine/care/deploy-backend.sh) resolves the head of the tracked branch (rithviknishad/care@rithviknishad/bodhi/ENG-737-test-fixtures; pass [ref] [repo] to deploy something else). It then builds a release the way upstream’s docker/prod.Dockerfile builds the image: a venv, pipenv install --deploy --categories packages (pipenv 2025.1.1, as upstream pins it), install_plugins.py. It flips current and restarts care.target. If current already is that build, it does nothing. A build is only marked complete at its very end, so an interrupted deploy is simply redone on the next run while the old release keeps serving. The two newest non-current releases are kept (~330 MB each).
- What’s running:
/opt/care/backend/current/REVISION(repo, ref, sha, plugs, build time, and the systems.nix commit it was built from), orjust box-status. - Rollback:
ssh lumine sudo ln -sfn <older-release> /opt/care/backend/current, thenjust box-restart. Migrations don’t roll back, so the old code meets the newer schema, the same as rolling back an image on avocado. - Plugs:
ADDITIONAL_PLUGS= avocado’sk8s/care/additional-plugs.jsonminus the three TeleICU plugs, i.e. justabdmat avocado’s pinned sha, derived at deploy time so the two boxes can’t drift. Each release’sbuild.envrecords the exact list that was pip-installed, and the units load that file, so the build-time and runtime values match by construction.<cfg8>hashes the plug list and the settings module: changing either makes a new release, the same as a new commit. - Measured (2026-10-07): a build takes ~2 min with a warm pip cache (~4 min cold). The first migrate +
sync_valueseton an empty DB took ~2.5 min. Idle footprint (PSS): API ~210 MB, worker ~170 MB, beat ~120 MB, postgres ~30 MB. The worst moment is the build itself (pip compiling C extensions: ~360 MB available, ~560 MB swap), not the migrations (~810 MB available).
Configuration and secrets
The units load two env files: /etc/care/care.env and the release’s build.env.
just box-secrets-render (lumine/render-secrets.sh) decrypts secrets/care-box.enc.env and secrets/lumine-cloudflared.json on the control plane and streams them over SSH into one root-only (0600) file per consumer, so each service sees only its own secrets:
| File | Contents | Consumer |
|---|---|---|
/etc/care/care.env | the non-secret template lumine/care/care.env (avocado’s care-backend-env ConfigMap with the care-box origin) + the app secrets from secrets/care-box.enc.env | care-* |
/etc/care/versitygw.env | ROOT_ACCESS_KEY_ID/ROOT_SECRET_ACCESS_KEY = BUCKET_KEY/BUCKET_SECRET, nothing else (avocado uses secretKeyRef for the same reason) | versitygw |
/etc/cloudflared/<tunnel-id>.json | secrets/lumine-cloudflared.json (sops binary), checked against the tunnel id | cloudflared-lumine (via LoadCredential=) |
Keys starting with BOX_ (e.g. BOX_ADMIN_PASSWORD) are for humans and recipes only and are left out. On the box, plaintext is staged next to its destination (atomic rename, root-only directory), never in /tmp or on stdout, and the script refuses a truncated stream. Both env files are read back through systemd’s own EnvironmentFile= parser to check that every value round-trips; only key names are reported. That check matters because systemd’s syntax isn’t shell: unquoted double quotes are stripped, so JSON values must be single-quoted. A file is only rewritten when it changed, and then its consumer is restarted (care.target if it was running; versitygw/cloudflared-lumine whenever they’re enabled, including their first start).
just box-secrets edits the sops file with the control plane’s age key. Follow it with just box-secrets-render.
Two settings differ from upstream’s config.settings.deployment. They live in lumine/care/care_box_settings.py, which every build copies to config/settings/care_box.py (DJANGO_SETTINGS_MODULE=config.settings.care_box):
EMAIL_USE_TLScomes from the env.deployment.pyhard-codes it toTrue, but mail goes through avocado’s Mailpit over the tailnet (avocado:1025, usercsaas, plain SMTP), so STARTTLS would fail every send. Mail is sent asCARE box <care-box@rithviknishad.dev>to tell it apart in the shared inbox. Test it withjust box-manage sendtestemail you@example.com.- gunicorn’s loggers are kept enabled. With
--preload, Django configures logging inside the gunicorn master, anddisable_existing_loggers: Truewould silence gunicorn entirely: no access log, and noWORKER TIMEOUTwarnings.
Operating it
just box-status # units, running REVISION, memory, disk, temperature
just box-health # everything up? (non-zero exit if not)
just box-logs # follow all care-* units (or: just box-logs care-beat)
just box-manage <command> [args] # manage.py as care, with the units' exact env
just box-restart # restart beat (migrates) -> API + worker, wait until ready
Peer auth means DATABASE_URL=postgres:///care works only as the care OS user, which is why box-manage goes through lumine/care/manage.sh (systemd-run with the units’ env files, a pty when interactive). The recipe shell-quotes its arguments for the remote side, so just box-manage shell -c 'print(1)' arrives intact. Scripts can add one-off, non-secret variables with leading --setenv=K=V options. Never pass secrets that way: a transient unit’s environment is readable by every local user through systemctl show. Celery’s own “ready” / “beat: Starting” lines never reach the log, because upstream’s LOGGING disables those loggers (avocado has the same quirk). Check the worker with: sudo systemd-run --pipe --wait -q --uid=care -p EnvironmentFile=/etc/care/care.env -p EnvironmentFile=/opt/care/backend/current/build.env -p WorkingDirectory=/opt/care/backend/current /opt/care/backend/current/.venv/bin/celery -A config.celery_app inspect ping.
Frontend
The SPA and the ABDM MFE are built on avocado, not on the Pi. care_fe’s Vite build needs ~4 GB of RAM and lumine has 2 GB, while the output is architecture-independent static files. just box-fe [ref] [repo] runs on avocado (it needs docker and the RAM):
- builds care_fe at the head of
3.1/immunization-policies(the top of the CARE 3.1 stack, care_fe#16916; its immunization/workspace screens need backend APIs the fork branch doesn’t have yet, so their calls 404 for now. avocado’s own SPA stays onbodhi/questionnaire-actions) with the same.env.localascare-fe-image, but with an emptyREACT_CARE_API_URL(care_fe’sscripts/validate-env.tsallows""): API calls are relative, so the one build is same-origin on both of care-box’s names (public and tailnet), and plugins getwindow.CARE_API_URL = ""too (+REACT_MFE_REGISTERED_COMPONENTS=AddFacilitySheet); - sets the care-box logo as the state logo (
REACT_STATE_LOGO, a JSON string{"light": ..., "dark": ...}, single-quoted in.env.localso dotenv keeps it intact).validate-env.tsfails the build unless both are absolute URLs (zodz.url()), which would tie the logo to one origin, so it’s inlined as adata:image/svg+xml;base64,...URL generated fromlumine/care_fe/public/images/CareOnABox_flat.svg(~16 KB, in the bundle once). The SPA’s CSP (report-only) allowsdata:images for it; - sets the login page’s
REACT_CUSTOM_DESCRIPTION(“running on a Raspberry Pi 5 (2GB)” + a link to this page). care_fe renders it as GitHub-flavoured markdown at build time (bare URLs become links) and sanitizes it with DOMPurify; - overlays
lumine/care_fe/onto the checkout before the build, mirroring care_fe’s layout:public/images/CareOnABox_flat.svgis served as/images/CareOnABox_flat.svg. Put more assets there the same way; - builds the ABDM MFE from
k8s/care/abdm-feat the sha pinned inadditional-plugs.json. The files are identical to avocado’s MFE (it bakes in no origin, only its/mfe-plugs/abdm/base); - copies the files out of the images (
docker create+docker cp, nothing runs) and rsyncs them to lumine viasudo rsyncas root-owned read-only files, then flips thecurrentsymlink.
/opt/care/fe/<sha12>-<cfg8>/{html/,REVISION} # care_fe; <cfg8> = hash of .env.local + lumine/care_fe/
/opt/care/abdm-fe/<sha12>-<cfg8>/{html/,REVISION} # ABDM MFE; <cfg8> = hash of k8s/care/abdm-fe/
/opt/care/{fe,abdm-fe}/current # what nginx serves
REVISION sits next to html/, not inside it, so build metadata isn’t served. A half whose <id> is already live is skipped. The two previous builds of each are kept, so a rollback is ssh lumine sudo ln -sfn <id> /opt/care/fe/current. It takes effect on the next request, with no reload.
Storage, routing and the tunnel
Object storage (VersityGW)
versitygw.service runs VersityGW 1.8.0 (the same version as avocado), configured the same way, on 127.0.0.1:7070 as the static system user versitygw. Its posix backend sits over /var/lib/care/s3 (0750): one directory per bucket, one plain file per object, S3 metadata in user.* xattrs (ext4 supports them). Its root credentials are CARE’s BUCKET_KEY/BUCKET_SECRET from /etc/care/versitygw.env and nothing else. VGW_REGION=ap-south-1 must equal BUCKET_REGION. A SigV2-capable region like us-east-1 would make botocore presign with SigV2, which VersityGW rejects (see CARE).
just box-buckets (lumine/care/buckets.sh) is avocado’s versitygw-buckets Job minus TeleICU’s bucket, and is idempotent: care-uploads stays private (presigned URLs only), and care-facility gets an anonymous s3:GetObject policy, because CARE serves covers and profile pictures as plain unsigned URLs. Listing stays denied on both. The gateway’s own bookkeeping (.vgwlocks/, <bucket>/.sgwtmp/) lives in the same tree; those files aren’t objects.
nginx: two origins, path-routed
lumine/nginx/care-box.conf (installed to /etc/nginx/conf.d/ by box-provision, which runs nginx -t and restores the previous file if the test fails) mirrors avocado’s care Ingress. Paths are forwarded unmodified. It has two servers, both on loopback only: the public one on 127.0.0.1:80, whose sole client is cloudflared, and the tailnet one on 127.0.0.1:8080 for tailscaled (Tailnet). Everything that doesn’t depend on the hostname (the MFE and SPA locations below, mime types, body size) is shared from lumine/nginx/snippets/care-box-static.conf → /etc/nginx/snippets/ (not conf.d/, which nginx would load as a top-level file). The public server:
| Path | Goes to | Notes |
|---|---|---|
/api/ | gunicorn 127.0.0.1:9000 | SPA API + ABDM callbacks. Requests are buffered, which keeps slow clients off the sync workers. X-Forwarded-Proto is passed through from cloudflared (https) |
/care-uploads, /care-facility (+ /…) | VersityGW 127.0.0.1:7070 | Host preserved (SigV4 signs it). Request/response bodies are streamed, not spooled to disk. Also matches bucket-level paths, so an anonymous LIST gets the gateway’s 403 rather than the SPA |
/mfe-plugs/abdm/ | /opt/care/abdm-fe/current/html | rules of k8s/care/abdm-fe/nginx.conf: remoteEntry.js no-cache, hashed assets immutable, .js/.mjs as text/javascript, misses 404 |
/ | /opt/care/fe/current/html | rules of care_fe’s own nginx/nginx.conf: its security headers (HSTS, X-Frame-Options, CSP report-only, …), 7d caching (6h for index.html), SPA fallback to index.html |
client_max_body_size 100m matches Cloudflare’s free-plan request cap. The SPA’s security headers are scoped to /, so API and MFE responses don’t get them, the same as on avocado, where they come from care_fe’s own nginx.
Django admin is not reachable at all (decision 2026-10-07, and again for the tailnet Service on 2026-10-19). Only /api/ reaches the backend, on both servers, so /admin/* is the SPA’s own admin UI there. Plain http://lumine:<port> wouldn’t work anyway, because the deployment settings mark the session and CSRF cookies Secure. If it’s ever needed, the zero-exposure way in is an SSH tunnel to gunicorn, ssh -L 8000:127.0.0.1:9000 lumine, then http://localhost:8000/admin/. Browsers accept Secure cookies on localhost, and Django’s CSRF origin check passes for the tunnel’s own origin, so no config change is needed.
Cloudflare Tunnel lumine
cloudflared-lumine.service runs tunnel lumine (1e284975-9221-4b79-8242-0722c96294ed), which is independent of avocado’s, so care-box stays up when avocado is down. It runs as a DynamicUser=, gets the root-only credentials file through LoadCredential=, and uses --no-autoupdate, because apt (Cloudflare’s repo) owns updates. Ingress in lumine/cloudflared/config.yml: care-box.rithviknishad.dev → http://127.0.0.1:80, everything else http_status:404. It has the same retry-forever policy as avocado’s tunnel (StartLimitIntervalSec=0, RestartSec=10; modules/cloudflared.nix explains the outage that motivated it). The DNS route (CNAME → tunnel) was created once from avocado, which holds the Cloudflare login cert. TLS terminates at Cloudflare’s edge under the *.rithviknishad.dev Universal SSL cert.
A healthy tunnel logs Registered tunnel connection four times (just box-logs cloudflared-lumine).
Verified (2026-10-07, from outside through Cloudflare)
SPA, client-side routes and assets 200; /api/v1/plug_config/ and /api/abdm/health 200; MFE remoteEntry.js 200 no-cache; /admin/ is the SPA. Using CARE’s own S3 client config (get_client_config(..., external=True)): presigned PUT/GET 200 on both buckets through the public origin, URLs carry X-Amz-Algorithm=AWS4-HMAC-SHA256, stored Content-Type round-trips (xattrs work), anonymous GET 403 on care-uploads / 200 on care-facility, anonymous LIST 403 on both. The same checks avocado passed after its VersityGW switch.
Tailnet: Tailscale Service svc:care-box
The same app is also on the tailnet, at https://care-box.orthrus-bass.ts.net, as the Tailscale Service svc:care-box (decision 2026-10-19). A Service has its own tailnet IP (VIP) and MagicDNS name, separate from lumine’s, and shows up in clients’ list of services, so it’s discoverable without knowing which machine hosts it. tailscaled on lumine terminates TLS with a tailnet Let’s Encrypt certificate for that name and proxies to nginx’s tailnet server on 127.0.0.1:8080. Nothing new listens off loopback, so the firewall is unchanged. Django admin isn’t exposed here either.
One-time tailnet setup (admin console):
- Services → define
svc:care-box, endpointtcp:443. - Machines → lumine → Edit ACL tags →
tag:care-box. Only tagged nodes can host a Service. Tagging turns lumine into a tagged device (owned by the tailnet rather than a user, key expiry off). -
Access controls: the tag’s owner, auto-approval of the Service host, and the grants. The last three grants keep what lumine already did working once it’s tagged (they’re redundant while the policy still has an allow-all rule; the Service grant is needed either way):
"tagOwners": { "tag:care-box": ["autogroup:admin"] }, "autoApprovers": { "services": { "svc:care-box": ["tag:care-box"] } }, "grants": [ // Use the app: people, and avocado (Gatus, box-health). { "src": ["autogroup:member", "tag:ssh-avocado"], "dst": ["svc:care-box"], "ip": ["tcp:443"] }, // avocado: box-* SSH, the backup pull, the metrics scrape. { "src": ["tag:ssh-avocado"], "dst": ["tag:care-box"], "ip": ["tcp:22", "tcp:9100", "tcp:9113", "tcp:9121", "tcp:9187", "tcp:9256", "tcp:9300"] }, // Your devices: SSH (box-* from the Mac). { "src": ["autogroup:member"], "dst": ["tag:care-box"], "ip": ["tcp:22"] }, // lumine's email goes to avocado's Mailpit. { "src": ["tag:care-box"], "dst": ["tag:ssh-avocado"], "ip": ["tcp:1025"] } ]
Then just box-provision. Its last step (skipped, with a warning, while lumine is untagged) runs tailscale serve --service=svc:care-box --https=443 http://127.0.0.1:8080 unless that exact config is already in place, and re-advertises the Service if it was drained. tailscaled persists both across restarts. It uses the CLI because tailscale serve set-config files can’t express “HTTPS on 443 to a plain-HTTP backend” (the target’s scheme decides the listener’s).
Same-origin without touching the backend. The backend keeps building every absolute URL from the public origin (CURRENT_DOMAIN, BUCKET_EXTERNAL_ENDPOINT): emails and ABDM callbacks must point there. On the tailnet name:
- the SPA calls the API relatively (empty
REACT_CARE_API_URL, Frontend), and its logo is adata:URL; - nginx’s tailnet server rewrites
https://care-box.rithviknishad.devtohttps://care-box.orthrus-bass.ts.netin/api/responses (sub_filteron JSON, withAccept-Encodingcleared so it can see the bodies). That covers presigned upload/download URLs, facility covers and the ABDM plug’sremoteEntry.jsURL in/api/v1/plug_config/; - the bucket locations pass
Host: care-box.rithviknishad.devto VersityGW: the URL’s host was rewritten, but its SigV4 signature covers the public host it was signed for; - Django needs nothing:
DJANGO_ALLOWED_HOSTSis*, and the CSRF origin check passes for same-origin HTTPS (X-Forwarded-Proto: https, set by nginx, trusted viaSECURE_PROXY_SSL_HEADER). The SPA uses JWTs anyway.
Caveats:
- A tailnet client that saves data containing a rewritten URL stores the ts.net one (e.g. editing a plug_config through the tailnet name). Normal clinical data has no such URLs.
- ABDM’s gateway can only reach the public origin; the tailnet name is for people.
- Clients on Tailscale 1.94+ reach Service VIPs out of the box. Older Linux clients need
tailscale set --accept-routes. - Pods can’t resolve MagicDNS through cluster DNS, but avocado’s tailscaled answers
100.100.100.100for them too, which is how Gatus probes the name (Uptime).
Withdraw it temporarily with ssh lumine sudo tailscale serve drain svc:care-box (the next box-provision re-advertises it); remove it for good by dropping the provision step and running sudo tailscale serve clear svc:care-box.
The tailnet assigns the VIP (100.112.78.131, fd7a:115c:a1e0::7838:4e84) when the Service is defined. Hosts become reachable only once approved: until then lumine’s peers don’t get a route to the VIP, and connections time out even though the name resolves.
Verified (2026-10-19, from avocado over the tailnet): SPA, plug list, /api/abdm/health and the MFE 200 over both IPv4 and IPv6; Let’s Encrypt cert for care-box.orthrus-bass.ts.net; the plug list’s ABDM URL comes back on the ts.net origin; /admin/ and /admin/login/ are the SPA. CARE’s own presigned PUT + GET (S3FilesManager’s client config, URL host rewritten as the tailnet server does) 200 through the ts.net name, and the Content-Type and Content-Disposition round-trip.
Data and ABDM
Demo data
care-box runs CARE’s demo fixtures (lumine/PLAN.md decision 5), not a production geo-organization import. just box-seed-demo (lumine/care/seed-demo.sh) mirrors avocado’s care-seed-demo:
- Installs Faker (a dev-only dependency) at the version upstream’s
Pipfile.lockpins, with its dependencies constrained to the lock, into a throwaway directory onPYTHONPATH, leaving the release venv clean. - Runs
load_fixtureswithDJANGO_DEBUG=truefor that one process only, because the fixture context refuses to run withoutsettings.DEBUG. The services keep DEBUG off. - Sets
admin’s password toBOX_ADMIN_PASSWORDfrom the sops file. The password reaches Python only through a pipe (manage.py shell -creads it from stdin), never through argv, the environment or logs.
It’s idempotent. The fixtures load only when the demo user care-admin doesn’t exist yet, because a second load would duplicate the data and load_fixtures always resets admin to admin/admin. The password step runs every time and is a no-op once set. Seeded 2026-10-07 in ~30 s: 2 facilities, 10 patients, 10 encounters, 10 users, a 31 MB DB.
The demo users are public.
care-doctor,care-nurse,care-admin, … all have the well-known passwordOhcn@123on a public host, withABDM_DEVELOPER_MODE=true(the/abdm/developerexplorer is open to any logged-in user). That’s the same deliberate trade-off as avocado. Rotate or disable them before anything real goes in. Onlyadminis rotated.
ABDM
just box-register-abdm upserts the abdm plug_config: meta.url = <CURRENT_DOMAIN>/mfe-plugs/abdm/assets/remoteEntry.js, name = care_abdm_fe. It goes through the ORM on the box rather than the admin API (so no admin credentials are involved) and clears the cached public plug list, as the API would. Like the demo data, plug_configs live in the DB: after a DB reset, re-run box-seed-demo and box-register-abdm.
care-box’s sandbox credentials (ABDM_CLIENT_ID/ABDM_CLIENT_SECRET in secrets/care-box.enc.env) get a gateway session: /api/abdm/gateway/status returns ok: true (verified 2026-10-07). The bridge URL has not been registered for care-box. ABDM keeps one bridge URL per client id, and per lumine/PLAN.md decision 3 that client is shared with avocado, which holds the bridge. So ABDM callbacks (/api/abdm/...) go to care.rithviknishad.dev: outbound calls work from care-box, but anything that waits on a callback doesn’t. Moving the callbacks here takes them away from avocado, so it’s a deliberate step:
just box-manage abdm_register_bridge_url --dry-run # shows the URL + the live bridge state
just box-manage abdm_register_bridge_url # takes callbacks over from avocado
Switching back = the same command on avocado (just care-manage abdm_register_bridge_url). See CARE → ABDM for per-facility setup (HFR link, HRP service registration).
Backups
lumine is a single disk, so its backups live on another machine. avocado pulls them nightly (care-box-backup.service, timer ~03:15 + up to 10 min, catches up after downtime; modules/care-box.nix):
/var/lib/care-box-backups/ (avocado, 0750 care-box-backup)
2026-10-07T034512Z/ one snapshot per run, named by UTC start time
care.dump pg_dump -Fc of `care`
s3/ VersityGW's tree, with its user.* xattrs
MANIFEST sizes, file count, TOC entries
latest -> 2026-10-07T034512Z
- Pull, not push. lumine holds no credentials for avocado. avocado’s key (
secrets/care-box-backup_ed25519) logs in as the Pi’scare-backupuser, whose root-ownedauthorized_keys(lumine/backup/authorized_keys) allows only avocado’s tailnet IP, with no shell or forwarding, and forceslumine/backup/backup-source.shvia a sudoers rule for that script alone. The script answerspg_dump(as postgres) or a read-onlyrrsyncof/var/lib/care/s3and refuses everything else, including writes and../paths (both tested). - Cheap dailies.
rsync --link-desthardlinks unchanged uploads to the previous snapshot, so a day costs what changed plus the dump (~1 MB for the demo data). - A dump only counts if it reads back.
pg_restore --listmust parse it. A run is built in<stamp>.partialand renamed when complete, and leftovers of a failed run are deleted on the next one. - Retention: 7 days, pruned by name, and only after a successful run, so failing backups never delete the last good ones.
- The
xattrsmatter: they hold each bucket’s ACL and policy (e.g.care-facility’s anonymous GetObject) and each object’s S3 metadata. - Alerts: after every run the service writes
care_box_backup_*textfile metrics (last success, last result, sizes, snapshot count), behindCareBoxBackupStale(critical, > 36h),CareBoxBackupFailedandCareBoxBackupMissing(Monitoring).
just box-backup # run it now and print this run's log
just box-backups # snapshots, sizes, disk use, next run
Verified 2026-10-07 with the service’s own script: a second run hardlinked everything, a 17-day-old snapshot was pruned, and the dump restored into a scratch database (10 users, 10 patients).
Restoring
Destructive: it replaces the live database and uploads. Run from avocado:
snap=/var/lib/care-box-backups/latest # or a dated snapshot
just box-stop
ssh lumine sudo systemctl stop versitygw
# Database: recreate it empty, owned by care, then restore (as postgres).
sudo cat $snap/care.dump | ssh lumine 'cd / && sudo -u postgres dropdb care &&
sudo -u postgres createdb -O care care && sudo -u postgres pg_restore --exit-on-error -d care'
# Uploads: with their xattrs, owned by versitygw again (the backup can't keep
# ownership because it runs unprivileged). Root on avocado reads the
# snapshot; your SSH key reaches lumine.
sudo rsync -rltX --delete --rsync-path='sudo rsync' --chown=versitygw:versitygw \
-e 'ssh -i /run/secrets/rithviknishad/ssh_id_ed25519' \
$snap/s3/ rithviknishad@lumine:/var/lib/care/s3/
ssh lumine sudo systemctl start versitygw
just box-start
just box-health
Metrics
The Pi is monitored from avocado’s VictoriaMetrics stack: Grafana → folder care-box → care-box (lumine), plus the stock Node Exporter Full (job node-exporter, nodename lumine). box-provision installs Debian’s exporters and configures them from lumine/metrics/:
| Port | Exporter | What |
|---|---|---|
| 9100 | prometheus-node-exporter | the usual host metrics, plus systemd (unit states, restarts, start times), processes, cpu.info, and hwmon’s Pi sensors (cpu_thermal, the fan, the RP1 ADC, the firmware’s under-voltage alarm). Textfile collector: the Pi metrics below and pending apt upgrades / reboot-required |
| 9187 | prometheus-postgres-exporter | connections, transactions, cache hits, locks, deadlocks, checkpointer (PG 17), per-table stats, DB size. Peer auth as role prometheus (pg_monitor), so no password |
| 9121 | prometheus-redis-exporter | memory, clients, commands, plus the length of the celery list = the task backlog |
| 9113 | prometheus-nginx-exporter | stub_status from 127.0.0.1:8081 (lumine/nginx/stub-status.conf) |
| 9256 | prometheus-process-exporter | per-service CPU, PSS memory, IO, process counts: care-api, care-worker, care-beat (by command line), postgres, redis, … (CAP_SYS_PTRACE via a drop-in, to read other users’ smaps) |
| 9300 | cloudflared | metrics: in the tunnel config: responses by status code, HA connections, QUIC RTT to the edge, edge locations |
Pi firmware metrics come from lumine/metrics/rpi-metrics.sh (rpi-metrics.timer, every 15 s, root for /dev/vcio), via vcgencmd: rpi_temperature_celsius{sensor="soc"|"pmic"}, every get_throttled bit as rpi_throttled{flag=...} (under_voltage_now, throttled_occurred, …), rpi_clock_hz{clock} (ARM, core, ISP, EMMC, …), the Pi 5 PMIC ADC per rail (rpi_pmic_volts/_amps/_watts, total rpi_power_watts, 5 V input rpi_input_volts), and info series for the firmware, the EEPROM bootloader and the SD card’s CID. Idle it draws ~1.9 W at ~49 °C.
Exposure. The exporters listen on every interface, and care-box-firewall.service loads lumine/metrics/care-box-metrics.nft: its own nftables table (atomically replaced, Tailscale’s tables untouched) drops those six ports on anything but lo and tailscale0. It’s ordered before the network and the exporters at boot, and box-provision loads it before apt can start a freshly installed exporter. Verified: from avocado, 100.67.15.72:9100 answers and 192.168.165.244:9100 (LAN) times out.
Scraping is k8s/monitoring/care-box-scrape.yaml, a VMStaticScrape of 100.67.15.72 (pods reach tailnet IPs through avocado’s tailscale0, but not MagicDNS names). Every series gets host="lumine". The node target is job="node-exporter", so the stack’s stock node alerts apply to lumine as well. On top of them, care-box-vmrules.yaml adds: unreachable, under-voltage (now: critical, since boot: warning), hot, throttling, SD card > 85%, memory, units down, crash loops, postgres/redis down, connections, Celery backlog, tunnel down. See Monitoring for the table. The collectors package’s timers for absent hardware (SMART, NVMe, IPMI, Mellanox) are masked, so they can’t trip the failed-unit alert.
Linux PSI (node_pressure_*) is off in the Raspberry Pi kernel by default (psi=1 on the kernel command line would enable it; not done).
Uptime. Gatus probes the public origin every 5 min in the ohcnetwork/care-box group (k8s/monitoring/gatus.yaml) and alerts through ntfy: care-box-fe (SPA + certificate > 10 days), care-box-api (/api/v1/plug_config/ lists abdm: gunicorn, DB and the plug_config), care-box-abdm (/api/abdm/health) and care-box-abdm-fe (the MFE’s remoteEntry.js). Not /ping/: only /api/ reaches the backend here, so the SPA’s fallback would answer it with a 200. care-box-tailnet probes the tailnet Service’s plug list, with Gatus resolving through 100.100.100.100: the Service is up, avocado is allowed in, its ts.net certificate has > 10 days left, and the ABDM URL comes back rewritten to the tailnet origin. The app gallery (apps.rithviknishad.dev) has a static CARE box tile with a siteMonitor status dot (Apps).
Gotchas
- The memory cgroup is off by default on Raspberry Pi OS. The firmware prepends
cgroup_disable=memoryto the kernel command line (it shows in/proc/cmdline, not in/boot/firmware/cmdline.txt), so systemd’sMemoryHigh=/MemoryMax=are silently ignored. Appendingcgroup_enable=memorytocmdline.txt(it’s a single line, and the later argument wins) plus a reboot turns it on. The care units already carry limits sized from measurements: API 450M/650M, worker 400M/600M, beat 350M/600M (High/Max). Beat gets extra room because its migrations run in its own cgroup, and an OOM-killed migration would just retry forever. - lumine can’t decrypt its own secrets, on purpose. It isn’t a sops recipient (
.sops.yaml); the control plane decrypts and streams. To read a value, usesops -d secrets/care-box.enc.envon avocado or the Mac. Decrypted copies on the box only ever go to root-owned0600files. - Keep the box free of agent sessions. A Cursor/Zed remote server plus agents took ~850 MB RSS during the build-out, close to half the RAM. Work on it from avocado instead.
systemctl stop care.targetreturns before the services are down. The target stops first (it’s ordered after its services) and the services after it, so a quickstartcan cancel a still-queued stop.box-stopnames the services explicitly, and start/restart wait for gunicorn.- Login rate limiting is effectively global. CARE’s
ratelimit()keys onREMOTE_ADDR, which behind nginx is always127.0.0.1(gunicorn takes it from the socket peer), so every client shares one per-IP bucket. A burst of failed logins from anyone can then demand a captcha from everyone. avocado has the same behaviour (there it’s Traefik’s pod IP), so it’s left as is. - Scripts behind Cloudflare need a User-Agent. Python’s
urllibdefault (Python-urllib/3.x) gets403 error code: 1010at the edge (python-requestsand curl pass). - On tagged lumine, change Tailscale settings with
tailscale set, nottailscale up.upresets every unspecified flag, and one without--advertise-tags=tag:care-boxtries to drop the tag and re-authenticate, taking the Service (and the SSH grants) with it.