kInit
One script takes a fresh Debian or Ubuntu install to a hardened, monitored server and checks every file it pulls from its own repository against a pinned manifest.
source (opens in new tab)The problem
Every new server starts the same way: set locale and timezone, install your SSH keys, harden SSH, install the usual packages, wire up monitoring, set up unattended maintenance. Doing it by hand is slow and inconsistent. Doing it with a pile of copy-pasted snippets is worse, because nobody remembers which snippet ran on which box.
kInit turns that ritual into one script with four modules (system, utilities,
software, miscellaneous), each switched on or off in kInit.vars. A fresh
Debian or Ubuntu install goes in, a box you can work on comes out, and every
box got there the same way.
Architecture
The first stage stays small. kInit.sh creates a private 0700 run
directory, downloads its helper library and a checksum manifest, checks both
against SHA-256 hashes embedded in the script, and only then runs modules.
Every file kInit later pulls from its own repository is checked against that
manifest. Optionally, minisign (a tool for signing and verifying files) adds provenance: a detached signature over the manifest, made with a signing key that never lives in the repository and checked against the public key pinned in kInit.sh, failing closed (aborting whenever a check can't complete) if minisign, the signature, or a match is missing.
Skipping any check takes an environment variable, an interactive terminal,
and typing I UNDERSTAND THE RISKS, so a piped one-liner or a CI job can't
skip verification just by inheriting a variable.
SSH hardening only starts once at least one valid key has landed in root's
authorized_keys; with no usable key, kInit logs a warning and leaves sshd
alone. With a key in place, root login defaults to prohibit-password and
password and keyboard-interactive authentication are switched off. The
changes go into /etc/ssh/sshd_config.d/00-kinit.conf when sshd includes
that directory, otherwise into a backed-up sshd_config, and kInit refuses
to reload sshd if sshd -t fails. Its command wrappers take argv arrays (argument lists passed to a program without shell parsing). Hostnames, ports, SSH keys, timezones, and cron entries are validated before
use, and analyze output and on-disk logs redact values that look like
credentials.
The utilities module installs update.sh and clean.sh as daily cron jobs.
Updates run a plain apt-get upgrade --with-new-pkgs, which never removes
packages, and keep existing config files. Cleanup vacuums the journal to
seven days, runs apt-get autoremove --purge for packages APT marks as
unneeded, and prunes dangling Docker images older than 24 hours. Every step
runs under timeout in its own session with stdin closed, so a stuck prompt
can't hang the cron job.
Monitoring means Zabbix Agent 2 from Zabbix's official APT repository, with
APT's normal key verification. The bundled per-distro zabbix.deb files are
the zabbix-release repository-configuration package, not agent binaries.
Analyze mode (--analyze) is for CI: kInit runs the full install, then
prints the redacted configuration, per-module results, and a verification
report before cleanup. --setup-profile-url swaps the module flow for an
external setup profile. Its bootstrap isn't in the manifest, so kInit
requires https:// and a SHA-256 pin; running it unpinned takes the same
typed acknowledgment as skipping checksums.
Boundaries
kInit configures a server; it doesn't manage one. No kInit process stays behind, and there's no drift detection and no reconciliation loop (a process that repeatedly restores declared state). Enforcing fleet state continuously is a job for configuration management.
The trust root is the first-stage script. Its embedded hashes protect the
repository files downloaded after it, so they're only as good as the copy of
kInit.sh you read; a piped one-liner trusts whatever the server sends.
minisign covers the gap between a file matching the script and a file coming
from its author, once you pin a public key you've verified out of band; it
stays off until you do.
The uninstaller is best-effort and says so. It restores kInit's config
backups, removes the SSH drop-in, kInit's files, and its cron jobs, and
reloads sshd only if the config still validates. Installed packages,
authorized keys, and the *.kinit-bak-* backups stay for you to review.