feat(templates): add starter runbook workspace (#5)
Document the notebook format and provide SSH-key, hardening-check, and package-install examples with inventory and credential exclusions.
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
---
|
||||
title: Base hardening checks
|
||||
params:
|
||||
host: { type: host, required: true, label: Target server }
|
||||
---
|
||||
|
||||
# Base hardening checks
|
||||
|
||||
Read-only baseline for Debian servers. These checks report state; they do not
|
||||
change configuration. A failed check needs investigation, not an automatic fix.
|
||||
SSH configuration checks need passwordless sudo to read all included files.
|
||||
|
||||
```sh {check host="{{host}}" id=os title="Identify operating system" capture=os_id}
|
||||
. /etc/os-release
|
||||
printf '%s\n' "$ID"
|
||||
```
|
||||
|
||||
```sh {check host="{{host}}" id=no-root-password title="Root password login disabled" sudo}
|
||||
sshd -T | grep -Eq '^permitrootlogin (no|prohibit-password|without-password)$'
|
||||
```
|
||||
|
||||
```sh {check host="{{host}}" id=no-password-auth title="SSH password authentication disabled" sudo}
|
||||
sshd -T | grep -qx 'passwordauthentication no'
|
||||
```
|
||||
|
||||
```sh {check host="{{host}}" id=no-interactive-auth title="SSH keyboard-interactive authentication disabled" sudo}
|
||||
sshd -T | grep -qx 'kbdinteractiveauthentication no'
|
||||
```
|
||||
|
||||
```sh {check host="{{host}}" id=firewall title="Firewall rules present" sudo timeout=10}
|
||||
nft list ruleset | grep -q 'hook input'
|
||||
```
|
||||
|
||||
This confirms an input hook exists, not that the complete firewall policy is safe.
|
||||
|
||||
```sh {check host="{{host}}" id=security-updates title="Automatic security updates active"}
|
||||
systemctl is-enabled unattended-upgrades.service
|
||||
systemctl is-active unattended-upgrades.service
|
||||
```
|
||||
|
||||
```sh {check host="{{host}}" id=no-failed-units title="No failed systemd units"}
|
||||
test "$(systemctl --failed --no-legend --plain | wc -l)" -eq 0
|
||||
```
|
||||
@@ -0,0 +1,52 @@
|
||||
---
|
||||
title: Install and enable a package
|
||||
params:
|
||||
host: { type: host, required: true, label: Debian server }
|
||||
package: { type: name, required: true, default: nginx, label: Package }
|
||||
service: { type: name, required: true, default: nginx, label: Systemd service }
|
||||
---
|
||||
|
||||
# Install and enable {{package}}
|
||||
|
||||
For Debian hosts using apt and systemd. Check the package/service pairing before
|
||||
running; installing packages can start services and expose network ports. Existing
|
||||
apt indexes must be available. Runs require passwordless sudo and confirmation.
|
||||
|
||||
```sh {check host="{{host}}" id=apt-available title="APT is available"}
|
||||
command -v apt-get
|
||||
command -v systemctl
|
||||
```
|
||||
|
||||
```sh {check host="{{host}}" id=package-available title="Package exists in configured repositories"}
|
||||
apt-cache show -- {{package}} > /dev/null
|
||||
```
|
||||
|
||||
```sh {check host="{{host}}" id=installed title="Package already installed"}
|
||||
dpkg-query -W -f='${Status}\n' -- {{package}} | grep -qx 'install ok installed'
|
||||
```
|
||||
|
||||
An absent package is an expected failed check. Proceed with installation only
|
||||
after the repository check succeeds.
|
||||
|
||||
```sh {run host="{{host}}" id=install title="Install package if absent" sudo confirm timeout=300}
|
||||
if ! dpkg-query -W -f='${Status}\n' -- {{package}} 2>/dev/null | grep -qx 'install ok installed'; then
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -y -- {{package}}
|
||||
fi
|
||||
```
|
||||
|
||||
```sh {run host="{{host}}" id=enable title="Enable and start service" sudo confirm timeout=60}
|
||||
systemctl enable --now -- {{service}}
|
||||
```
|
||||
|
||||
```sh {check host="{{host}}" id=enabled title="Service enabled"}
|
||||
systemctl is-enabled -- {{service}}
|
||||
```
|
||||
|
||||
```sh {check host="{{host}}" id=active title="Service active"}
|
||||
systemctl is-active -- {{service}}
|
||||
```
|
||||
|
||||
:::after{step=enable}
|
||||
The enable command succeeded. Run the final checks and verify application health
|
||||
and firewall policy before directing traffic to **{{host}}**.
|
||||
:::
|
||||
@@ -0,0 +1,56 @@
|
||||
---
|
||||
title: New server SSH key
|
||||
params:
|
||||
host: { type: host, required: true, label: Target server }
|
||||
user: { type: name, required: true, default: admin, label: Login user }
|
||||
keyname: { type: name, default: "id_ed25519_{{host}}" }
|
||||
---
|
||||
|
||||
# New server SSH key
|
||||
|
||||
Creates a key pair for **{{user}}** on **{{host}}** and authorizes it.
|
||||
The host needs OpenSSH and passwordless sudo. The private key stays local to
|
||||
ShellBook until downloaded; only the public key is uploaded.
|
||||
|
||||
```sh {check host="{{host}}" id=user-exists title="User exists"}
|
||||
id {{user}}
|
||||
```
|
||||
|
||||
```sh {check host="{{host}}" id=password-login-disabled title="Password login disabled" sudo}
|
||||
sshd -T | grep -qx 'passwordauthentication no'
|
||||
```
|
||||
|
||||
```sh {run on=local id=keygen title="Generate key pair" artifacts="{{keyname}},{{keyname}}.pub"}
|
||||
ssh-keygen -q -t ed25519 -N '' -C {{user}}@{{host}} -f {{keyname}}
|
||||
```
|
||||
|
||||
Each execution generates a fresh pair in its own workdir. Rerunning this step
|
||||
intentionally creates a new key; it does not overwrite a key from an earlier run.
|
||||
|
||||
```sh {run host="{{host}}" id=authorize title="Authorize key" sudo confirm upload="{{keyname}}.pub:/tmp/shellbook-new-key.pub"}
|
||||
home=$(getent passwd {{user}} | cut -d: -f6)
|
||||
test -n "$home"
|
||||
group=$(id -gn {{user}})
|
||||
install -d -m 700 -o {{user}} -g "$group" "$home/.ssh"
|
||||
touch "$home/.ssh/authorized_keys"
|
||||
key=$(cat /tmp/shellbook-new-key.pub)
|
||||
if ! grep -qxF -- "$key" "$home/.ssh/authorized_keys"; then
|
||||
printf '%s\n' "$key" >> "$home/.ssh/authorized_keys"
|
||||
fi
|
||||
chown {{user}}:"$group" "$home/.ssh/authorized_keys"
|
||||
chmod 600 "$home/.ssh/authorized_keys"
|
||||
rm -f /tmp/shellbook-new-key.pub
|
||||
```
|
||||
|
||||
:::after{step=keygen}
|
||||
Download the private key once and save it securely:
|
||||
|
||||
- **Linux:** `~/.ssh/{{keyname}}`, then `chmod 600 ~/.ssh/{{keyname}}`.
|
||||
- **Windows:** `C:\Users\<you>\.ssh\{{keyname}}`, accessible only to your user.
|
||||
|
||||
Keep the public artifact available for the authorization step. Never commit the private key.
|
||||
:::
|
||||
|
||||
:::after{step=authorize failed}
|
||||
Inspect the output and confirm the account and sudo access before retrying.
|
||||
:::
|
||||
Reference in New Issue
Block a user