navid/veinsforge / commit
bfca04557da7
Navid M <navidmomtahen@gmail.com> · 2026-11-28
parents: 2680d964b4aa
Browse files at this commit · Download source
--- a/DEPLOY.md+++ b/DEPLOY.md@@ -38,6 +38,7 @@ 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@@ -194,5 +195,8 @@ key changes. Do not edit `.veins/access` by hand on a served repository. - The app runs one `vn serve` supervisor process. Do not start a second native server on the same port.+- `VEINSFORGE_USER_QUOTA_MB` caps stored pack/index bytes per owner namespace+ (user or organisation). `vn` enforces the cap during push; set it to `0` to+ disable it. - SQLite uses WAL with a 5 second busy timeout. Keep the data directory on local disk, not a network filesystem.--- a/cmd/veinsforge/main.go+++ b/cmd/veinsforge/main.go@@ -62,8 +62,8 @@ environment: VEINSFORGE_ADDR, VEINSFORGE_DATA, VEINSFORGE_BASE_URL, VEINSFORGE_VN_BIN, VEINSFORGE_NATIVE_LISTEN, VEINSFORGE_NATIVE_HOST, VEINSFORGE_NATIVE_CERT,- VEINSFORGE_NATIVE_KEY, VEINSFORGE_TRUSTED_PROXIES, VEINSFORGE_ADMIN_USER,- VEINSFORGE_ADMIN_PASSWORD+ VEINSFORGE_NATIVE_KEY, VEINSFORGE_TRUSTED_PROXIES, VEINSFORGE_USER_QUOTA_MB,+ VEINSFORGE_ADMIN_USER, VEINSFORGE_ADMIN_PASSWORD `) } @@ -134,7 +134,7 @@ } logger.Printf("service key %s (%s)", runner.KeyPublic, runner.KeyFinger) - native := vn.NewNativeServer(cfg.VNBin, cfg.VNHome, cfg.NativeListen, cfg.NativeAddress(), cfg.RepoRoot, cfg.NativeCert, cfg.NativeKey, cfg.NativeHost, logger)+ native := vn.NewNativeServer(cfg.VNBin, cfg.VNHome, cfg.NativeListen, cfg.NativeAddress(), cfg.RepoRoot, cfg.NativeCert, cfg.NativeKey, cfg.NativeHost, cfg.UserQuotaBytes, logger) ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) defer cancel() if err := native.Start(ctx); err != nil {--- a/deploy/veinsforge.env.example+++ b/deploy/veinsforge.env.example@@ -7,6 +7,9 @@ # Native protocol. Use 0.0.0.0:7419 only if external clients need it. VEINSFORGE_NATIVE_LISTEN=0.0.0.0:7419 VEINSFORGE_NATIVE_HOST=forge.example.com++# Per-owner storage cap for served repositories. 0 disables it.+VEINSFORGE_USER_QUOTA_MB=50 # Trust X-Forwarded-For only from the local reverse proxy. VEINSFORGE_TRUSTED_PROXIES=127.0.0.1/32,::1/128--- a/internal/config/config.go+++ b/internal/config/config.go@@ -33,6 +33,7 @@ SessionTTL time.Duration MaxUploadBytes int64 MaxAvatarBytes int64+ UserQuotaBytes int64 ReadHeaderTimeout time.Duration ReadTimeout time.Duration WriteTimeout time.Duration@@ -63,6 +64,7 @@ SessionTTL: time.Duration(envInt("VEINSFORGE_SESSION_DAYS", 30)) * 24 * time.Hour, MaxUploadBytes: int64(envInt("VEINSFORGE_MAX_UPLOAD_MB", 10)) << 20, MaxAvatarBytes: int64(envInt("VEINSFORGE_MAX_AVATAR_MB", 2)) << 20,+ UserQuotaBytes: int64(envInt("VEINSFORGE_USER_QUOTA_MB", 50)) << 20, ReadHeaderTimeout: time.Duration(envInt("VEINSFORGE_READ_HEADER_SECONDS", 5)) * time.Second, ReadTimeout: time.Duration(envInt("VEINSFORGE_READ_SECONDS", 60)) * time.Second, WriteTimeout: time.Duration(envInt("VEINSFORGE_WRITE_SECONDS", 60)) * time.Second,@@ -146,6 +148,9 @@ } if c.RateLimitBurst <= 0 { c.RateLimitBurst = 60+ }+ if c.UserQuotaBytes < 0 {+ c.UserQuotaBytes = 0 } return nil }--- a/internal/vn/serve.go+++ b/internal/vn/serve.go@@ -16,6 +16,7 @@ "os" "os/exec" "path/filepath"+ "strconv" "strings" "sync" "time"@@ -30,6 +31,7 @@ CertPath string KeyPath string Host string+ QuotaBytes int64 Logger *log.Logger Fingerprint string @@ -38,10 +40,10 @@ lastErr string } -func NewNativeServer(bin, home, listen, address, repoRoot, certPath, keyPath, host string, logger *log.Logger) *NativeServer {+func NewNativeServer(bin, home, listen, address, repoRoot, certPath, keyPath, host string, quotaBytes int64, logger *log.Logger) *NativeServer { return &NativeServer{ Bin: bin, Home: home, Listen: listen, Address: address, RepoRoot: repoRoot,- CertPath: certPath, KeyPath: keyPath, Host: host, Logger: logger,+ CertPath: certPath, KeyPath: keyPath, Host: host, QuotaBytes: quotaBytes, Logger: logger, } } @@ -98,12 +100,17 @@ backoff = minDuration(backoff*2, 30*time.Second) continue }- cmd := exec.CommandContext(ctx, n.Bin, "serve",+ args := []string{+ "serve", "-listen", n.Listen, "-root", n.RepoRoot, "-tls-cert", n.CertPath, "-tls-key", n.KeyPath,- )+ }+ if n.QuotaBytes > 0 {+ args = append(args, "-quota", strconv.FormatInt(n.QuotaBytes, 10))+ }+ cmd := exec.CommandContext(ctx, n.Bin, args...) cmd.Env = append(os.Environ(), "HOME="+n.Home, "XDG_CONFIG_HOME="+filepath.Join(n.Home, ".config")) if n.Logger != nil { n.Logger.Printf("starting native server: %s -listen %s -root %s", n.Bin, n.Listen, n.RepoRoot)