Deploy ttstd relay and configure secure public WSS clients
This commit is contained in:
1 parent
82adce545d
commit
c38f067bea
16 files changed
+384
-24
No files matched your search
+3
-1
@@ -1,9 +1,11 @@
|
||||
# Process management examples
|
||||
|
||||
Actual `ttstd.com` deployment and startup commands are documented in `docs/deployment-ttstd.md`.
|
||||
|
||||
Examples are templates, not installed automatically. Replace paths, domain, user and tokens before use. Public endpoints require HTTPS/WSS.
|
||||
|
||||
- Linux: create a dedicated `ads` user and `/opt/ads`; protect `/etc/ads/*.env` so only the intended account/root can read them. `server.env` contains `ADS_AGENT_TOKEN=...` and `ADS_CLIENT_TOKEN=...`; `agent.env` contains only `ADS_AGENT_TOKEN=...`. Copy the respective systemd unit to `/etc/systemd/system/`, then enable it. The local client normally runs as the desktop user, so it shares that user's ADB server and keys.
|
||||
- macOS: edit the launchd plist, restrict its file permissions, and install it as the appropriate user's LaunchAgent. It contains a credential, so do not publish the edited file. Client launchd configuration can use the same pattern with `ads-client` and `ADS_CLIENT_TOKEN`.
|
||||
- Windows: the binaries run as foreground long-lived processes. Use Task Scheduler to launch them under the intended account at logon, with a startup wrapper that sets the token environment variable, and configure restart on failure. Keep wrapper/config files readable only by that account and administrators. Native Service Control Manager support and installers are not implemented; do not use `sc.exe create` directly on these binaries.
|
||||
|
||||
These templates have not been exercised on Linux/macOS yet. Test the binaries and process manager on each target platform before relying on unattended startup.
|
||||
The Linux server unit has been deployed and verified on Debian 12. Agent service and macOS templates still require target-platform validation.
|
||||
@@ -8,11 +8,16 @@ Type=simple
|
||||
User=ads
|
||||
WorkingDirectory=/opt/ads
|
||||
EnvironmentFile=/etc/ads/server.env
|
||||
ExecStart=/opt/ads/ads-server --listen 127.0.0.1:8080
|
||||
Environment=GOMEMLIMIT=128MiB
|
||||
ExecStart=/opt/ads/ads-server --listen 127.0.0.1:18081
|
||||
Restart=on-failure
|
||||
RestartSec=3
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
ProtectSystem=strict
|
||||
ProtectHome=true
|
||||
MemoryMax=256M
|
||||
LimitNOFILE=8192
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env bash
|
||||
# Run as root after uploading the binary, unit, and nginx snippet to a staging dir.
|
||||
# Usage: bash install-server.sh /root/ads-stage-<timestamp>
|
||||
set -euo pipefail
|
||||
stage=${1:?staging directory required}
|
||||
case "$stage" in /root/ads-stage-*) ;; *) echo 'Unexpected staging path' >&2; exit 1;; esac
|
||||
test -f "$stage/ads-server"
|
||||
test -f "$stage/ads-server.service"
|
||||
test -f "$stage/nginx-ads-path.conf"
|
||||
nginx -t
|
||||
|
||||
backup="/var/backups/ads/$(date -u +%Y%m%dT%H%M%SZ)"
|
||||
install -d -m 0700 "$backup"
|
||||
nginx_site=$(readlink -f /etc/nginx/sites-enabled/zz-ttstd-main.conf)
|
||||
test -f "$nginx_site"
|
||||
cp -a "$nginx_site" "$backup/ttstd-main.conf"
|
||||
if test -e /opt/ads/ads-server; then cp -a /opt/ads/ads-server "$backup/ads-server"; fi
|
||||
if test -e /etc/systemd/system/ads-server.service; then cp -a /etc/systemd/system/ads-server.service "$backup/ads-server.service"; fi
|
||||
if test -e /etc/nginx/snippets/ads-path.conf; then cp -a /etc/nginx/snippets/ads-path.conf "$backup/ads-path.conf"; fi
|
||||
|
||||
if ! id -u ads >/dev/null 2>&1; then
|
||||
useradd --system --user-group --home-dir /var/lib/ads --shell /usr/sbin/nologin ads
|
||||
fi
|
||||
install -d -m 0755 /opt/ads
|
||||
install -d -m 0700 /etc/ads
|
||||
install -d -m 0750 -o ads -g ads /var/lib/ads
|
||||
if ! test -f /etc/ads/server.env; then
|
||||
python3 - <<'PY'
|
||||
import os, secrets
|
||||
fd = os.open('/etc/ads/server.env', os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
|
||||
with os.fdopen(fd, 'w') as f:
|
||||
f.write('ADS_AGENT_TOKEN=' + secrets.token_hex(32) + '\n')
|
||||
f.write('ADS_CLIENT_TOKEN=' + secrets.token_hex(32) + '\n')
|
||||
PY
|
||||
fi
|
||||
chmod 0600 /etc/ads/server.env
|
||||
install -m 0755 "$stage/ads-server" /opt/ads/ads-server.next
|
||||
mv /opt/ads/ads-server.next /opt/ads/ads-server
|
||||
install -m 0644 "$stage/ads-server.service" /etc/systemd/system/ads-server.service
|
||||
install -m 0644 "$stage/nginx-ads-path.conf" /etc/nginx/snippets/ads-path.conf
|
||||
|
||||
# Insert only into the inspected ttstd.com:443 block, not the other sites.
|
||||
NGINX_SITE="$nginx_site" python3 - <<'PY'
|
||||
from pathlib import Path
|
||||
import os
|
||||
p = Path(os.environ['NGINX_SITE'])
|
||||
text = p.read_text()
|
||||
include = ' include /etc/nginx/snippets/ads-path.conf;'
|
||||
if include not in text:
|
||||
anchor = ' listen 443 ssl;\n server_name ttstd.com;'
|
||||
if text.count(anchor) != 1:
|
||||
raise SystemExit('Expected unique ttstd.com HTTPS server block; refusing ambiguous edit')
|
||||
if 'location ^~ /ads/' in text or 'location /ads/' in text:
|
||||
raise SystemExit('An existing /ads/ location must be reviewed before deployment')
|
||||
text = text.replace(anchor, anchor + '\n\n' + include, 1)
|
||||
p.write_text(text)
|
||||
PY
|
||||
|
||||
if ! nginx -t; then
|
||||
cp -a "$backup/ttstd-main.conf" "$nginx_site"
|
||||
if test -f "$backup/ads-path.conf"; then cp -a "$backup/ads-path.conf" /etc/nginx/snippets/ads-path.conf; fi
|
||||
echo "Nginx validation failed; site configuration restored from $backup" >&2
|
||||
exit 1
|
||||
fi
|
||||
systemctl daemon-reload
|
||||
systemctl enable ads-server.service
|
||||
systemctl restart ads-server.service
|
||||
for attempt in $(seq 1 20); do
|
||||
if curl --fail --silent --max-time 2 http://127.0.0.1:18081/healthz >/dev/null; then break; fi
|
||||
sleep 1
|
||||
done
|
||||
curl --fail --silent --max-time 5 http://127.0.0.1:18081/healthz
|
||||
systemctl reload nginx
|
||||
curl --noproxy '*' --fail --silent --max-time 10 --resolve ttstd.com:443:127.0.0.1 https://ttstd.com/ads/healthz
|
||||
systemctl is-active ads-server nginx
|
||||
systemctl show ads-server --property=MainPID,MemoryCurrent,MemoryPeak
|
||||
printf 'Backup directory: %s\n' "$backup"
|
||||
@@ -0,0 +1,23 @@
|
||||
# Include inside the existing ttstd.com HTTPS server block.
|
||||
# URI prefix /ads/ is stripped before forwarding to the relay.
|
||||
location = /ads {
|
||||
return 308 /ads/;
|
||||
}
|
||||
location ^~ /ads/ {
|
||||
proxy_pass http://127.0.0.1:18081/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_buffering off;
|
||||
proxy_request_buffering off;
|
||||
proxy_read_timeout 3600s;
|
||||
proxy_send_timeout 3600s;
|
||||
# Do not cache authenticated requests or log tickets in query strings.
|
||||
proxy_cache off;
|
||||
proxy_hide_header Cache-Control;
|
||||
add_header Cache-Control "no-store" always;
|
||||
access_log off;
|
||||
}
|
||||
Reference in new issue
Block a user