security: document bot-scoped steward access and key-only operator root
Rewrite the host-access runbook for the installed model: ubuntu may sudo into the bot accounts and run the docs/backup allowlist but has no root; operator holds NOPASSWD:ALL via its own SSH key; root SSH stays closed. Record the closed backup root path, the silent watchdog, verification commands, safe-mode recovery, and rollback. Update the fleet and backup pages to match.
This commit is contained in:
1 parent
f63096d4dc
commit
cd5960f62d
4 files changed
+154
-27
No files matched your search
@@ -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
|
||||
|
||||
|
||||
+130
-22
@@ -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-<bot>-nosudo`
|
||||
`<bot> 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.
|
||||
Reference in new issue
Block a user