diff --git a/README.md b/README.md index 0593e91..b72f8b2 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ Read it on the web here: | `maintenance/librechat-sandbox.md` | Operating the LibreChat evaluation instance (config, overlay image, key sync, pitfalls) | | `maintenance/model-transitions.md` | Repoint vs rename when a provider retires or replaces a model: the spend-log measurement that decides it, the aliases and factor keys that must move with the pointer, the picker that only needs touching on a rename, and verification by spend row rather than HTTP 200 | | `maintenance/backups.md` | The two backup systems (agent-host restic + Cloudron app backup): schedules, retention, the cache split and the grouping fix | +| `maintenance/host-access.md` | Agent-host privilege model: bot accounts, steward bot access, key-only operator root, root-trust watchdog, and safe-mode recovery | | `maintenance/woodpecker-ci.md` | The self-hosted CI server and agent: build/pin, manual-only trigger, git-lfs, and its not-yet-green state | | `maintenance/provisioning-boundary.md` | Which Open Collective contributors auto-provision as members and which are deliberately excluded (org-backed, credit-pack, manual, hidden-email), plus the daily paid-but-unprovisioned watchdog | | `maintenance/2026-11-08-litellm-1.108.0-librechat-1.4.8.md` | The Sunday-evening upgrade-window runbook (gateway → 1.108.0, chat overlay → appstore 1.4.8): candidates, order, exact commands, per-step verification, rollback, window estimate | diff --git a/agent-fleet.md b/agent-fleet.md index abf7cc9..c1ed7f4 100644 --- a/agent-fleet.md +++ b/agent-fleet.md @@ -21,9 +21,10 @@ app) that all three draw on — the agent host runs no gateway of its own. ### Who is who (do not conflate them) - **Inferencebot** is the **steward** and the fleet administrator: full Cloudron - token, gateway master key, member-data plumbing. Root access is restricted to - the docs/backup service commands in `maintenance/host-access.md`; it is NOT a - member-facing chat persona. + token, gateway master key, member-data plumbing. It can act inside the bot + accounts (`sudo -iu socialbot`, and so on) and run the docs/backup service + commands in `maintenance/host-access.md`, but it has **no root**. Root belongs + to the separate `operator` account; it is NOT a member-facing chat persona. - **infrastructure-bot** is a **lower-privileged** infrastructure agent. Per its own SOUL it has **no sudo, no Cloudron admin token, and no member data**; when a task needs more privilege it hands up to the steward rather than working around @@ -32,6 +33,16 @@ app) that all three draw on — the agent host runs no gateway of its own. Matrix rooms; its only writable surface is the `#social-drafts` room, and it **never publishes an unapproved draft** — silence is its correct failure mode. +## Fleet access + +- **Bots have no sudo.** Each bot account carries `ALL=(ALL) !ALL`; its home is + mode `0700` and owned by the bot. +- **The steward can enter bot accounts**, and that is how fleet maintenance + happens: `sudo -iu ...`. It cannot enter root. +- **Root is a human door.** SSH as `operator` with a key, then `sudo -i`. Root + SSH login stays closed, and no account has a password login. The account and + its sudoers rules are documented in `maintenance/host-access.md`. + ## Working-group bots — one Unix user each **Policy (2026-11-17; supersedes the tier-2 profile plan in co-op/support#33).** diff --git a/maintenance/backups.md b/maintenance/backups.md index 4a94983..c3c9f91 100644 --- a/maintenance/backups.md +++ b/maintenance/backups.md @@ -12,7 +12,7 @@ mistake — they do not back each other up, and neither one covers the other's h | Target | Infomaniak **Swiss Backup** (S3-compatible) | Infomaniak **Swiss Backup** (S3-compatible, `s3-v4-compat`) | | Schedule | 04:30 UTC + up to 5 min jitter (`agent-backup.timer`) | daily 23:00 UTC (`00 00 23 * * *`) | | Retention | 7 daily / 4 weekly / 3 monthly, no grouping | 7 days (`keepWithinSecs: 604800`) | -| Config lives | `~/.hermes/scripts/backup.sh`, unit at `/etc/systemd/system/agent-backup.*` | Cloudron dashboard (no write API — see below) | +| Config lives | installed as `/usr/local/sbin/agent-backup` (root-owned) from `~/.hermes/scripts/backup.sh`; unit at `/etc/systemd/system/agent-backup.*` | Cloudron dashboard (no write API — see below) | | Last verified | 2026-11-04 (13 snapshots in the repo) | 2026-11-02 (runs 2026-10-30 → 11-03 all `normal`, ~5.4 GB) | Nothing on the Cloudron **host OS** is backed up by either system (netplan, sshd, @@ -23,7 +23,8 @@ it. This was the migration's central caveat and it still holds. ## 1. Agent-host backup (restic) -`agent-backup.timer` → `agent-backup.service` → `~/.hermes/scripts/backup.sh`. +`agent-backup.timer` → `agent-backup.service` → `/usr/local/sbin/agent-backup`, +a root-owned installed copy of `~/.hermes/scripts/backup.sh`. - **The unit runs as `User=root` on purpose.** The agent homes under `/home/*` are mode `0700`, so only root can enumerate them; `ubuntu` sees `EACCES` and a @@ -41,6 +42,12 @@ it. This was the migration's central caveat and it still holds. - **Failure is visible, not silent.** On failure the script appends a note to `~/.hermes/cron/updates_notes.jsonl`, which the daily stewarding digest reads. Exit codes: 0 ok, 1 config, 2 backup, 3 prune. +- **Root trust.** The installed copy runs with root-owned `restic`, does not put + `/home/ubuntu/.local/bin` on `PATH`, and does not source + `/home/ubuntu/.hermes/.env`. Credentials come only from root-only + `/etc/agent-backup.env`, so no agent-writable file is executed as root. + Verified 2026-11-21: `check_root_trust.py` is silent and a manual timer run + completed with `backup: ok`. ### Deliberate-but-surprising: the PER-USER restic cache split diff --git a/maintenance/host-access.md b/maintenance/host-access.md index 45d7a78..c511749 100644 --- a/maintenance/host-access.md +++ b/maintenance/host-access.md @@ -1,37 +1,145 @@ -# Agent host root access +# Agent host access -The steward agent (`ubuntu`) does **not** have passwordless root for arbitrary commands. The cloud-init `ubuntu ALL=(ALL) NOPASSWD:ALL` rule was removed on 2026-11-20. +The agent host (`ov-0f018e`, an Infomaniak VPS Lite instance) separates three +levels of privilege: the bots, the steward, and the human operator. -## What `ubuntu` may run without a password +## The model -`/etc/sudoers.d/90-inferencebot-restricted` allows only: +| Account | Role | Privilege | +|---|---|---| +| `socialbot`, `infrabot`, `designbot`, future working-group bots | agents | own Unix user, own gateway unit, **no sudo at all** | +| `ubuntu` | steward agent (Inferencebot) | may act inside the bot accounts and run the docs/backup service commands; **no root** | +| `operator` | human operator | own SSH key, full `sudo` (`NOPASSWD:ALL`); root SSH login stays closed | -- `systemctl start|stop|restart docs-deploy-poll.service` -- `systemctl start|restart agent-backup.service` -- `systemctl start|restart agent-backup.timer` -- `journalctl -u docs-deploy-poll.service ...` +The steward is the fleet administrator, not a root user. Root belongs to a +person: the operator signs in as `operator` with an SSH key and escalates +deliberately with `sudo -i`. -Everything else — package installs, user management, file writes under `/etc`, arbitrary shells — requires operator credentials or a new root-owned helper. Do not re-add `NOPASSWD:ALL` to make a task convenient. +### sudoers files + +- `/etc/sudoers.d/91-bot-access` + `ubuntu ALL=(socialbot,infrabot,designbot) NOPASSWD: ALL` +- `/etc/sudoers.d/90-inferencebot-restricted` + `ubuntu` may only start/stop/restart `docs-deploy-poll.service` and + `agent-backup.service`/`.timer`, and read `docs-deploy-poll` logs. +- `/etc/sudoers.d/90-operator` + `operator ALL=(ALL) NOPASSWD:ALL` +- `/etc/sudoers.d/90--nosudo` + ` ALL=(ALL) !ALL` — each bot is denied sudo, including via its own + account. + +Do not re-add the old cloud-init `ubuntu ALL=(ALL) NOPASSWD:ALL` rule. The +steward must not regain root, and the operator account is the root door. + +### No passwords + +- `ubuntu` and the bot accounts are password-locked (cloud image + `lock_passwd: True`); SSH password authentication is disabled + (`/etc/ssh/sshd_config.d/60-cloudimg-settings.conf`). +- Access is SSH public keys only. Do not set a password on `ubuntu`, a bot, or + `operator` as a convenience. +- `operator`'s key is copied from `/home/ubuntu/.ssh/authorized_keys` when the + account is created. If the operator's key rotates, update **both** + `/home/ubuntu/.ssh/authorized_keys` and + `/home/operator/.ssh/authorized_keys`. +- Root SSH login is not authorized; do not add root authorized keys. ## Root-owned execution paths -- The docs publisher is split: `/usr/local/sbin/docs-poll` and `/usr/local/sbin/docs-publish` are root-owned; the build runs as `docsbuild` without credentials. -- The nightly backup runs as root from **`/usr/local/sbin/agent-backup`** via an `agent-backup.service` drop-in. The script is root-owned; the agent's `~/.hermes/scripts/backup.sh` is no longer executed by the unit and must not be treated as root code. -- Backup credentials live in root-only `/etc/agent-backup.env`. +- **Docs publisher.** `/usr/local/sbin/docs-poll` and `/usr/local/sbin/docs-publish` + are root-owned; the build runs as `docsbuild` with a scrubbed environment. +- **Nightly backup.** `agent-backup.service` runs as root with + `ExecStart=/usr/local/sbin/agent-backup`, a root-owned copy of + `~/.hermes/scripts/backup.sh`. The source script stays editable by `ubuntu`, + but the unit executes the installed root-owned copy. + `/usr/local/bin/restic` is `root:root`. +- **Backup credentials.** `RESTIC_PASSWORD`, `RESTIC_REPOSITORY`, + `SWB_S3_ACCESS_KEY`, `SWB_S3_SECRET_KEY` live only in root-only + `/etc/agent-backup.env` (0600). The root script must not source + `/home/ubuntu/.hermes/.env` and must not put `/home/ubuntu/.local/bin` on its + `PATH`; either would make an agent-writable file a root code-execution path. +- **Watchdog.** `check_root_trust.py` (daily cron) stays silent when healthy and + alerts if broad sudo returns, `sudo -n true` succeeds, a root-executed binary + is agent-owned, or a root script trusts agent files. It is silent as of + 2026-11-21. -## Residual root-trust gap (operator root required) +Any new root-executed script that reads an agent-writable file is a root path. +Audit it before installing it as root code. -The root-owned backup script still resolves `restic` from `/usr/local/bin/restic`, which is owned by `ubuntu`, and it still sources `/home/ubuntu/.hermes/.env`. An agent-writable binary or `PATH` line there is therefore a root code-execution path through the nightly backup timer. Until root fixes it: +## Verification -- `chown root:root /usr/local/bin/restic` (or install a root-owned copy and call it absolutely) -- remove `/home/ubuntu/.local/bin` from the root script’s `PATH` -- stop sourcing `/home/ubuntu/.hermes/.env` from the root script -- remove the Hermes-python `pip list` diagnostic +Run from an operator session: -This requires root outside the agent; the restricted sudo policy does not grant it. Treat the backup timer as privileged until fixed. +```bash +# steward: bot access, no root +sudo -iu socialbot id # uid=1002 +sudo -iu infrabot id # uid=1001 +sudo -iu designbot id # uid=1003 +sudo -n true # must fail: interactive authentication required +sudo -n /usr/bin/id # must fail -A daily root-trust watchdog (cron `82130f968506`, `check_root_trust.py`) stays silent when healthy and alerts if broad sudo returns, the root backup script starts trusting agent files again, or `/usr/local/bin/restic` is not root-owned. +# operator: root door +sudo -n true && echo root-ok # root-ok +sudo -i -## Recovery (operator only) +# root-trust watchdog: silence is the pass +python3 ~/.hermes/scripts/check_root_trust.py +``` -The pre-change cloud-init sudoers file is preserved at `/root/sudoers-cloud-init.bak` (0600). Restoring it requires root access outside the agent, e.g. the provider console. Do not expose it to the agent. +## Recovery when root is unreachable + +If sudo policy or the operator key is wrong, or no in-band root remains, use the +provider's rescue environment. On Infomaniak VPS Lite it is called **Safe mode**, +not "Rescue". + +1. Manager → **VPS** → the server → **MANAGE** → **Restart the server (Safe + mode)**. Services stop while it is booted. +2. Connect to the rescue image as user `infomaniak` (temporary rescue password + from the panel if SSH asks). The rescue image has a different host key, so + use `-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no` for this + session only. Then `sudo -i`; confirm `id -u` is `0`. +3. Identify the disks with `lsblk -f`. The rescue system is the first disk + (root partition hostname `ik-rescue`). The cloud disk is the second disk; its + root partition is labelled `cloudimg-rootfs`, usually `/dev/sdb1`. Mount it: + + ```bash + mount /dev/sdb1 /mnt + cat /mnt/etc/hostname # must print ov-0f018e + ``` + + If it prints `ik-rescue` or the file is missing, unmount and mount the + `cloudimg-rootfs` partition instead. +4. Run the staged recovery script, kept on the cloud disk: + + ```bash + less /mnt/home/ubuntu/recover.sh # inspect first + bash /mnt/home/ubuntu/recover.sh + ``` + + It backs up the current sudoers files to + `/mnt/root/pre-recovery-YYYYMMDD/`, writes the bot-access and operator rules, + ensures the operator user and key, closes the backup root path, and runs + `visudo -c`. Do not unmount `/mnt` while it runs. +5. `umount /mnt`, then **MANAGE → Restart the server (Classic mode)**. +6. Verify with the commands above. The normal SSH host key returns after the + classic boot. + +A narrative handoff of the same procedure, with no credentials, is kept at +`/home/ubuntu/recovery-context.txt` on the host. + +### Rollback + +- Previous sudoers files: `/root/pre-recovery-YYYYMMDD/` on the cloud disk. +- Original cloud-init sudoers: `/root/sudoers-cloud-init.bak` (0600). +- Provider snapshots are the outer rollback. +- Restoring the broad cloud-init rule is **not** the intended end state; it is + only a temporary recovery step while a narrower rule is installed. + +## Things not to do + +- Do not restore `ubuntu ALL=(ALL) NOPASSWD:ALL`. +- Do not set a password on any account; keep access key-based. +- Do not use the backup unit's agent-owned binary, `PATH`, or `.env` as a + shortcut to root; that is the hole, not a recovery channel. +- Do not run a root-owned unit against agent-writable files without a root-trust + review.