publishing: build without credentials, publish from a host-owned script

Repo build logic now runs as the unprivileged docsbuild user with a scrubbed
environment; the Cloudron token lives only in a root-owned publish script that
executes no repository code.
This commit is contained in:
inference-admin committed 2026-11-19 21:51:05 +00:00
1 parent f2e74564df
commit b39c9b9289
2 files changed
+65 -91

No files matched your search

+23 -22
View File
@@ -1,41 +1,42 @@
# systemd unit for the docs auto-deploy poller (agent host).
#
# docs-deploy-poll.service ALWAYS ON. Polls Gitea every 60s; deploys on
# any change to main. Works with the agent
# host's current firewall (outbound only).
# any change to main.
#
# docs-deploy-webhook.service INSTALLED, INACTIVE UNTIL THE PORT IS OPEN.
# Instant push -> deploy once the Infomaniak
# panel allows inbound TCP to the agent host
# (the Gitea webhook is already registered).
# docs-deploy-webhook.service INSTALLED, INACTIVE. It predates the
# build/publish split, loads the agent's env
# file, and runs repo scripts with the Cloudron
# token. Do not enable it until it is ported to
# the same split.
#
# Install:
# sudo cp publishing/docs-deploy-poll.service /etc/systemd/system/
# sudo install -o root -g root -m 0644 publishing/docs-deploy-poll.service \
# /etc/systemd/system/docs-deploy-poll.service
# sudo systemctl daemon-reload
# sudo systemctl enable --now docs-deploy-poll
#
# poll-watcher.sh itself needs NO manual copy: the service runs the copy in
# the dedicated checkout (/home/ubuntu/.docs-publisher), which git pull keeps
# at main on every deploy, and the watcher re-execs itself when a deploy
# changed it.
# The unit runs a HOST-OWNED script, /usr/local/sbin/docs-poll, which is not
# copied from this repository. That script:
# * builds as the unprivileged `docsbuild` user from its own checkout at
# /var/lib/docs-publisher/repo (a scrubbed environment, no read access to
# /home/ubuntu, so repo code cannot see any co-op credential);
# * publishes with /usr/local/sbin/docs-publish, a root-owned script that
# runs no repository code and reads the Cloudron token from
# /etc/docs-deploy.env (root-only, mode 0600).
#
# ONE BUILD ENVIRONMENT: the poller builds from its own dedicated checkout
# (uncommitted edits in a working clone must never block or leak into a
# deploy) but with the ONE canonical venv, DOCS_CANONICAL_DIR/.venv-docs, and
# drift-checks its publishing/ tree against the canonical checkout before
# every build. See publishing/README.md.
# Repo code (build.sh, hooks.py) therefore never executes with a credential.
# See publishing/README.md.
[Unit]
Description=Inference docs: poll Gitea main and deploy to Surfer
Description=Inference docs: poll Gitea main, build unprivileged, publish without repo code
After=network-online.target
Wants=network-online.target
[Service]
User=ubuntu
WorkingDirectory=/home/ubuntu/.docs-publisher
Environment=DOCS_REPO_DIR=/home/ubuntu/.docs-publisher
Environment=DOCS_CANONICAL_DIR=/home/ubuntu/repos/docs
ExecStart=/bin/bash /home/ubuntu/.docs-publisher/publishing/poll-watcher.sh
User=root
Environment=DOCS_REPO_DIR=/var/lib/docs-publisher/repo
Environment=DOCS_DEPLOY_LOG=/var/log/docs-deploy.log
ExecStart=/usr/local/sbin/docs-poll
Restart=on-failure
RestartSec=10