feat(hub): add central service foundation and transactional mail
This commit is contained in:
parent
b14f036bdb
commit
a811de590a
25 changed files with 1521 additions and 4 deletions
80
deploy/central/README.md
Normal file
80
deploy/central/README.md
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
# Central Hub deployment
|
||||
|
||||
Current target: `central.loki-code.dev`, Ubuntu22.04, Nginx443 terminating HTTPS;
|
||||
Hub listener `127.0.0.1:37623` (randomly selected free port). The foundation has no
|
||||
public email-send/auth/registry/friends/DM endpoints. See `hub/README.md` for exact
|
||||
capability status. SMTP sender display name is Vnox, address `noreply@loki-code.dev`.
|
||||
|
||||
## Layout
|
||||
|
||||
- `/opt/vnox-central/releases/<git-revision>-<binary-hash>/vnox-hub`: immutable release.
|
||||
- `/opt/vnox-central/current`: symlink to selected release.
|
||||
- `/etc/vnox-central/hub.env`: real config, root-owned0600, outside Git.
|
||||
- `/var/lib/vnox-central/`: private service data0700, issuer0600 and SQLite.
|
||||
- `/etc/systemd/system/vnox-central.service`: dedicated non-login service user.
|
||||
- `/etc/nginx/sites-available/central.loki-code.dev`: dedicated virtual host.
|
||||
|
||||
Only copy explicitly authorized SMTP keys from the existing service in-process.
|
||||
Do not dump Docker environment/config, source secrets into shell logs, add them to
|
||||
command arguments, publish them in preview pages or commit them. Displaying a
|
||||
successful SMTP test is enough; it does not require revealing credentials.
|
||||
|
||||
## Build and publish
|
||||
|
||||
Build from `VNOX-Server/`, after tests/review, on the installed Rust toolchain:
|
||||
|
||||
```sh
|
||||
CC_x86_64_unknown_linux_musl=musl-gcc cargo build --locked --release \
|
||||
--target x86_64-unknown-linux-musl -p vnox-hub
|
||||
sha256sum target/x86_64-unknown-linux-musl/release/vnox-hub
|
||||
```
|
||||
|
||||
The static musl build avoids depending on a newer local glibc than Ubuntu22.04.
|
||||
Build and verify before uploading. Install into a new revision/hash directory,
|
||||
verify its remote SHA256, switch `current` atomically, restart only
|
||||
`vnox-central`, and verify readiness before pointing/reloading the Nginx proxy.
|
||||
Keep the preceding release for rollback; do not replace identity or DB on update.
|
||||
|
||||
Install the service/config templates with local paths/port adjusted as needed.
|
||||
Create `vnox-central` system user and private state dir first. SMTP credentials
|
||||
are supplied only in protected `hub.env`; example credentials do not work.
|
||||
|
||||
## Certificate and renewal
|
||||
|
||||
Provision HTTP ACME webroot before requesting the cert:
|
||||
|
||||
```sh
|
||||
certbot certonly --webroot -w /var/www/vnox-acme -d central.loki-code.dev \
|
||||
--non-interactive --agree-tos
|
||||
nginx -t
|
||||
systemctl reload nginx
|
||||
```
|
||||
|
||||
Keep the ACME path available after enabling the HTTP→HTTPS redirect. Certbot's
|
||||
timer handles renewal; a deploy hook validates/reloads Nginx after renewal.
|
||||
Check certificate chain/hostname from outside the VPS, not only with `nginx -t`.
|
||||
Run renewal staging checks without unnecessary random sleep when unattended.
|
||||
|
||||
## Verification
|
||||
|
||||
```sh
|
||||
systemctl is-active vnox-central
|
||||
curl --fail http://127.0.0.1:37623/ready
|
||||
curl --fail https://central.loki-code.dev/ready
|
||||
curl --fail https://central.loki-code.dev/v1/info
|
||||
```
|
||||
|
||||
Use a transient systemd service with the same protected EnvironmentFile to run
|
||||
`vnox-hub --check-smtp` as the service user. It connects/authenticates and issues
|
||||
NOOP without sending a message. Actual delivery needs a separately authorized
|
||||
recipient/test. Previews use dummy tokens and must not be mistaken for working
|
||||
verification links.
|
||||
|
||||
Restart once and verify the issuer ID/public key remain unchanged and `/ready`
|
||||
returns200. Confirm the backend listener is loopback-only, key/env modes are
|
||||
private, other Nginx virtual hosts still work, and SIGTERM exits cleanly.
|
||||
|
||||
Back up issuer and SQLite consistently (SQLite backup API/checkpoint or stopped
|
||||
service), with encrypted/private storage; test paired restore. Do not back up
|
||||
only DB and silently generate a new issuer if its key is missing. Future DM
|
||||
payload/attachment backup policy is separate from account/registry state.
|
||||
32
deploy/central/central.loki-code.dev.conf
Normal file
32
deploy/central/central.loki-code.dev.conf
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name central.loki-code.dev;
|
||||
location ^~ /.well-known/acme-challenge/ {
|
||||
root /var/www/vnox-acme;
|
||||
default_type text/plain;
|
||||
}
|
||||
location / { return 301 https://central.loki-code.dev$request_uri; }
|
||||
}
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
listen [::]:443 ssl http2;
|
||||
server_name central.loki-code.dev;
|
||||
ssl_certificate /etc/letsencrypt/live/central.loki-code.dev/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/central.loki-code.dev/privkey.pem;
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
server_tokens off;
|
||||
client_max_body_size 1m;
|
||||
add_header X-Content-Type-Options nosniff always;
|
||||
add_header Referrer-Policy no-referrer always;
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:37623;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-Proto https;
|
||||
proxy_set_header X-Forwarded-For $remote_addr;
|
||||
proxy_set_header Connection "";
|
||||
proxy_connect_timeout 5s;
|
||||
proxy_read_timeout 30s;
|
||||
}
|
||||
}
|
||||
11
deploy/central/hub.env.example
Normal file
11
deploy/central/hub.env.example
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# Install a completed copy as /etc/vnox-central/hub.env, root:root mode 0600.
|
||||
# This is an example, never add production secrets to Git.
|
||||
HUB_BIND=127.0.0.1:37623
|
||||
HUB_DATA_DIR=/var/lib/vnox-central
|
||||
PUBLIC_BASE_URL=https://central.loki-code.dev
|
||||
SMTP_HOST=smtp.provider.example
|
||||
SMTP_PORT=587
|
||||
SMTP_USER=replace-on-server
|
||||
SMTP_PASSWORD=replace-on-server
|
||||
MAIL_FROM="Vnox <noreply@loki-code.dev>"
|
||||
RUST_LOG=vnox_hub=info
|
||||
32
deploy/central/vnox-central.service
Normal file
32
deploy/central/vnox-central.service
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
[Unit]
|
||||
Description=Vnox Central Hub
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
User=vnox-central
|
||||
Group=vnox-central
|
||||
WorkingDirectory=/var/lib/vnox-central
|
||||
EnvironmentFile=/etc/vnox-central/hub.env
|
||||
ExecStart=/opt/vnox-central/current/vnox-hub
|
||||
Restart=on-failure
|
||||
RestartSec=5
|
||||
TimeoutStopSec=30
|
||||
StateDirectory=vnox-central
|
||||
StateDirectoryMode=0700
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
PrivateDevices=true
|
||||
ProtectHome=true
|
||||
ProtectSystem=strict
|
||||
ReadWritePaths=/var/lib/vnox-central
|
||||
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
|
||||
ProtectKernelTunables=true
|
||||
ProtectKernelModules=true
|
||||
ProtectControlGroups=true
|
||||
UMask=0077
|
||||
LimitNOFILE=8192
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
Loading…
Add table
Add a link
Reference in a new issue