[deploy] Anywhere: the Docker image and compose file (edge and control), the Linux installer and systemd units, the Windows Server installer (Caddy mode, three services), the preview client for Fabrica, and the Windows smoke script
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
# Ianitor control: API and web UI on 127.0.0.1:7878 (deploy/linux/install.sh writes this).
|
||||
[Unit]
|
||||
Description=Ianitor control (API and UI on loopback)
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
User=ianitor
|
||||
Group=ianitor
|
||||
Environment=IANITOR_LOG=info
|
||||
ExecStart=/usr/local/bin/ianitor-control --config /etc/ianitor/control.toml
|
||||
# After every stop, a crash included: a trial still loaded into Caddy goes back at once.
|
||||
ExecStopPost=/usr/local/bin/ianitor-control caddy-revert --config /etc/ianitor/control.toml
|
||||
Restart=on-failure
|
||||
RestartSec=2
|
||||
ReadWritePaths=/var/lib/ianitor
|
||||
NoNewPrivileges=yes
|
||||
ProtectSystem=strict
|
||||
ProtectHome=yes
|
||||
PrivateTmp=yes
|
||||
PrivateDevices=yes
|
||||
ProtectKernelTunables=yes
|
||||
ProtectKernelModules=yes
|
||||
ProtectControlGroups=yes
|
||||
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
|
||||
RestrictNamespaces=yes
|
||||
LockPersonality=yes
|
||||
MemoryDenyWriteExecute=yes
|
||||
SystemCallArchitectures=native
|
||||
CapabilityBoundingSet=
|
||||
UMask=0027
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,39 @@
|
||||
# Ianitor edge: the Pingora data plane on 80 and 443 (deploy/linux/install.sh writes this).
|
||||
# Header-rule secrets: add one LoadCredential=<name>:/var/lib/ianitor/credentials/<name> each
|
||||
# (systemctl edit ianitor-edge).
|
||||
[Unit]
|
||||
Description=Ianitor edge (Pingora)
|
||||
After=network-online.target ianitor-control.service
|
||||
Wants=network-online.target
|
||||
StartLimitIntervalSec=0
|
||||
|
||||
[Service]
|
||||
User=ianitor-edge
|
||||
Group=ianitor
|
||||
Environment=IANITOR_LOG=info
|
||||
ExecStart=/usr/local/bin/ianitor-edge --config /var/lib/ianitor/edge/edge.json --admin-socket /run/ianitor-edge/admin.sock --share-revocations /var/lib/ianitor/edge/share-revocations.json
|
||||
LoadCredential=share-link-key:/var/lib/ianitor/credentials/share-link-key
|
||||
RuntimeDirectory=ianitor-edge
|
||||
RuntimeDirectoryMode=0750
|
||||
ReadWritePaths=/var/lib/ianitor/edge-state /var/lib/ianitor/logs
|
||||
AmbientCapabilities=CAP_NET_BIND_SERVICE
|
||||
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
|
||||
# The first start may come before control has written edge.json.
|
||||
Restart=always
|
||||
RestartSec=2
|
||||
LimitNOFILE=65536
|
||||
NoNewPrivileges=yes
|
||||
ProtectSystem=strict
|
||||
ProtectHome=yes
|
||||
PrivateTmp=yes
|
||||
PrivateDevices=yes
|
||||
ProtectKernelTunables=yes
|
||||
ProtectKernelModules=yes
|
||||
ProtectControlGroups=yes
|
||||
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
|
||||
RestrictNamespaces=yes
|
||||
LockPersonality=yes
|
||||
SystemCallArchitectures=native
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,81 @@
|
||||
#!/bin/sh
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# Ianitor Domi on plain Linux with systemd (T4), in one line:
|
||||
#
|
||||
# curl -fsSL https://gitea.marek-novak.cz/mnovak/Ianitor/releases/download/vX.Y.Z/install.sh \
|
||||
# | sudo IANITOR_ADMIN_HOST=ianitor.example.org sh
|
||||
#
|
||||
# It downloads the release tarball and SHA256SUMS of the same release, checks the sum, installs
|
||||
# the binaries, the web UI and two systemd units (ianitor-control, ianitor-edge), writes
|
||||
# /etc/ianitor/control.toml once (deploy/linux/setup.sh: every IANITOR_* variable), starts both,
|
||||
# and prints the first admin's sign-in link. Running it again upgrades the binaries and keeps
|
||||
# the config and the state. IANITOR_TARBALL=<file> installs a local tarball instead (no download).
|
||||
set -eu
|
||||
|
||||
VERSION="${IANITOR_VERSION:-__VERSION__}"
|
||||
BASE="${IANITOR_RELEASES:-https://gitea.marek-novak.cz/mnovak/Ianitor/releases/download}/v$VERSION"
|
||||
ARCH="$(uname -m)"
|
||||
NAME="ianitor-$VERSION-linux-$ARCH.tar.gz"
|
||||
|
||||
die() { echo "ianitor install: $*" >&2; exit 1; }
|
||||
[ "$(id -u)" = 0 ] || die "run it as root (sudo)"
|
||||
command -v systemctl >/dev/null || die "this installer needs systemd; use the Docker image otherwise (deploy/docker)"
|
||||
command -v git >/dev/null || die "install git first (apt install git / dnf install git)"
|
||||
[ "$ARCH" = x86_64 ] || die "only x86_64 builds are published so far"
|
||||
|
||||
work="$(mktemp -d)"
|
||||
trap 'rm -rf "$work"' EXIT
|
||||
if [ -n "${IANITOR_TARBALL:-}" ]; then
|
||||
cp "$IANITOR_TARBALL" "$work/$NAME"
|
||||
else
|
||||
command -v curl >/dev/null || die "install curl first"
|
||||
curl -fsSLo "$work/$NAME" "$BASE/$NAME"
|
||||
curl -fsSLo "$work/SHA256SUMS" "$BASE/SHA256SUMS"
|
||||
(cd "$work" && grep " $NAME\$" SHA256SUMS | sha256sum -c -) || die "the download does not match SHA256SUMS"
|
||||
fi
|
||||
tar -xzf "$work/$NAME" -C "$work"
|
||||
src="$work/ianitor-$VERSION"
|
||||
[ -x "$src/bin/ianitor-control" ] || die "the tarball has no bin/ianitor-control"
|
||||
|
||||
getent group ianitor >/dev/null || groupadd --system ianitor
|
||||
id ianitor >/dev/null 2>&1 || useradd --system --gid ianitor --home-dir /var/lib/ianitor --shell /usr/sbin/nologin ianitor
|
||||
id ianitor-edge >/dev/null 2>&1 || useradd --system --gid ianitor --no-create-home --home-dir /nonexistent --shell /usr/sbin/nologin ianitor-edge
|
||||
|
||||
install -m 0755 "$src/bin/ianitor-control" "$src/bin/ianitor-edge" /usr/local/bin/
|
||||
install -d -m 0755 /usr/local/lib/ianitor /usr/share/ianitor
|
||||
install -m 0755 "$src/lib/setup.sh" /usr/local/lib/ianitor/setup.sh
|
||||
rm -rf /usr/share/ianitor/web && cp -r "$src/web" /usr/share/ianitor/web
|
||||
install -m 0644 "$src/lib/ianitor-control.service" "$src/lib/ianitor-edge.service" /etc/systemd/system/
|
||||
|
||||
IANITOR_ROOT=/var/lib/ianitor IANITOR_CONFIG=/etc/ianitor/control.toml \
|
||||
IANITOR_EDGE_SOCKET=/run/ianitor-edge/admin.sock sh /usr/local/lib/ianitor/setup.sh
|
||||
|
||||
# Who may read what (as the NixOS module's tmpfiles): control owns the state, edge reads its
|
||||
# config and the certificates through the group and writes only its own state and logs.
|
||||
chown -R ianitor:ianitor /var/lib/ianitor
|
||||
chmod 0755 /var/lib/ianitor
|
||||
chmod 0700 /var/lib/ianitor/control /var/lib/ianitor/credentials
|
||||
chmod 0750 /var/lib/ianitor/edge /var/lib/ianitor/certs /var/lib/ianitor/caddy
|
||||
chown -R ianitor-edge:ianitor /var/lib/ianitor/edge-state /var/lib/ianitor/logs
|
||||
chmod 0700 /var/lib/ianitor/edge-state
|
||||
chmod 0770 /var/lib/ianitor/logs
|
||||
chown root:ianitor /etc/ianitor /etc/ianitor/control.toml
|
||||
chmod 0750 /etc/ianitor
|
||||
chmod 0640 /etc/ianitor/control.toml
|
||||
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now ianitor-control.service ianitor-edge.service
|
||||
systemctl restart ianitor-control.service ianitor-edge.service
|
||||
|
||||
i=0
|
||||
until curl -s -o /dev/null http://127.0.0.1:7878/api/v1/health 2>/dev/null; do
|
||||
i=$((i + 1)); [ $i -le 30 ] || die "control did not start; see journalctl -u ianitor-control"
|
||||
sleep 1
|
||||
done
|
||||
echo
|
||||
echo "Ianitor $VERSION is running. Open this link to sign in as the first admin:"
|
||||
runuser -u ianitor -- /usr/local/bin/ianitor-control team setup-link --config /etc/ianitor/control.toml 2>/dev/null \
|
||||
|| echo "(the team already has an admin; they invite you from Settings → Team)"
|
||||
@@ -0,0 +1,144 @@
|
||||
#!/bin/sh
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
#
|
||||
# Writes Ianitor's control.toml and its first secrets from environment variables, once.
|
||||
# Shared by the Linux installer (deploy/linux/install.sh) and the Docker image's entrypoint.
|
||||
# An existing control.toml is never touched; secrets are random files (0600), never values in
|
||||
# the config, the image or a log.
|
||||
#
|
||||
# IANITOR_ADMIN_HOST the web UI's address, e.g. ianitor.example.org (required)
|
||||
# IANITOR_TLS letsencrypt (default) or domi, for the admin host
|
||||
# IANITOR_DOMI_ROOT the Domi root certificate (public) for tls = domi (docs/pki.md)
|
||||
# IANITOR_PREVIEW_DOMAIN branch previews live under it, e.g. preview.example.org
|
||||
# IANITOR_PREVIEW_UPSTREAMS comma list of what previews may point at (10.0.0.0/8,app.internal)
|
||||
# IANITOR_PREVIEW_TLS letsencrypt or domi (default: IANITOR_TLS)
|
||||
# IANITOR_ROUTES_REMOTE where the routes repository is pushed (https URL on Gitea, GitHub, GitLab)
|
||||
# IANITOR_ROUTES_HOST gitea (default), github or gitlab: the push user name and the UI's label
|
||||
# IANITOR_ROUTES_USER overrides the push user name
|
||||
# IANITOR_ROOT state root (default /var/lib/ianitor)
|
||||
# IANITOR_CONFIG where control.toml goes (default /etc/ianitor/control.toml)
|
||||
# IANITOR_CREDENTIALS the credentials folder (default $IANITOR_ROOT/credentials)
|
||||
# IANITOR_EDGE_SOCKET edge's admin socket (default /run/ianitor/admin.sock)
|
||||
# IANITOR_WEB the built web UI (default /usr/share/ianitor/web)
|
||||
# IANITOR_HTTP, IANITOR_HTTPS listen addresses (default 0.0.0.0:80, 0.0.0.0:443)
|
||||
set -eu
|
||||
|
||||
ROOT="${IANITOR_ROOT:-/var/lib/ianitor}"
|
||||
CONFIG="${IANITOR_CONFIG:-/etc/ianitor/control.toml}"
|
||||
CREDS="${IANITOR_CREDENTIALS:-$ROOT/credentials}"
|
||||
SOCKET="${IANITOR_EDGE_SOCKET:-/run/ianitor/admin.sock}"
|
||||
WEB="${IANITOR_WEB:-/usr/share/ianitor/web}"
|
||||
TLS="${IANITOR_TLS:-letsencrypt}"
|
||||
|
||||
die() { echo "ianitor setup: $*" >&2; exit 1; }
|
||||
|
||||
# Only plain values reach the TOML: no quotes, backslashes, dollars or newlines.
|
||||
plain() {
|
||||
case "$1" in
|
||||
*[\"\\\'\`\$]*) die "$2 contains a character that is not allowed" ;;
|
||||
esac
|
||||
if [ "$(printf '%s' "$1" | wc -l)" -ne 0 ]; then die "$2 must be one line"; fi
|
||||
}
|
||||
|
||||
for d in "$ROOT" "$ROOT/control" "$ROOT/edge" "$ROOT/caddy" "$ROOT/certs" "$ROOT/edge-state" \
|
||||
"$ROOT/caddy-state" "$ROOT/logs" "$CREDS"; do
|
||||
mkdir -p "$d"
|
||||
done
|
||||
chmod 0700 "$CREDS" "$ROOT/control"
|
||||
|
||||
# Secrets: made here once, random, readable by their owner only.
|
||||
umask 077
|
||||
[ -s "$CREDS/share-link-key" ] || head -c 32 /dev/urandom | od -An -tx1 | tr -d ' \n' > "$CREDS/share-link-key"
|
||||
[ -s "$CREDS/pki-password" ] || head -c 32 /dev/urandom | od -An -tx1 | tr -d ' \n' > "$CREDS/pki-password"
|
||||
umask 022
|
||||
[ -f "$ROOT/edge/share-revocations.json" ] || echo '{"epoch":0,"deny":[]}' > "$ROOT/edge/share-revocations.json"
|
||||
[ -f "$ROOT/engine" ] || echo pingora > "$ROOT/engine"
|
||||
|
||||
if [ -f "$CONFIG" ]; then
|
||||
echo "ianitor setup: $CONFIG exists; leaving it as it is." >&2
|
||||
exit 0
|
||||
fi
|
||||
|
||||
[ -n "${IANITOR_ADMIN_HOST:-}" ] || die "IANITOR_ADMIN_HOST is required (the web UI's address, e.g. ianitor.example.org)"
|
||||
plain "$IANITOR_ADMIN_HOST" IANITOR_ADMIN_HOST
|
||||
case "$TLS" in letsencrypt|domi) ;; *) die "IANITOR_TLS must be letsencrypt or domi" ;; esac
|
||||
PTLS="${IANITOR_PREVIEW_TLS:-$TLS}"
|
||||
case "$PTLS" in letsencrypt|domi) ;; *) die "IANITOR_PREVIEW_TLS must be letsencrypt or domi" ;; esac
|
||||
|
||||
routes_remote=""
|
||||
if [ -n "${IANITOR_ROUTES_REMOTE:-}" ]; then
|
||||
plain "$IANITOR_ROUTES_REMOTE" IANITOR_ROUTES_REMOTE
|
||||
case "${IANITOR_ROUTES_HOST:-gitea}" in
|
||||
github) user=x-access-token; label=GitHub ;;
|
||||
gitlab) user=oauth2; label=GitLab ;;
|
||||
gitea) user=ianitor; label=Gitea ;;
|
||||
*) die "IANITOR_ROUTES_HOST must be gitea, github or gitlab" ;;
|
||||
esac
|
||||
user="${IANITOR_ROUTES_USER:-$user}"
|
||||
plain "$user" IANITOR_ROUTES_USER
|
||||
routes_remote="remote = \"$IANITOR_ROUTES_REMOTE\"
|
||||
remote_name = \"$label\"
|
||||
push_username = \"$user\"
|
||||
push_credential = \"routes-token\""
|
||||
fi
|
||||
|
||||
pki=""
|
||||
if [ "$TLS" = domi ] || [ "$PTLS" = domi ]; then
|
||||
[ -n "${IANITOR_DOMI_ROOT:-}" ] || die "tls = domi needs IANITOR_DOMI_ROOT (the Domi root certificate; docs/pki.md)"
|
||||
plain "$IANITOR_DOMI_ROOT" IANITOR_DOMI_ROOT
|
||||
pki="[pki]
|
||||
root_cert = \"$IANITOR_DOMI_ROOT\""
|
||||
fi
|
||||
|
||||
previews=""
|
||||
if [ -n "${IANITOR_PREVIEW_DOMAIN:-}" ]; then
|
||||
plain "$IANITOR_PREVIEW_DOMAIN" IANITOR_PREVIEW_DOMAIN
|
||||
plain "${IANITOR_PREVIEW_UPSTREAMS:-}" IANITOR_PREVIEW_UPSTREAMS
|
||||
list=$(printf '%s\n' "${IANITOR_PREVIEW_UPSTREAMS:-}" | tr ',' '\n' | sed '/^ *$/d; s/^ *//; s/ *$//; s/.*/"&"/' | paste -sd, -)
|
||||
previews="[previews]
|
||||
domain = \"$IANITOR_PREVIEW_DOMAIN\"
|
||||
tls = \"$PTLS\"
|
||||
upstreams = [$list]"
|
||||
fi
|
||||
|
||||
mkdir -p "$(dirname "$CONFIG")"
|
||||
cat > "$CONFIG.new" <<EOF
|
||||
# Written by Ianitor's setup on $(date -u +%Y-%m-%d). Edit freely; setup never rewrites it.
|
||||
# Secrets are files in $CREDS, never values here.
|
||||
listen = "127.0.0.1:7878"
|
||||
state_dir = "$ROOT/control"
|
||||
credentials_dir = "$CREDS"
|
||||
|
||||
[routes]
|
||||
repo = "$ROOT/routes.git"
|
||||
$routes_remote
|
||||
|
||||
[edge]
|
||||
config = "$ROOT/edge/edge.json"
|
||||
admin_socket = "$SOCKET"
|
||||
share_revocations = "$ROOT/edge/share-revocations.json"
|
||||
|
||||
[caddy]
|
||||
config = "$ROOT/caddy/caddy.json"
|
||||
|
||||
[compile]
|
||||
http_listen = "${IANITOR_HTTP:-0.0.0.0:80}"
|
||||
https_listen = "${IANITOR_HTTPS:-0.0.0.0:443}"
|
||||
cert_dir = "$ROOT/certs"
|
||||
state_dir = "$ROOT/edge-state"
|
||||
access_log = "$ROOT/logs/access.log"
|
||||
caddy_credentials_dir = "$CREDS"
|
||||
|
||||
[ui]
|
||||
hostname = "$IANITOR_ADMIN_HOST"
|
||||
static_dir = "$WEB"
|
||||
admin_tls = "$TLS"
|
||||
|
||||
$pki
|
||||
|
||||
$previews
|
||||
EOF
|
||||
mv "$CONFIG.new" "$CONFIG"
|
||||
echo "ianitor setup: wrote $CONFIG" >&2
|
||||
Reference in New Issue
Block a user