Skip to content

Provisioning the VM

Build vm-nri-www with these steps, in order. They are idempotent and safe to re-run. They also serve as the rebuild procedure, since there is no VM-level backup. The Azure-side prerequisites — the NSG rules, the managed identity and its vault grant — are on the Azure page.

Terminal window
fallocate -l 4G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap sw 0 0' >> /etc/fstab
printf 'vm.swappiness=10\n' > /etc/sysctl.d/60-swap.conf
sysctl -p /etc/sysctl.d/60-swap.conf

The VM has 4 GiB of RAM, and the conventional guidance for a 4 GiB server is a swap file equal to RAM. It exists as a cushion, not as working memory: Umbraco’s Examine index rebuilds and the Node SSR process are both capable of a short allocation spike that would otherwise end in the kernel killing the application. vm.swappiness=10 keeps the kernel from reaching for swap during normal operation. The VM size has no temporary disk, so the swap file lives on the OS disk and is covered by its encryption.

Caddy, from Cloudsmith:

Terminal window
apt-get install -y debian-keyring debian-archive-keyring apt-transport-https curl
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' \
| gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' \
> /etc/apt/sources.list.d/caddy-stable.list

Azure CLI, from Microsoft — needed by the backup job, not by the application:

Terminal window
mkdir -p /etc/apt/keyrings
curl -sLS https://packages.microsoft.com/keys/microsoft.asc \
| gpg --dearmor -o /etc/apt/keyrings/microsoft.gpg
chmod go+r /etc/apt/keyrings/microsoft.gpg
cat > /etc/apt/sources.list.d/azure-cli.sources <<'EOF'
Types: deb
URIs: https://packages.microsoft.com/repos/azure-cli/
Suites: resolute
Components: main
Architectures: amd64
Signed-By: /etc/apt/keyrings/microsoft.gpg
EOF

Both repositories are pinned to a signing key. Nothing is installed from a pipe-to-shell installer.

Terminal window
apt-get update
apt-get install -y aspnetcore-runtime-10.0 nodejs sqlite3 rsync caddy \
unattended-upgrades git htop azure-cli
Package Why
aspnetcore-runtime-10.0 Umbraco 17 targets .NET 10
nodejs Svelte SSR runs as a Node child process of the CMS
caddy Reverse proxy, automatic HTTPS
sqlite3 Used by the backup job to snapshot the databases
rsync Used by make deploy
azure-cli Used by the backup job to upload snapshots

dpkg -l on the host shows the installed versions; this page does not pin them.

/etc/apt/apt.conf.d/20auto-upgrades
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";

Allowed origins are the Ubuntu distribution and -security pockets only. Automatic reboot is off, so a kernel update needs a scheduled reboot. Check for one with cat /var/run/reboot-required.

Terminal window
mkdir -p /var/www/nri-inc.org/umbraco/Logs /var/www/nri-inc.org/umbraco/Data
chown -R www-data:www-data /var/www/nri-inc.org

The whole tree is owned by www-data, and make deploy writes into it as www-data over rsync. That means the application can modify its own deployed code. Root-owned code with only umbraco/ writable by www-data would be tighter, and would need the deploy to write as a different user.

The unit files are checked into the repository under deploy/. Install them unchanged:

Terminal window
install -m 644 deploy/nri-inc.service /etc/systemd/system/
install -m 644 deploy/backup/nri-inc-backup.service /etc/systemd/system/
install -m 644 deploy/backup/nri-inc-backup-daily.timer /etc/systemd/system/
install -m 700 deploy/backup/nri-inc-sqlite-backup /usr/local/sbin/
systemctl daemon-reload
systemctl enable nri-inc.service
systemctl enable --now nri-inc-backup-daily.timer

nri-inc.service sets User/Group=www-data, UMask=0027 and NoNewPrivileges=true. It does not set ProtectSystem, PrivateTmp, ProtectHome or a CapabilityBoundingSet; those would further limit what a compromised application can touch.

/etc/caddy/Caddyfile
# cms.nri-inc.org — the only site on this server.
cms.nri-inc.org {
tls /etc/caddy/certs/cms.nri-inc.org.cloudflare-origin.crt /etc/caddy/certs/cms.nri-inc.org.cloudflare-origin.key
reverse_proxy 127.0.0.1:5019
}

The certificate is a Cloudflare origin certificate for cms.nri-inc.org, created in the Cloudflare dashboard under SSL/TLS → Origin Server. Cloudflare shows the private key only once, at creation. Save both files before reloading Caddy:

Terminal window
install -d -m 750 -o root -g caddy /etc/caddy/certs
# paste the certificate and key into these two files
chown root:caddy /etc/caddy/certs/cms.nri-inc.org.cloudflare-origin.*
chmod 644 /etc/caddy/certs/cms.nri-inc.org.cloudflare-origin.crt
chmod 640 /etc/caddy/certs/cms.nri-inc.org.cloudflare-origin.key
Terminal window
caddy validate --config /etc/caddy/Caddyfile
systemctl reload caddy

Caddy requests no certificate of its own, so the site works as soon as DNS points at the VM through Cloudflare. The packaged service unit runs as the caddy user with ProtectSystem=full and the CAP_NET_ADMIN/CAP_NET_BIND_SERVICE ambient capabilities. To compare the effective configuration between hosts, compare the adapted JSON rather than the source text:

Terminal window
caddy adapt --config /etc/caddy/Caddyfile

Write /etc/nri-inc-backup.env (root:root, mode 600) with the backup account key; the backup job reads it. Application secrets need nothing on the host once the VM’s managed identity holds its vault role.

To copy a live database onto the host — from a backup, or from another machine — use SQLite’s own VACUUM INTO, which produces a consistent copy of a running database. A plain cp of a database in WAL mode can copy a torn page and is not safe:

Terminal window
sqlite3 Umbraco.sqlite.db "VACUUM INTO '/var/tmp/nri-xfer/Umbraco.sqlite.db';"
sqlite3 Umbraco.Automate.sqlite.db "VACUUM INTO '/var/tmp/nri-xfer/Umbraco.Automate.sqlite.db';"
sqlite3 /var/tmp/nri-xfer/Umbraco.sqlite.db 'PRAGMA quick_check;' # ok

Check PRAGMA quick_check on both ends of the transfer.

Release the application with make deploy — see Deploying on the architecture page.