navid/veinsforge / f7153a2b9d81c99f7cdc3796d834953db63f94cd85065044ffee7659e7705b27 / DEPLOY.md
DEPLOY.md
← root · 6732 bytes · raw · download · view source
Deploying veinsforge
veinsforge is a single Go binary plus the vn binary. It supervises its own
vn serve process for the native protocol, manages SQLite migrations, and
writes .veins/access policies from database permissions.
1. Build
cd frontend
CGO_ENABLED=0 go build -trimpath -buildvcs=false -ldflags="-s -w" -o veinsforge ./cmd/veinsforge
modernc.org/sqlite is pure Go, so the service builds without CGO. Put the
built binary and a recent vn binary on the server:
install -m 0755 veinsforge /usr/local/bin/veinsforge
install -m 0755 vn /usr/local/bin/vn
2. Service account and directories
useradd --system --home-dir /var/lib/veinsforge --shell /usr/sbin/nologin veinsforge
install -d -o veinsforge -g veinsforge -m 0700 /var/lib/veinsforge /etc/veinsforge
install -m 0644 deploy/veinsforge.service /etc/systemd/system/veinsforge.service
install -m 0600 deploy/veinsforge.env.example /etc/veinsforge/veinsforge.env
Edit /etc/veinsforge/veinsforge.env. A typical IONOS setup behind Caddy:
VEINSFORGE_ADDR=127.0.0.1:8080
VEINSFORGE_DATA=/var/lib/veinsforge
VEINSFORGE_BASE_URL=https://forge.example.com
VEINSFORGE_VN_BIN=/usr/local/bin/vn
VEINSFORGE_NATIVE_LISTEN=0.0.0.0:7419
VEINSFORGE_NATIVE_HOST=forge.example.com
VEINSFORGE_TRUSTED_PROXIES=127.0.0.1/32,::1/128
VEINSFORGE_USER_QUOTA_MB=50
VEINSFORGE_NATIVE_LISTEN=127.0.0.1:7419 (the default) keeps the native
protocol local-only. Set it to 0.0.0.0:7419 only when you actually want
clients outside the machine to clone and push.
3. Create the first administrator
Do this before exposing the web port. The first signup also becomes an administrator, so on a fresh public host an unauthenticated visitor could take that role.
sudo -u veinsforge /usr/local/bin/veinsforge create-admin \
-data /var/lib/veinsforge \
-username admin \
-password 'use-a-long-random-password'
If the password contains characters your shell treats specially, such as !,
read it silently and pass it through stdin instead:
read -rsp 'Admin password: ' ADMIN_PASSWORD; echo
printf '%s' "$ADMIN_PASSWORD" | sudo -u veinsforge /usr/local/bin/veinsforge create-admin \
-data /var/lib/veinsforge \
-username admin \
-password-stdin
Alternatively set VEINSFORGE_ADMIN_USER and VEINSFORGE_ADMIN_PASSWORD in
the environment file for the first start. After the account exists, remove the
password from the environment file.
4. TLS in front of the web UI
Use Caddy (or nginx) for public HTTPS. Caddy obtains and renews certificates automatically:
forge.example.com {
encode zstd gzip
header {
Strict-Transport-Security "max-age=31536000; includeSubDomains"
X-Content-Type-Options "nosniff"
}
reverse_proxy 127.0.0.1:8080
}
Set VEINSFORGE_BASE_URL=https://forge.example.com. The app then marks session
and CSRF cookies Secure and trusts X-Forwarded-For only from the proxies
listed in VEINSFORGE_TRUSTED_PROXIES.
5. Native protocol TLS
On first start, if VEINSFORGE_NATIVE_CERT / VEINSFORGE_NATIVE_KEY do not
exist, the service generates a self-signed certificate in
$VEINSFORGE_DATA/native/ and prints its SHA-256 pin. The repository page shows
the pin; clients can clone with:
vn clone veins://forge.example.com:7419/owner/repo -key:your-key -pin:<pin>
If you already have a publicly trusted certificate, point
VEINSFORGE_NATIVE_CERT and VEINSFORGE_NATIVE_KEY at it. Clients can then
omit -pin. Restart the service after changing certificates.
The native server authenticates every push with the Ed25519 keys registered in the web UI. Public repositories also allow anonymous read. Private repositories only include keys for users/teams with access.
After registering a key, clients can select it once for every repository on this server:
vn auth use your-key
# or scope it to one host:
vn auth use your-key forge.example.com:7419
vn clone, vn fetch, vn push, and vn whoami then fall back to that key
when a repository has no explicit remote.<name>.key.
6. Firewall and basic DDoS posture
The web application has per-IP token buckets, auth/write-specific limits, concurrent-request caps, connection limits, body limits, and HTTP timeouts. That is not a substitute for a network firewall or a provider-level DDoS filter.
Example nftables policy for a VPS (adjust the interface name):
table inet filter {
chain input {
type filter hook input priority 0; policy drop;
ct state established,related accept
iif lo accept
ip protocol icmp accept
ip6 nexthdr icmpv6 accept
tcp dport 22 accept
tcp dport { 80, 443 } accept
# Native veins protocol. Rate-limit new connections.
tcp dport 7419 ct state new limit rate 20/second burst 40 packets accept
tcp dport 7419 ct state new drop
}
}
Keep SSH behind key authentication. Consider fail2ban on repeated
429/403 responses and on vn serve authentication failures, and keep the
host and vn binary patched.
7. systemd
systemctl daemon-reload
systemctl enable --now veinsforge
journalctl -u veinsforge -f
The unit uses ProtectSystem=strict; the only writable path is
/var/lib/veinsforge, which contains:
veinsforge.db— SQLite (WAL mode)repos/— served veins repositoriescache/browse/— disposable read-only checkoutsattachments/,avatars/— filesystem assetshome/— the service Ed25519 key used for cache/merge operationsnative/— generated native TLS certificate/key and pin
8. Backups
Back up SQLite with the online backup command, then copy object storage and filesystem assets:
sqlite3 /var/lib/veinsforge/veinsforge.db \
".backup '/var/backups/veinsforge-$(date +%F).db'"
tar -C /var/lib/veinsforge -czf /var/backups/veinsforge-data-$(date +%F).tar.gz \
repos attachments avatars home native
The browse cache is disposable and should not be backed up. Test restores on a separate host before relying on them.
9. Operational notes
- Registration is open by default after the first administrator exists. An administrator can close it in Admin → Site settings.
- Access files are regenerated from SQLite periodically and after permission or
key changes. Do not edit
.veins/accessby hand on a served repository. - The app runs one
vn servesupervisor process. Do not start a second native server on the same port. VEINSFORGE_USER_QUOTA_MBcaps stored pack/index bytes per owner namespace (user or organisation).vnenforces the cap during push; set it to0to disable it.- SQLite uses WAL with a 5 second busy timeout. Keep the data directory on local disk, not a network filesystem.