diff --git a/INSTALLATION.md b/INSTALLATION.md index bc837d8..38156c3 100644 --- a/INSTALLATION.md +++ b/INSTALLATION.md @@ -42,11 +42,45 @@ Copy `config.example.toml` and edit it. The important parts: | `[storage]` | Default guaranteed (`min`) and cap (`max`) home size, and the largest cap anyone may set (`limit`) | | `[[drives]]` | btrfs folders for home folders, each with a `reserve` kept free | | `[permissions]` | Starting permissions, copied in on first start only (see USERGUIDE.md) | -| `[cluster]` | Only for more than one node (see step 5) | +| `[cluster]` | Only for more than one node (see step 6) | -Secrets go in the environment rather than the file: `SLACK_APP_TOKEN`, `SLACK_BOT_TOKEN`, `CLUSTER_SECRET`, and any API keys used in `[agent_env]`. +## 4. Secrets -## 4. Run the bot +The Slack tokens from step 1 and the model API key are read from the bot's **environment**. Put them in a root-only env file, kept out of git and the Nix store: + +``` +sudo install -d -m 700 /etc/slackerbot +sudo install -m 600 /dev/null /etc/slackerbot/secrets +sudoedit /etc/slackerbot/secrets +``` + +```sh +SLACK_APP_TOKEN=xapp-… +SLACK_BOT_TOKEN=xoxb-… +ANTHROPIC_API_KEY=sk-ant-… +CLUSTER_SECRET=… +``` + +One `NAME=value` per line, with no quotes needed and no comments after a value (systemd would read the comment as part of the value). `CLUSTER_SECRET` is only needed with more than one node. + +| Variable | Overrides | Needed on | +|---|---|---| +| `SLACK_APP_TOKEN` | `[slack] app_token` | master | +| `SLACK_BOT_TOKEN` | `[slack] bot_token` | master | +| `CLUSTER_SECRET` | `[cluster] secret` | every node, if clustered | +| anything named in `[agent_env]` (e.g. `$ANTHROPIC_API_KEY`) | expanded into the container's env | master | + +The master refuses to start without both Slack tokens. You *can* write them into `[slack]` in the config instead, but then the config holds secrets. With NixOS, the config file is copied into the world-readable Nix store, so use the env file there. + +The bot writes the `[agent_env]` values, with `$VARS` expanded, to a root-only file under `state_dir/env/`, and bind-mounts it read-only into the container at `/var/lib/slackerbot/agent.env`, where goose reads it at start. To give goose another key, add it to the secrets file and reference it in `[agent_env]`: + +```toml +[agent_env] +GOOSE_PROVIDER = "anthropic" +ANTHROPIC_API_KEY = "$ANTHROPIC_API_KEY" +``` + +## 5. Run the bot ### NixOS @@ -60,7 +94,7 @@ imports = [ inputs.slackerbot.nixosModules.host ]; services.slackerbot = { enable = true; configFile = ./slackerbot.toml; - environmentFile = "/etc/slackerbot/secrets"; # SLACK_APP_TOKEN=…, SLACK_BOT_TOKEN=…, ANTHROPIC_API_KEY=… + environmentFile = "/etc/slackerbot/secrets"; # from step 4; a string path, so it stays out of the Nix store }; ``` @@ -69,17 +103,39 @@ The module runs the bot as a systemd service with `/var/lib/slackerbot` as its s ### Other Linux ``` -nix build git+https://gitea.skyg.ca/ari/slacker-bot.git#slackerbot # or: cd slackerbot && go build -sudo slackerbot -config /etc/slackerbot/config.toml +sudo nix build git+https://gitea.skyg.ca/ari/slacker-bot.git#slackerbot -o /opt/slackerbot # or: cd slackerbot && go build +``` + +Run it as a systemd service so the secrets file from step 4 is loaded. Save this as `/etc/systemd/system/slackerbot.service`: + +```ini +[Unit] +Description=slackerbot +After=network-online.target systemd-machined.service +Wants=network-online.target + +[Service] +ExecStart=/opt/slackerbot/bin/slackerbot -mode master -config /etc/slackerbot/config.toml +EnvironmentFile=/etc/slackerbot/secrets +StateDirectory=slackerbot +Restart=on-failure + +[Install] +WantedBy=multi-user.target +``` + +``` +sudo systemctl daemon-reload && sudo systemctl enable --now slackerbot +journalctl -u slackerbot -f ``` Make sure `systemd-networkd` manages `ve-*` links. systemd ships `80-container-ve.network` for this. `btrfs-progs` must be on the bot's `PATH`. Check the log for the node's capacity line and "connected to Slack", then DM the bot `help`. -## 5. More nodes (optional) +## 6. More nodes (optional) -1. On every node, set the same `[cluster] secret` (16+ characters), plus its own `system`, `[[drives]]` and `host_reserve`, and build the container system there. Slaves don't need Slack tokens or `agent_env`, because the master sends those. +1. On every node, set the same `[cluster] secret` (16+ characters), plus its own `system`, `[[drives]]` and `host_reserve`, and build the container system there. Slaves don't need Slack tokens or `agent_env`, because the master sends those, but each needs `CLUSTER_SECRET` in its own secrets file (step 4). 2. **Master:** set `cluster.listen = ":7946"` and open the port. On NixOS: `services.slackerbot.clusterPort = 7946`. 3. **Slaves:** set `cluster.master = "wss://:7946"` and a unique `cluster.name` (default: the hostname). Run with `-mode slave`. On NixOS: `services.slackerbot.mode = "slave"`. 4. The master logs its certificate fingerprint at startup. Put it in each slave's `cluster.master_fingerprint`. If you leave it empty, a slave trusts the first certificate it sees, saves it in `state_dir/master.fingerprint`, and refuses any other from then on.