Files
coreapp-dev/PLAN.md
T
davidandClaude Opus 5.5 d8c6d1011f coreapp new --postgres --sso: database and sign-in together
Overlays no longer replace service: each names the Core apps it needs in
.depends, merged into DEPENDS. The sign-in code is a module (oidc.py)
that examples import; templates/postgres-sso is the combined example
(sign-in, each person's visits counted in PostgreSQL). Tested with
team-visits, including sign-in in a browser.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 12:43:22 -07:00

204 lines
12 KiB
Markdown

# Plan
coreapp-dev is a software development kit for building apps that run as
Docker containers on Federated Core. It is a CoreDesktop sibling project:
people install it with `sibling add <url>`, and CoreDesktop's `update` keeps
it current (format: `~/Projects/coredesktop/skills/sibling-project-format.md`).
Delete an item once it's done; git history keeps the record.
## Now: a working Core in a local VM
What we know about the CoreServer image (2026-12-02): it's Arch Linux, boots
with BIOS or UEFI, and needs a display device (it stalls at "Loading initial
ramdisk" with `--graphics none`). All passwords are locked; cloud-init
(NoCloud) installs root's SSH keys. `/` is a fixed 10 GiB btrfs partition;
the extra disk space goes to `/federated`, which the image's own
`grow-federated.service` grows on first boot.
The Core `dev.fedcom.net` was provisioned on 2026-12-03 in the VM
(10.123.0.10). It's reachable from the internet at 77.216.180.150
through corerelay, which also carries its outbound traffic.
What we learned provisioning (2026-12-02/03):
- Federated Core finds its public IP with `dig @resolver4.opendns.com
myip.opendns.com` and publishes it in DNS, so the Core's outbound traffic
must leave through the relay (first attempt published the home IP)
- The Core is the authoritative DNS server for its domain (ns1/ns2.<domain>
point at `ip`), so 53 tcp/udp must be forwarded, plus 25 143 465 587 993
4190 9980 besides 22 80 443
- The domain is picked round-robin (dev.federatedcomputer.cloud,
dev.federatedcomputer.net, dev.fedcom.net, ...)
- The progress stream from core-create is server-sent events; it takes 5+
minutes, a full install about 40
- Deleting a Core makes the platform SSH into its IP and tear it down, so
never put a new VM behind an IP whose old Core still exists. A failed Core
has no delete button; Federated has to remove it
- The Core's containers use 192.168.0.0/16 and send replies for any
192.168.x.x address onto their own bridge, so the VM network is
10.123.0.0/24 (moved there on 2026-12-03 from 192.168.123.0/24)
- libvirt's DHCP `<host>` reservations are ignored on this workstation:
libvirt writes the hosts file readable by root only and dnsmasq reads it as
`nobody`. The reservation is a `dnsmasq:option` in the network instead
- Before core-create on a fresh VM: `systemctl is-active docker`, opendns
sees the VPS IP, and the hairpin (`/dev/tcp/<vps-ip>/22` from the VM)
- [ ] The Core shows as Active in the dashboard
- [ ] Tell Federated (2026-12-03):
- On this image, disabling systemd-resolved isn't enough: networkd's
`systemd-networkd-resolve-hook.socket` starts it at boot, it takes
port 53 and pdns can't start after a reboot. coreapp-dev masks it
through cloud-init; the installer should mask it too
- Every Core timer (upgrade-federated, free-up-space, backuptool,
dumpcerts, fix-nextcloud, nextcloud-maintenance) has
`Requires=<its service>` in `[Unit]`, so its job also runs at every
boot, about 5 s in, not just on its schedule. Evidence (2026-12-03):
boots at 18:01:20 and 18:14:08 UTC; all four checked jobs started at
18:01:25 and 18:14:13. Consequences:
- upgrade-federated runs before the network is online (it has no
`After=network-online.target`): `git pull` fails with "Could not
resolve host: gitea.federated.computer", then `send_alert_upgrade`
emails ALERTS_EMAIL ("upgrade failed to run on <ip> - couldn't
pull from git") and posts a Matrix alert, and it exits 2
(`/federated/logs/upgrade.log`). So every reboot sends a false
alert
- free-up-space runs `docker system prune -f` and
`docker image prune -a --filter until=24h` while containers are
still starting: at 18:01:25 it deleted the pdns container that
had failed to start (port 53) and its image
(`/federated/logs/freeupspace.log`). Any app container that is
stopped at boot time goes the same way
- `/federated/bin/upgrade` has an API token in it, readable by anyone
with the image; `lib/functions.sh` has the monitoring registrar's
bearer token, and `uninstallapp`'s `set -x` prints it
- `bin/start` doesn't know apps outside its fixed lists, so a new
app in the generic format isn't started by `installapp`
## Next: the SDK (build, deploy and test an app on the Core)
### How the Core runs apps (studied 2026-12-03 on dev.fedcom.net)
- `/federated` is a git checkout of Federated's `Core` repo, updated by
`/federated/bin/upgrade` (`git pull`). Untracked folders survive pulls.
- Installed apps live in `/federated/apps/<app>/`: `docker-compose.yml`,
`.env` (mode 600), secrets in files, data under `data/`.
- Every container is on the external Docker network `core`
(192.168.0.0/16) with a fixed `ipv4_address`. Federated's apps use
192.168.0.7 to .121.
- traefik (`providers.docker`, `exposedByDefault=false`) routes by labels:
`traefik.enable=true`, `routers.<app>.rule=Host(`<app>.<domain>`)`,
`entrypoints=websecure`, `tls.certresolver=letsencrypt` (DNS challenge
through the Core's own pdns, so any hostname gets a certificate), and
`services.<app>.loadbalancer.server.port` when the port isn't 80.
- DNS: the zone has `*.<domain>` CNAME `www.<domain>` (the public IP), so
every app hostname already resolves. Some apps also add their own A record.
- `/federated/bin/installapp [-n] <app>` installs an app from either
- `lib/<app>.sh` with `config_<app>`, `start_<app>`, `uninstall_<app>` and
optionally `configsso_<app>` (Authelia OIDC) and `email_<app>`; or
- the newer generic format, `services/<app>/`:
- `service`: `NAME`, `DESCRIPTION`, `DOCS`, `CONTAINER`, `VERSION`,
`INTERNAL_IP`, `DEPENDS`, `PORTS`, `MONITOR="https://<app>.@DOMAIN@|http_2xx"`
- `docker-compose.yml.in` and `env.in`: templates. `@DOMAIN@` and other
variables from `/etc/federated`; `@IMAGE_VERSION@`;
`@NAME:RANDOM:LLLL...@` makes a random value (L = letter or digit)
- `icon.png`
- `install`: `. /federated/lib/helpers.sh` and `installGeneric <app>`
(fills in the templates into `/federated/apps/<app>/`); installapp
then runs `/federated/bin/start <app>`
- optional `uninstall`, `timers/`, `services/` (systemd units)
- installapp installs `DEPENDS` first; `uninstallapp <app>` reverses it.
- superpanel's catalog lists `services/*/service`, so an app installed this
way shows up in the Core's dashboard.
### Design (proposed)
An app is a folder in the generic format, kept anywhere on the workstation
(its own git repo). A `coreapp` command, run inside that folder, works
against the Core in the local VM (`coreapp-vm ip`):
- `coreapp new <name>`: scaffold the folder: `service`,
`docker-compose.yml.in` with the traefik labels, `env.in`, `install`, a
placeholder `icon.png`, a `Dockerfile` with a minimal web server, and a
README. Its `INTERNAL_IP` comes from 192.168.200.0/24, well away from
Federated's 192.168.0.x, and different for each app made on this machine.
- `coreapp deploy`: build the image locally (`docker build`), copy it to the
Core (`docker save | ssh docker load`, no registry needed), copy the folder
to `/federated/services/<name>/`, then `installapp -n <name>` the first
time. Later deploys re-render `docker-compose.yml` but keep `.env` (its
random secrets), and restart the app.
- `coreapp status`, `coreapp logs [-f]`, `coreapp shell`: on the Core.
- `coreapp check`: the app answers at `https://<name>.<domain>/` as its
`MONITOR` line says, with a valid certificate.
- `coreapp remove`: `uninstallapp <name>` and remove its services folder.
Built and tested 2026-12-03 with a test app `hello` (busybox httpd):
new, deploy (first install and redeploy), check, status, logs, remove all
work against dev.fedcom.net; `https://hello.dev.fedcom.net/` answers through
the relay.
What we learned:
- `/federated/bin/start <app>` only starts apps in the fixed `CORE_APPS` /
`EXTRA_APPS` lists in `lib/functions.sh`; for anything else it prints its
usage. So `installapp` installs a new app but doesn't start it, and
`start all` skips it. `coreapp deploy` starts it with the same
`docker compose ... up -d`; `restart: always` covers reboots
- `installapp` / `uninstallapp` call `update_monitors`, which registers or
removes the app's `MONITOR` URL with Federated's external monitoring
(blackboxregistrar.monitoreast.fedcom.net). Dev apps get registered too
- `uninstallapp` runs with `set -x`; its trace includes the monitoring
registrar's bearer token (in plain text in `lib/functions.sh`) and the
Core's email addresses. coreapp keeps the trace in
`~/.local/share/coreapp-dev/logs/` (mode 600)
- `uninstallapp` only stops a generic app if the app has an `uninstall`
script (sourced, so no `exit`); the template has one
- Decided 2026-12-03: apps in development are not registered with
Federated's monitoring. `coreapp deploy` drops `MONITOR` from the copy of
`service` on the Core
- [ ] Document the app format fully in the README (done in each app's README)
Databases (2026-12-03): `coreapp new --postgres <name>` adds
`DEPENDS="postgresql"`, DB_* settings in `env.in` (random password), an
`install` that creates the user and database on the Core's PostgreSQL
(`docker exec postgresql psql -U postgres`, as Federated's own installers
do) and an `uninstall` that drops them, and a Python example (psycopg)
that counts visits. Tested with `guest-book`: deploy, the count goes up,
a redeploy and a reboot of the Core keep the data, remove drops the database
and user. `postgresql.<domain>` resolves to the PostgreSQL container on the
`core` network (Docker's DNS); outside it, it's the public IP.
Sign-in (2026-12-03): `coreapp new --sso <name>`. Its `install` registers
the OIDC client `coreapp-<name>` in Authelia's `idproviders.yml` between
`### coreapp-<name> begin/end` markers (secret from `.env`, hashed with the
running Authelia's `authelia crypto hash generate pbkdf2`), checks the
result with `authelia validate-config`, restores the old file if that fails,
and restarts Authelia; `uninstall` removes the block. `installapp`'s
`apply_authelia_2fa_policy` then applies the Core's 2FA policy to it.
The app reaches `https://authelia.<domain>` through traefik
(`extra_hosts` to `@TRAEFIK_IP@`, which the template's `install` and
coreapp's redeploy both provide; Federated's apps use the public IP, which
here would loop out through the relay). The example is a standard-library
Python OIDC client (code flow with PKCE).
Tested with `sso-demo`: install, redeploy, remove and reinstall each leave
one (or no) client block, a valid config, and the other clients and
Nextcloud working; `/login` redirects to Authelia with PKCE.
A real sign-in to sso-demo with a Core account in a browser worked
(2026-12-03, tested by David).
- `bin/stop` and `bin/start` don't know apps outside Federated's lists, so
when a dependency (postgresql, authelia) is upgraded, coreapp apps keep
running instead of being stopped and restarted; they reconnect
Both together (2026-12-03): overlays no longer replace `service`; each
names the Core apps it needs in `.depends`, merged into `DEPENDS`. The
sign-in code is a module (`oidc.py`) any example imports;
`templates/postgres-sso` is the combined example (sign-in, each person's
visits in PostgreSQL). Tested with `team-visits`: database, Authelia client
`coreapp-team-visits`, `DEPENDS="postgresql authelia"`, `/login` to Authelia.
Signing in to team-visits and sso-demo (with the oidc.py code) in a browser
worked (2026-12-03, tested by David).
- [ ] Later: apps published for other Cores (registry, submitting to
Federated)
## SDK packaging
- [ ] Tag the first release once install and VM creation work end to end