@softure-ai/host
v0.2.0
Published
SOFTURE AI host CLI: provisions a shared app server on top of the softure.vps_foundation Ansible collection (Traefik edge, Cloudflare-only origin, deploy user) and onboards an app with one command (server folder, first deploy.sh, forced-command deploy key
Readme
@softure-ai/host
Provisions a server that hosts several apps and onboards each app onto it with one command. Ansible does the server
work, on top of the softure.vps_foundation collection; the CLI
validates the inventory, runs the playbooks it ships, and does what Ansible is awkward at: GitHub through gh and
Cloudflare through its API. Every command is idempotent and takes --check, which changes nothing anywhere.
It is the server side of the one-VPS model of @softure-ai/deploy: deploy covers
everything from the release on; host sets up the server and the app's place on it, once.
A server that already runs other apps (another Traefik, other names): read Adding an app to a server that already runs apps first.
npx --yes @softure-ai/host@<version> server --inventory=infra/inventory.yml --check
npx --yes @softure-ai/host@<version> server --inventory=infra/inventory.yml --connect-as=root # first run on a fresh server
npx --yes @softure-ai/host@<version> app add --inventory=infra/inventory.yml --app=notes
npx --yes @softure-ai/host@<version> operator add-key --inventory=infra/inventory.yml --app=notes --key=~/.ssh/notes-operator.pub
npx --yes @softure-ai/host@<version> survey --inventory=infra/inventory.yml # read-only: what the server runsRunning the CLI
The bin is softure-host. Run it from the operator's machine as the scoped package at a pinned version, from any
folder:
npx --yes @softure-ai/host@<version> <command> [flags]npx softure-host … finds the bin only inside a project that has @softure-ai/host installed; anywhere else npm
looks up an unscoped package named softure-host, which is not this one. The commands below are written as
softure-host <command> for short; the next step server prints is the full, pinned form.
Requirements on the operator's machine
- Node.js 22,
ansible-core2.14+ (ansible-playbook,ansible-galaxy),ssh, andghsigned in with admin rights on the app's repository. - An SSH login to the server as the admin user (key-based; Ansible cannot type passwords).
- For Cloudflare:
CLOUDFLARE_API_TOKENin the environment, scoped to the zone (DNS edit, Zone settings read, Access apps and policies edit). Without it the Cloudflare step is skipped with one line.
The CLI installs ansible/requirements.yml (the pinned softure.vps_foundation tag and its dependencies) into
~/.cache/softure-host/<version>/collections before every run, so the pinned release is the one that runs. Nothing
the CLI handles is stored: secrets go to gh on stdin, the issued deploy key exists only in memory and in GitHub.
The inventory
One YAML file per server, on the operator's machine or in a private infrastructure repository, never in an app repository. Every shared name has a generic default, so no app's name leaks into another app.
server:
host: srv.example.com # SSH host
ipv4: 203.0.113.10 # for the Cloudflare DNS record and DEPLOY_ORIGIN_IP
adminUser: admin # sudo, used by Ansible (the collection's vps_app_user)
adminPublicKey: ~/.ssh/id_ed25519.pub # the key the admin logs in with (see "server" below)
deployUser: deploy # no sudo, releases only
edge:
acmeEmail: [email protected]
cdn: cloudflare # or none
apps:
- slug: notes
repo: acme/notes
host: notes.example.com
database: true
access: { enabled: true, bypassPaths: [/api/mcp, /api/oauth/token], emails: [[email protected]] }| Field | Default | What it is |
| --- | --- | --- |
| server.port | 22 | SSH port |
| server.ipv4, server.ipv6 | none | the server's addresses; ipv4 is required for Cloudflare DNS, ipv6 adds an AAAA record |
| server.identityFile | none | private key for the admin connection, when the SSH agent does not hold it |
| server.deployUser | deploy | the non-sudo user releases log in as; must differ from adminUser |
| server.timezone | UTC | system time zone |
| edge.name | softure-edge | the edge's compose project and folder (/srv/<name>) |
| edge.network | edge.name | the Docker network apps join as external (softure-deploy init --edge, #516) |
| edge.certResolver | letsencrypt | the ACME resolver apps' routers name |
| edge.manage | true | false: an edge that already exists (under other names) is used as it is, never touched |
| edge.acmeEmail | none | required when edge.manage |
| edge.cdn | none | cloudflare: trusted proxy ranges, origin firewall, DNS and Access |
| firewall.manage | edge.manage and cdn: cloudflare | install the Cloudflare-only origin firewall |
| firewall.name | softure-cloudflare-only | script and systemd units |
| firewall.rangesFile | /srv/<edge.name>/cloudflare-ips.txt | the ranges the firewall reads, refreshed daily by a timer |
| apps[].database | false | generate POSTGRES_PASSWORD, SOFTURE_MIGRATOR_PASSWORD, SOFTURE_APP_PASSWORD when missing |
| apps[].access | disabled | Cloudflare Access for the whole host (emails), plus one bypass per path: bypassPaths and the publicPaths of the app's deploy.json |
The deploy user never has sudo. The inventory refuses deployUser equal to adminUser, and both playbooks
first read the deploy user on the server and stop, before any change and in --check too, when it is in sudo,
wheel or admin or has a sudoers entry: the collection's deploy_user role locks its password, which would take
password sudo from an admin account (#1431). On a first onboarding, where the deploy user does not exist yet,
app add --check reports the user, its authorized_keys and the key line as planned changes.
An edge another app already runs (say a network first-app-edge with the resolver le): set edge.network,
edge.certResolver and edge.manage: false, and app add onboards new apps onto it. Moving the edge out of that
app is that app's own change.
softure-host server
softure-host server --inventory=<file> [--check] [--connect-as=<user>]Runs ansible/server.yml: softure.vps_foundation.vps_bootstrap (admin user with sudo, SSH hardening without root
or passwords, UFW on 22/80/443, fail2ban, unattended upgrades, Docker with the compose plugin and the edge network),
then the collection's shared-edge roles:
deploy_user: the deploy user, indocker, never insudo.traefik_edge(whenedge.manage): Traefik in its own compose project, label routing withexposedByDefault=false, HTTP → HTTPS, the ACME resolver, Cloudflare's ranges as trusted proxies behind Cloudflare.cloudflare_origin(whenfirewall.manage): only Cloudflare reaches ports 80/443 (DOCKER-USER, since UFW does not filter published container ports), ranges refreshed by a systemd timer.
server.adminPublicKey becomes the admin user's only authorized key (the collection writes it exclusively): it
must be the key you log in with, or the run locks you out. sshd's AllowUsers gets the admin and the deploy user.
On a fresh server, --connect-as=root (or ubuntu) logs in as the provider's first user; after the first run, log
in as the admin user. The bootstrap adds the server's host key to your known_hosts on first contact.
softure-host app add
softure-host app add --inventory=<file> --app=<slug> [--check] [--rotate-key]In order:
Preflight, before any change and in
--checktoo (issue #1432). Over your admin SSH connection the CLI runs the read-only probe ofsurvey, reads the app'sdocker/prod/docker-compose.yml, and stops, listing every problem, when:- a Traefik that is not the inventory's own edge (compose project
edge.name) runs whileedge.manageistrue; - the inventory's
edge.networkdoes not exist on the server (the message lists the networks that do); - the compose file joins external networks of which none is
edge.network: a literal name, or a variable's default.${EDGE_NETWORK:-…}passes, sinceapp addsetsEDGE_NETWORK(step 4); - a router's
traefik.http.routers.<router>.tls.certresolverlabel (on a service or underdeploy.labels, variables resolved like compose) names another resolver thanedge.certResolver(issue #1429): the edge runs only that one, so Traefik would issue no certificate for the app.
When the admin cannot read Docker (not installed, no
dockergroup, no passwordless sudo) the edge checks are skipped with one line.- a Traefik that is not the inventory's own edge (compose project
GitHub Environment.
productionis created with the deployment policy "v*tags" before anything reads its secrets (a dry run against a repository without it reads nothing under it).Server (
ansible/app.yml, as the admin user):/srv/<slug>owned by the deploy user, the first copy of the app'sdocker/server/deploy.shfrom its default branch (never overwritten: releases replace it), and the release key linecommand="/srv/<slug>/deploy.sh",restrict <key> <slug>-releasein the deploy user'sauthorized_keys, added or replaced in place, never duplicated, other apps' lines untouched. When sshd'sAllowUsersis set without the deploy user (a serverservernever provisioned), the playbook adds/etc/ssh/sshd_config.d/60-softure-host-<deployUser>.confwithAllowUsers <deployUser>(AllowUsers lines add up, so nobody else loses access), checks it withsshd -tandsshd -T, and reloads sshd; a drop-in sshd refuses is removed again. ADenyUsers,DenyGroupsorAllowGroupsthat would still turn the deploy user away stops the run before any change and names the step left to you: those lists decide who else may log in.Host keys. Read over your own admin SSH connection (checked against your
known_hosts, not a blindssh-keyscan); their fingerprints are printed.GitHub secrets (Environment
production):DEPLOY_SSH_HOST,DEPLOY_SSH_USER,DEPLOY_SSH_KNOWN_HOSTS,DEPLOY_SSH_KEYwhen issued,DEPLOY_ORIGIN_IPbehind Cloudflare, the three database passwords only when missing (a new password locks the app out of an existing volume); the repository variablesAPP_HOSTandEDGE_NETWORK(the inventory'sedge.network, which a compose file fromsofture-deploy init --edgejoins at deploy time; issue #1429).Cloudflare (with
edge.cdn: cloudflareandCLOUDFLARE_API_TOKEN): a proxied A (and AAAA) record, a check that the zone's TLS mode is Full (strict) (reported, not changed: it is zone-wide), and the Access applications<slug> (softure-host)for the host'semailsand<slug> bypass <path> (softure-host)per bypass path, created or updated by name. Applications it did not create are never touched, and none is deleted: one the inventory no longer lists is reported. The bypass paths are the inventory'sbypassPathsplus thepublicPathsof the app'sdeploy.jsonon its default branch (issue #1435): each path taken frompublicPathsis printed, and an inventory path thatpublicPathsdoes not list is a warning (add it topublicPathsif it must answer without a login). WithoutpublicPaths, or with adeploy.jsonthat cannot be read, onlybypassPathsis used and one line says so.What is left: the names the app's
docker/prod/docker-compose.ymlrequires that are set nowhere yet (the app's own secrets, such as mail API keys), then the next step: run the app's release workflow. A name counts as set when it is aproductionsecret, a repository orproductionvariable, or oneapp addhas just written (such asAPP_HOST), since the release renders.env.prodfrom secrets and variables alike (issue #1434).
A deploy key is issued (ed25519, made in memory) when the Environment has no DEPLOY_SSH_KEY, or with
--rotate-key. Otherwise the server's line stays as it is; when the server has no line while GitHub holds a key,
the run stops and asks for --rotate-key.
The app must already have run softure-deploy init (it needs docker/server/deploy.sh): in the app,
npm install --save-dev @softure-ai/deploy, then npx softure-deploy init ….
Running operator commands
An app's operational commands (status, cleanup, and with a database the ops scripts and SQL reports of
softure-deploy run and report) run on the server
through the same forced command as a release: a key in the deploy user's authorized_keys that can only start
/srv/<slug>/deploy.sh. The release key belongs to GitHub; the operator binds a key of their own.
A key for this app. One per app and machine, never the admin key (sshd takes the first line that matches a key, so one key cannot serve two lines):
ssh-keygen -t ed25519 -f ~/.ssh/notes-operator -C "$USER@$(hostname)"Bind it (as the admin user, through Ansible, like
app add):softure-host operator add-key --inventory=<file> --app=notes --key=~/.ssh/notes-operator.pub [--name=laptop] [--check]It writes
command="/srv/notes/deploy.sh",restrict <key> notes-operator-<name>(--namedefaults todefault; lower-case letters and digits, one label per machine). A second run with the same name replaces that line in place, never duplicates it; the release key line, other apps' lines and lines added by hand are never touched. It refuses a file that is not one public key line (a private key, a line with options in front), a key already on another line of the file, and an appapp addhas not set up.--checkprints the line and changes nothing.Use it. The command prints the ssh line and what
deploy.shaccepts:ssh -i ~/.ssh/notes-operator [email protected] status ssh -i ~/.ssh/notes-operator [email protected] cleanup --keep=2Any other command, and a login without one, reaches
deploy.sh, never a shell;restrictturns off port, agent and X11 forwarding and the terminal. Forsofture-deploy runandreport, name the user and the key in~/.ssh/configand pass the alias as--host:Host notes-prod HostName srv.example.com User deploy IdentityFile ~/.ssh/notes-operator IdentitiesOnly yes
softure-host operator list --inventory=<file> --app=notes # labels and fingerprints, read only
softure-host operator remove-key --inventory=<file> --app=notes --name=laptoplist reads the file over your admin SSH connection (sudo -n cat) and flags a notes-operator-* line that lacks
the forced command or restrict (one edited by hand): re-add it with add-key. Whoever holds such a key can run
every command deploy.sh accepts, a deploy of any image included: give one to each person who operates the app, and
remove it when they stop.
softure-host survey
softure-host survey --inventory=<file>Logs in as the admin user and prints what an inventory for the server needs, changing nothing: the OS and Docker
versions, whether the admin has passwordless sudo, the users with their groups and sudo rights, sshd's
AllowUsers/AllowGroups (and DenyUsers/DenyGroups, with drop-ins, from sshd -T), running Traefik containers
with their compose project, networks, entry points and certificate resolvers, the Docker networks, the folders under
/srv, and whether the Cloudflare-only firewall is installed. When an edge that is not the inventory's own runs, it
ends with the edge: block to paste:
edge:
manage: false
network: first-app-edge
certResolver: leOnly the server's connection (server.host, port, adminUser, identityFile, deployUser) is needed; apps may
be empty. Root-only reads go through sudo -n; without passwordless sudo they are reported as partial.
Adding an app to a server that already runs apps
On a server other apps already use, with an edge softure-host did not set up:
- Run
softure-host survey --inventory=<file>with only theserver:block filled in. - Set
edge.manage: falseand theedge.networkandedge.certResolverthe survey found (paste itsedge:block). Leavefirewall.manageoff unless the firewall is yours to manage. - Never run
softure-host serveron such a server. It rewrites the SSH hardening, sshd'sAllowUsersand the admin's authorized keys for everyone;app adddoes what onboarding needs (the deploy user, its sshd access, the app folder). - Use a dedicated deploy user without sudo (
server.deployUser, defaultdeploy), never the admin or a user the other apps share; both commands refuse a deploy user with sudo rights. softure-host app add --inventory=<file> --app=<slug> --check: the preflight reports any contradiction between the inventory, the server and the app's compose file, and Ansible's check mode lists the changes.softure-host app add --inventory=<file> --app=<slug>.- The first release from the app's own pipeline.
What stays manual
- Buying the server and the domain; the first SSH key on the server.
- Credentials only the owner holds: the admin SSH login,
ghwith admin rights, the Cloudflare token. - The app's own secrets (listed by
app add, never invented). - Releases: the app's own pipeline. Removing an app (
app remove) and backups off the server are later work.
Tests
npm test covers the inventory, the Ansible command lines and variables, the key format and the public key checks,
the GitHub and Cloudflare calls and every command with fakes. e2e/converge.sh (CI job host-ansible) converges
ansible/app.yml against an Ubuntu container twice and logs in with the issued key through the forced command, then
runs ansible/operator.yml: one line per label, other lines byte-equal, the operator key reaching only deploy.sh,
--check changing nothing, a key another line holds refused, remove-key removing only its line. Its sshd starts with AllowUsers root, as on a server server never
provisioned, so the test also proves the AllowUsers drop-in, the AllowGroups refusal, and that survey (the CLI
over SSH) changes nothing.
