# Administer a d.rymcg.tech server with drtctl Use this when the user wants a [d.rymcg.tech](https://github.com/EnigmaCurry/d.rymcg.tech) server built, changed, upgraded, backed up, or torn down, with the checkout and the `.env` files living on that host. The tool is `_scripts/drtctl/drtctl` in a checkout of this repository (`drtctl --help` lists the verbs). Human details are in `_scripts/drtctl/README.md`. The provider contract is `_scripts/drtctl/providers/README.md`. Follow the repo `AGENTS.md` as well: never overwrite an existing `.env_*`, and do not drive `make config`. DigitalOcean is the implemented provider. Pass `--provider digitalocean` (the default when the flag or the inventory `PROVIDER` is omitted). Do not invent a Proxmox or bring-your-own-SSH provider; those are later files under `providers/`. ## Starting from scratch Do not assume a DigitalOcean account, a domain, or an SSH key. Ask which of those three they already have, and only walk through what is missing. - **No DigitalOcean account.** Point them at [sign up](https://cloud.digitalocean.com/registrations/new). Say the cost first: about $6–$24/mo for the droplet, plus 20% when weekly backups are on (the default). Then they create an API token: control panel → API → Tokens → Generate New Token, with read and write. If this platform has a secret input, they put the token there. They do not paste it into the chat. `doctl` reads it as `DIGITALOCEAN_ACCESS_TOKEN`. - **No domain, or the domain is at another registrar.** They register a domain, or they set the existing domain's nameservers to `ns1.digitalocean.com`, `ns2.digitalocean.com`, and `ns3.digitalocean.com`, and add the zone under Networking → Domains. - **No SSH key.** They create one and share only the `.pub` file. Never the private key. Linux and macOS (OpenSSH): ```bash ssh-keygen -t ed25519 ``` The public key is `~/.ssh/id_ed25519.pub`. On Windows, the same command in PowerShell or Windows Terminal (install OpenSSH Client if `ssh-keygen` is missing); the public key is `C:\Users\\.ssh\id_ed25519.pub`. The file without `.pub` stays on their machine. When all three are ready, continue with the interview below, then `init`, `confirm-user-key`, `up-infra`, `bootstrap`, and `up-core`. ## Model The host is a self-contained sworkstation (the `_e2e` model). SSH in and run `make` / `d.rymcg.tech` there. Do not copy `.env` files off the host, and do not print their values, generated passwords, or tokens. Core verbs (`init`, `confirm-user-key`, `bootstrap`, `up-core`, `app-add`, `app-set`, `upgrade`, `health`, `ssh`, `export-env`, `rekey`) do not talk to a cloud API. `up-infra`, `status`, `backup-now`, `destroy`, and `storage-destroy` call `providers/.sh`. DNS is a provider hook: DigitalOcean creates records itself; a provider that does not own DNS leaves that to the operator. `drtctl` uses SSH with its own key. The DigitalOcean driver also uses `doctl` (`DIGITALOCEAN_ACCESS_TOKEN`). Per-server state is outside the repo: - `DRTCTL_STATE_DIR` (default `~/.local/share/drtctl`, or `$XDG_DATA_HOME/drtctl`) - `inventory/.env` — non-secret settings, `HOST`, `PROVIDER`, S3 fields, and provider ids (`DO_*` on DigitalOcean) - `ssh//` — the bot SSH key and `known_hosts` - `logs/` — scratch Set `DRTCTL_STATE_DIR` if the default is not the right place. The checkout must not contain a domain, host name, or key. An older inventory that still uses `DROPLET_IP`, `DOMAIN`, `SPACES_BUCKET`, and the other pre-provider names is read and rewritten into `HOST`, `DO_DNS_ZONE`, `S3_BUCKET`, and the `DO_*` ids. `S3_ENDPOINT` defaults to `https://.digitaloceanspaces.com` for the DigitalOcean provider. Weekly DigitalOcean backups are turned on at creation. `export-env` uploads to any S3-compatible endpoint (Spaces, AWS S3, MinIO, R2, B2) and refuses to run until the user's own age public key is in the inventory. Before asking anything, run `drtctl list` and `drtctl show `. Ask only for what is missing. ## Interview (ask only the gaps) Group the questions and offer the defaults, so the user can agree in one reply. 1. **Provider.** DigitalOcean unless they already said otherwise. `--provider digitalocean`. 2. **Server.** Short lowercase name (droplet name, tag `drtctl:`, Docker context). Region (default `nyc3`). Size (default `s-2vcpu-4gb`; say the monthly price). Image (default `debian-13-x64`). 3. **Domain.** A DigitalOcean-managed zone (`doctl compute domain list`) and a subdomain, or `@` for the apex. Apps are served as `.`. The registrar must delegate to DigitalOcean. `up-infra` checks this. `--domain` and `--dns-zone` are the same flag. 4. **TLS.** Wildcard via self-hosted acme-dns (the default). Production or staging Let's Encrypt (default production), and an optional notice email. 5. **SSH.** Port 22 is open to the world, key-only, with no source-IP allowlist. Ask for the user's own SSH public key (paste or a path). Both that key and the bot key are installed. 6. **Who can reach apps.** Traefik ipallowlist for new apps (default `0.0.0.0/0`). 7. **Timezone** (default `Etc/UTC`) and the git URL and ref to track (default upstream `master`). 8. **Backups.** Weekly window: `--backup-weekday` plus `--backup-hour` (`0 4 8 12 16 20` UTC), or one `--backup-window WEEKDAY:HOUR`. If they want an S3 export, collect their age **public** key during this interview, before any `export-env`. Walk them through creating it (below). An assistant age key is optional and is not a substitute. Spaces is `--spaces-bucket` and `--spaces-region` (stored as `S3_BUCKET`, `S3_REGION`, `S3_ENDPOINT`). Any other S3 endpoint is `--s3-bucket`, `--s3-endpoint`, `--s3-region`, `--s3-prefix`. 9. **Apps.** Which projects to install after the core, anything non-default (read the project's `.env-dist` on the host), and auth (none / basic / oauth2 / mTLS). Record the answers with `init` (re-runnable; it also creates the bot key): ``` drtctl init --provider digitalocean \ --domain D --subdomain S --region R --size Z --image I \ --user-pubkey "" --timezone TZ --acme-ca production --acme-email E \ --app-sourcerange CIDRS --backup-window SUN:4 \ --user-age-recipient age1... [--bot-age-recipient age1...] \ [--spaces-bucket B --spaces-region R] ``` ### The user's age key (before any export-env) Ask for this during the interview whenever an S3 export might be used. Do not run `export-env` until `init --user-age-recipient` has been recorded. Do not generate the key yourself, and do not keep the only copy. The user does this on their own machine: ```bash age-keygen -o key.txt age-keygen -y key.txt ``` `age-keygen -y` prints the public key (`age1...`). That is the only line they send. The private key is the contents of `key.txt` (`AGE-SECRET-KEY-1...`). They store that file in their password manager (KeePass or KeePassXC, 1Password, or Bitwarden, as a secure note or an attachment). It stays off the server. They never paste it into chat. If a private key shows up in chat, treat it as exposed: stop, tell them to generate a new key, and do not record the exposed one. `drtctl init` rejects `AGE-SECRET-KEY-` values. `--bot-age-recipient` (or the older `--age-recipients`) may add an extra recipient. `export-env` still refuses if `USER_AGE_RECIPIENT` is empty. To restore, on a machine that has the private key (not the host): download the object, then ```bash export SOPS_AGE_KEY_FILE=/path/to/key.txt sops --decrypt --input-type dotenv --output-type dotenv backup.sops.env > backup.env ``` or `d restore-env backup.sops.env` with `SOPS_AGE_KEY_FILE` set (SOPS also reads `~/.config/sops/age/keys.txt`). ## Safety Wait for a clear yes in chat. Every verb that changes infrastructure refuses to run without `--yes`. - **Before `up-infra`:** run `drtctl plan ` and show the size, region, and image, the monthly cost including weekly backups, every DNS record, every firewall rule, and both SSH key fingerprints. Then `drtctl up-infra --yes`. - **The user's key:** `init` prints the fingerprint. Ask if it is their key. Only after they say yes, run `drtctl confirm-user-key --fingerprint SHA256:...`. `up-infra` refuses until this matches. Changing the key clears the confirmation. - **`destroy`:** the user must type the server name. Pass that exact string to `--confirm-name`, and pass `--yes`. On DigitalOcean the droplet must carry the tag `drtctl:`. Do not destroy to retry a certificate: the acme-dns name is limited to 5 certificates per week. - **Backups are a separate question.** When the provider reports backups, `destroy` deletes them. On DigitalOcean that is the automatic droplet backups (deleted with the droplet when backups are enabled). S3 export objects are deleted only by `storage-destroy` (alias `spaces-destroy`). Do not fold that into the destroy yes. Ask, on its own: do they accept losing those backups? Suggest `backup-now` or `export-env` first if they need a copy that survives (snapshots from `backup-now` are kept when the droplet is destroyed; S3 objects are not removed by `destroy`). Only after a clear yes, add `--delete-backups`. Without that flag, `destroy` (when the provider reports backups) and `storage-destroy` refuse. - **`storage-destroy --yes --delete-backups`** empties and deletes the export bucket and the provider keys for this server, then clears `S3_BUCKET`, `S3_ENDPOINT`, and `S3_REGION`. It needs the same separate backup yes. `spaces-destroy` is the same command. - **The user's provider SSH key stays** unless they explicitly want it removed. Then pass `--delete-user-key`. On DigitalOcean the default is to keep `drtctl--user`. - **DNS, auth, TLS, routing:** `up-core` creates the `_acme-challenge` CNAME when the provider owns DNS, and needs `--yes`. `app-set` needs `--yes` for keys that match auth, TLS, host, port, source range, entrypoint, or profiles. Say the URL and who can reach a newly exposed app. - **Spend:** `backup-now`, resizing, extra volumes, or reserved IPs each need a yes and the price. - **Upgrades:** `drtctl upgrade ` is read-only. `drtctl upgrade --apply --yes` only after a yes. - No confirmation for `plan`, `show`, `list`, `status`, `health`, read-only `run` (`status`, `logs-out`, `dotenv_get`), or `DRTCTL_DRY_RUN=1`. - Never print `.env` values, generated passwords, tokens, or private keys. Never ask for an age private key. Only `age1...` public keys go in the inventory. Firewall from the DigitalOcean `up-infra`: inbound TCP 22, 80, 443; TCP and UDP 53; ICMP. The acme-dns API port 2890 stays closed. Traefik reaches it on the host. ## Which verb 1. `init --provider digitalocean`, then `confirm-user-key`. Optional check: `DRTCTL_DRY_RUN=1 drtctl up-infra --yes`. 2. `plan`. Get a yes. 3. `up-infra --yes` — keys, tag, firewall, droplet with weekly backups, DNS, wait for cloud-init. Idempotent. 4. `bootstrap ` — runs this checkout's `_e2e/lib/remote_bootstrap.sh` on the host, then writes the root `.env_`. 5. `up-core --yes` — acme-dns, Traefik wildcard, `_acme-challenge` CNAME, live certificate, whoami. Tell the user when `https://whoami.` works. 6. `app-add [instance] [KEY=VAL ...]`. A non-default instance is `-.`. Later changes: `app-set`. `app-add` sets `_INSTANCE` to the instance name when that variable exists and is blank. Day to day: `health` (report problems unless a full report was asked for), `run` for logs and `dotenv_get`, `upgrade` then `--apply --yes` then `health`, `backup-now --yes` before risky changes. `export-env --yes` only after the user's age public key is in the inventory and they have confirmed the upload. `rekey ` retires the bot key and prints the new public key and the commands the user runs with their own key. Wait until they say it is installed, then `status`. `rekey --update-do --yes` replaces the key stored in the DigitalOcean account (only for a later create or rebuild). `DRTCTL_DRY_RUN=1` prints mutating provider and `ssh` commands and does not create resources. `--delete-backups` is still required when backups would be deleted. Verbs are idempotent: fix the cause and re-run the same one.