- Python 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
backup restore wants --snapshot and the source's name typed; destructive flow steps (the incident rebuild) want the name typed even with --yes; the ceremony no longer takes the context's login for a root token; a context drops another infrastructure's address, mount and restic settings. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PVUe4g65L7UnUVqHmQp7kG |
||
| .forgejo/workflows | ||
| docs | ||
| src/infractl | ||
| tests | ||
| .gitignore | ||
| .gitleaks.toml | ||
| .pre-commit-config.yaml | ||
| .yamllint | ||
| CHANGELOG.md | ||
| CONTRIBUTING.md | ||
| LICENSE | ||
| pyproject.toml | ||
| README.md | ||
| SECURITY.md | ||
infractl
One operator tool for a belowtoxic-ansible
infrastructure: it selects the infrastructure you work on, gives every
command the right toolchain, OpenBao login and site repository, runs long
work as jobs that survive a closed terminal, and checks the workstation.
It guides the first run of a new infrastructure step by step (infractl bootstrap anchor, then infractl bootstrap idp); see the design.
Status: 0.4. Contexts, setup, doctor, status, login, ssh, run,
jobs, the helpers that used to live in the site repository's bin/ (key
ceremony, intent, WireGuard, backups, images), play, kv, and the guided
first run: the trust anchor (bootstrap anchor) and the identity provider
(bootstrap idp).
Install
Linux, Python 3.12+:
uv tool install git+https://git.belowtoxic.cloud/belowtoxic-ansible/infractl.git@v0.7.0
First steps
git clone https://git.belowtoxic.cloud/belowtoxic-ansible/infrastructure.git ~/src/infrastructure
infractl context add prod --site ~/src/infrastructure --ssh-identity ~/.ssh/ops
infractl setup # the toolchain the site repository pins, and its collections
infractl doctor # one line per check, with what to do on failure
infractl context set openbao https://bao.internal.example.com:8200 # once the anchor exists
infractl login # OIDC; the token is kept for this context only
infractl config pull # the intent from OpenBao, into this context's state
infractl ssh --list
infractl run --job -- infractl play idp # long runs as a job: survives a closed terminal
A new infrastructure
infractl context add prod --site ~/src/infrastructure --ssh-identity ~/.ssh/ops
infractl setup
infractl docs anchor | less # read it first: what you need, every step
infractl bootstrap anchor # asks, explains, runs, checks - stop any time, run it again to continue
infractl bootstrap idp # part 2: OIDC login, root token revoked, first backups
Each step shows what it does, why, what it needs and the commands it runs, asks before running them, and ends with a check. Secrets (the Hetzner token, DNS credentials) are asked without echo; the Hetzner token stays in memory and reaches only the commands that need it.
Contexts
A context is one infrastructure: a site repository (shared code), an OpenBao (that infrastructure's intent and secrets) and a private state directory. Every command first says which context it uses and why:
$ infractl status
infractl: context prod (selected with infractl use)
Which context, first match wins: -c NAME / INFRACTL_CONTEXT, then
infractl use NAME, then the site repository the current directory is in
(if only one context uses it), then the only context there is.
Commands run in a context get a scrubbed environment: an OpenBao address,
token or Hetzner token exported in your shell for another infrastructure
never reaches them. infractl never reads or writes ~/.vault-token.
Where things are
| Path | Content |
|---|---|
~/.config/infractl/contexts/<ctx>/context.yml |
settings, no secrets |
~/.config/infractl/current |
the context infractl use selected |
~/.local/share/infractl/contexts/<ctx>/ (0700) |
bao-token, intent/ (pulled intent), ssh/ (config, known hosts), jobs/, toolchain.json |
~/.cache/infractl/toolchain/<ref> |
toolchain checkouts; the built toolchain lives in ~/.cache/bt-ci |
Files with secrets are 0600 in 0700 directories; infractl doctor checks it.
Commands
| Command | |
|---|---|
context list|add|show|set|remove |
manage contexts (remove needs the name typed, or --confirm NAME) |
use [NAME] [--clear] |
select the context |
setup |
toolchain (bt-ci-setup of the pinned release) and collections |
doctor |
tools, permissions, toolchain pin, DNS, OpenBao state, login |
status |
context, OpenBao, login, jobs |
login [--method oidc] [-- skip_browser=true], logout |
OpenBao login per context |
ssh [--list] HOST [SSH OPTIONS] [-- COMMAND] |
SSH from the intent, without touching ~/.ssh |
config pull|validate|edit|diff|push |
the intent documents |
wg [--network N] list|add|config|update|rekey|isolate|revoke |
WireGuard members of a network (admin, services, monitoring, backup); client keys stay in the context's state; rekey replaces a leaked client key, isolate forgets a compromised host's key until it is re-created |
device add NAME [--text], device list, device remove NAME |
phones and tablets (role mobile: SSH and web, not OpenBao); the configuration is shown once as a QR code, the key never stored |
dns setup [--interface IF] |
send the internal zone to the anchor's resolver on the tunnel interface (systemd-resolved) |
bao init|unseal|root [--generate] |
OpenBao key ceremony, unseal, break-glass root token |
bao rekey|rotate|revoke-prefix |
after a compromise (site ADR 0009), with the root token from the shares: new unseal shares, a new barrier key, revoke every token under a prefix such as auth/oidc/ |
bao snapshot-pull |
copy the anchor's encrypted OpenBao snapshots |
backup run|status|restic|restore|drill |
restic backups of the anchor, the IdP and the mail servers; drill reads the newest snapshot back and checks it |
idp recover USER [MINUTES] |
a one-time recovery link for an Authentik user |
image flatcar |
upload a signature-checked Flatcar release as a Hetzner Cloud snapshot |
bootstrap anchor|idp|monitoring|backup|mail [--verify] [--from STEP] [--answers FILE] |
the guided first runs (anchor, IdP, monitoring host, backup coordinator, mail servers); resumable |
bootstrap hypervisor NAME |
(re)build a dedicated server as a hypervisor with its guests; the install step needs the name typed |
incident HOST [--verify] [--from STEP] [--docs], incident report HOST |
a compromised host or device (site ADR 0009): isolate, rotate, rebuild, restore, verify - built for that host, resumable, recorded with times |
docs FLOW |
a flow as a runbook (Markdown) |
mail dns [NAME] |
the DNS records a mail server's domains need, for the registrar |
play NAME [--bootstrap CIDR] [OPTIONS] |
a playbook of the site repository, with the context's intent and secrets |
kv put MOUNT/PATH KEY... / - |
a secret into OpenBao: values asked hidden or JSON on stdin |
kv escrow MOUNT/PATH --to R --out FILE |
an age-encrypted offline copy of a secret |
run [--job [--no-follow]] -- COMMAND |
a command in the context; --job detached |
jobs, logs [-f] [ID], cancel ID |
jobs (last is the newest) |
The helper commands pass everything after them through (infractl bao root --help). With --raw they run without a context, in the environment and
directory as they are: the site repository's bin/ scripts are such calls,
for playbooks, test scenarios and CI.
Questions are asked only on a terminal; in scripts, --yes answers them -
but never a destructive one, which needs --confirm NAME.
Development
eval "$(../toolchain/bin/bt-ci-setup)"
PYTHONPATH=src pytest -q
ruff check src tests && ruff format --check src tests && mypy --strict src
The tests run with their own HOME; they never touch your contexts or logins.
License
MIT