feat(gen1): safe Let's Encrypt provisioning for SYS.API port 8850

This commit is contained in:
OpenGenesis (MPL 2.0) committed 2026-11-17 18:28:01 +01:00
1 parent 0cb68b95a4
commit d8b4b439d7
4 files changed
+78

No files matched your search

+1
View File
@@ -974,6 +974,7 @@ jobs:
run: |
set -euo pipefail
python3 tools/ci/verify_sys_api_foundation.py
bash -n tools/ops/sys-api-tls-install.sh
dotnet build addons/SysApi/sys.api.csproj --configuration Release --no-restore
dotnet run --project tools/ci/SysApiSmoke/SysApiSmoke.csproj --configuration Release
@@ -48,3 +48,7 @@ Use the HTTPS gateway that already terminates the city's portal TLS, or configur
dotnet run --project tools/ci/SysApiSmoke/SysApiSmoke.csproj -c Release
Smoke covers UserLevel 199 vs 200, revoked permissions, invalid credentials, bearer token, secret persistence, CSP, official mascot embedding and origin checks. Production activation and public certificate issuance require the operator's actual FQDN and an acceptance test.
## Automated ACME installer (after choosing a domain)
Once the FQDN, ACME email and externally reachable HTTP-01 webroot are configured, the root-only helper `tools/ops/sys-api-tls-install.sh <fqdn> <email> <webroot>` verifies the HTTP-01 route, obtains the official Let’s Encrypt certificate via certbot, applies the Nginx 8850 TLS template, validates Nginx, and enables the certbot renewal timer plus a reload hook. It refuses to proceed if external TCP/80 does not return the challenge. It does **not** change or stop ROBUST TCP/80. If HTTP-01 cannot be routed, issue through DNS-01 at your trusted gateway instead. Never publish 8851 or use a self-signed cert for production.
+3
View File
@@ -37,4 +37,7 @@ assert "sys.api" in read("OpenSim.sln")
assert "sys.api" in read("runprebuild.sh") and "sys.api.dll" in read("compile.sh")
assert "NexVerseWorldApiConnector" in read("bin/Robust.HG.ini"),"Legacy World API removed"
assert "ssl_certificate" in read("tools/ops/sys-api-nginx-8850.conf.example")
installer=read("tools/ops/sys-api-tls-install.sh")
for marker in ("certbot certonly", "certbot.timer", "nginx -t", "renewal-hooks/deploy", "/.well-known/acme-challenge/"):
assert marker in installer, marker
print("SYS.API independent DLL, UserLevel 200, persistent token, TLS proxy, legacy API and OGL mascot: PASS")
+70
View File
@@ -0,0 +1,70 @@
#!/usr/bin/env bash
# SPDX-License-Identifier: MPL-2.0
# Provision TLS on external port 8850 using an already routed HTTP-01 webroot.
# Never stops or reconfigures the ROBUST process that owns port 80.
set -Eeuo pipefail
if [[ $# -ne 3 ]]; then
echo "Usage: sudo bash $0 <sysapi-fqdn> <acme-email> <public-http01-webroot>" >&2
exit 2
fi
domain="$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]')"
email="$2"
webroot="$3"
[[ "$EUID" -eq 0 ]] || { echo "Root required" >&2; exit 2; }
[[ "$domain" =~ ^[a-z0-9][a-z0-9.-]{2,245}[a-z0-9]$ ]] &&
[[ "$domain" == *.* ]] && [[ "$domain" != *..* ]] ||
{ echo "Invalid FQDN" >&2; exit 2; }
[[ "$email" =~ ^[^[:space:]@]+@[^[:space:]@]+\.[^[:space:]@]+$ ]] ||
{ echo "Valid ACME contact email required" >&2; exit 2; }
[[ -d "$webroot" && ! -L "$webroot" ]] ||
{ echo "ACME webroot missing or symlink" >&2; exit 2; }
for binary in certbot nginx curl openssl; do
command -v "$binary" >/dev/null ||
{ echo "Missing $binary; install it first" >&2; exit 2; }
done
challenge_dir="$webroot/.well-known/acme-challenge"
install -d -m 0755 "$challenge_dir"
nonce="$(openssl rand -hex 16)"
challenge="$challenge_dir/ogl-sysapi-check-$nonce"
trap 'rm -f "$challenge"' EXIT
printf '%s' "$nonce" > "$challenge"
public="$(curl -fsSL --max-time 12 \
"http://$domain/.well-known/acme-challenge/ogl-sysapi-check-$nonce" || true)"
[[ "$public" == "$nonce" ]] ||
{ echo "HTTP-01 cannot reach webroot through public TCP/80 for $domain." >&2
echo "Route ACME challenges via the public gateway or use DNS-01." >&2
exit 3; }
certbot certonly --webroot -w "$webroot" -d "$domain" \
--agree-tos --non-interactive --email "$email" --keep-until-expiring
cert="/etc/letsencrypt/live/$domain/fullchain.pem"
key="/etc/letsencrypt/live/$domain/privkey.pem"
[[ -s "$cert" && -s "$key" ]] ||
{ echo "Missing freshly issued certificate" >&2; exit 4; }
template="$(dirname "$(realpath "$0")")/sys-api-nginx-8850.conf.example"
[[ -r "$template" ]] || { echo "Nginx template missing" >&2; exit 4; }
target=/etc/nginx/conf.d/ogl-sys-api-8850.conf
backup=""
if [[ -e "$target" ]]; then
backup="$target.backup-$(date -u +%Y%m%d%H%M%S)"
cp -p "$target" "$backup"
fi
sed "s/YOUR_DOMAIN/$domain/g" "$template" > "$target"
if ! nginx -t; then
if [[ -n "$backup" ]]; then cp -p "$backup" "$target"; else rm -f "$target"; fi
nginx -t || true
echo "Nginx config invalid; reverted" >&2
exit 5
fi
install -d -m 0755 /etc/letsencrypt/renewal-hooks/deploy
hook=/etc/letsencrypt/renewal-hooks/deploy/ogl-sysapi-nginx-reload
printf '#!/bin/sh\nsystemctl reload nginx\n' > "$hook"
chmod 0755 "$hook"
if systemctl list-unit-files certbot.timer >/dev/null 2>&1; then
systemctl enable --now certbot.timer
else
echo "Configure an ACME renewal timer for this certificate." >&2
fi
systemctl reload nginx || systemctl start nginx
echo "HTTPS proxy ready at https://$domain:8850/"
echo "Set [SysApi] PublicOrigin accordingly and verify public NAT/firewall."
echo "Port 8851 must remain private; renewals reload Nginx."