Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
feat: support direct https setup via environment variables (#1877)
Kyle Mendell11369aa41deb
diff --git a/.env.example b/.env.exampleindex def8c06d8..8ed8c8245 100644--- a/.env.example+++ b/.env.example@@ -8,6 +8,12 @@ ENVIRONMENT=productionPORT=3552APP_URL=https://your-domain.com+# Optional direct TLS server mode (HTTP/2 over TLS)+# Leave disabled when running behind a reverse proxy that terminates TLS.+# TLS_ENABLED=false+# TLS_CERT_FILE=/path/to/fullchain.pem+# TLS_KEY_FILE=/path/to/privkey.pem+# User/Group IDs for file permissions (used by Docker)PUID=1000PGID=1000diff --git a/backend/internal/bootstrap/bootstrap.go b/backend/internal/bootstrap/bootstrap.goindex 984be6b97..01b108ce0 100644--- a/backend/internal/bootstrap/bootstrap.go+++ b/backend/internal/bootstrap/bootstrap.go@@ -250,32 +250,57 @@ func runServices(appCtx context.Context, cfg *config.Config, router http.HandlerlistenAddr := cfg.ListenAddr()httpHandler := router+ useTLS := cfg.TLSEnabled+ tlsCertFile := strings.TrimSpace(cfg.TLSCertFile)+ tlsKeyFile := strings.TrimSpace(cfg.TLSKeyFile)++ if useTLS && (tlsCertFile == "" || tlsKeyFile == "") {+ return fmt.Errorf("TLS_ENABLED requires both TLS_CERT_FILE and TLS_KEY_FILE")+ }var grpcServer *grpc.Serverif !cfg.AgentMode && tunnelServer != nil {grpcServer = grpc.NewServer(tunnelServer.GRPCServerOptions(appCtx)...)tunnelpb.RegisterTunnelServiceServer(grpcServer, tunnelServer)- httpHandler = h2c.NewHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ httpHandler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {if isTunnelGRPCRequestInternal(r) {grpcReq := normalizeTunnelGRPCRequestPathInternal(r)grpcServer.ServeHTTP(w, grpcReq)return}router.ServeHTTP(w, r)- }), &http2.Server{})+ })slog.InfoContext(appCtx, "Using shared HTTP/gRPC listener for edge tunnel", "addr", listenAddr)}+ var protocols http.Protocols+ protocols.SetHTTP1(true)+ if useTLS {+ protocols.SetHTTP2(true)+ } else {+ protocols.SetUnencryptedHTTP2(true)+ httpHandler = h2c.NewHandler(httpHandler, &http2.Server{})+ }+srv := &http.Server{Addr: listenAddr,Handler: httpHandler,+ Protocols: &protocols,ReadHeaderTimeout: 5 * time.Second,}go func() {- slog.InfoContext(appCtx, "Starting HTTP server", "addr", listenAddr, "listen", cfg.Listen, "port", cfg.Port)- if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {+ slog.InfoContext(appCtx, "Starting HTTP server", "addr", listenAddr, "listen", cfg.Listen, "port", cfg.Port, "tls_enabled", useTLS)++ var err error+ if useTLS {+ err = srv.ListenAndServeTLS(tlsCertFile, tlsKeyFile)+ } else {+ err = srv.ListenAndServe()+ }++ if err != nil && !errors.Is(err, http.ErrServerClosed) {slog.ErrorContext(appCtx, "Failed to start server", "error", err)}}()diff --git a/backend/internal/config/config.go b/backend/internal/config/config.goindex 50e62f2aa..54fc40275 100644--- a/backend/internal/config/config.go+++ b/backend/internal/config/config.go@@ -31,6 +31,9 @@ type Config struct {DatabaseURL string `env:"DATABASE_URL" default:"file:data/arcane.db?_pragma=journal_mode(WAL)&_pragma=busy_timeout(2500)&_txlock=immediate" options:"file"`Port string `env:"PORT" default:"3552"`Listen string `env:"LISTEN" default:""`+ TLSEnabled bool `env:"TLS_ENABLED" default:"false"`+ TLSCertFile string `env:"TLS_CERT_FILE" default:""`+ TLSKeyFile string `env:"TLS_KEY_FILE" default:""`Environment AppEnvironment `env:"ENVIRONMENT" default:"production"`JWTSecret string `env:"JWT_SECRET" default:"default-jwt-secret-change-me" options:"file"` //nolint:gosec // configuration field name is part of stable config APIEncryptionKey string `env:"ENCRYPTION_KEY" default:"arcane-dev-key-32-characters!!!" options:"file"`diff --git a/backend/internal/config/config_test.go b/backend/internal/config/config_test.goindex 5514c3f12..24cd096d2 100644--- a/backend/internal/config/config_test.go+++ b/backend/internal/config/config_test.go@@ -262,6 +262,37 @@ func TestConfig_ListenAddr(t *testing.T) {}}+func TestConfig_TLSSettings(t *testing.T) {+ origTLSEnabled := os.Getenv("TLS_ENABLED")+ origTLSCertFile := os.Getenv("TLS_CERT_FILE")+ origTLSKeyFile := os.Getenv("TLS_KEY_FILE")+ defer restoreEnv("TLS_ENABLED", origTLSEnabled)+ defer restoreEnv("TLS_CERT_FILE", origTLSCertFile)+ defer restoreEnv("TLS_KEY_FILE", origTLSKeyFile)++ t.Run("defaults to tls disabled", func(t *testing.T) {+ unsetEnv(t, "TLS_ENABLED")+ unsetEnv(t, "TLS_CERT_FILE")+ unsetEnv(t, "TLS_KEY_FILE")++ cfg := Load()+ assert.False(t, cfg.TLSEnabled)+ assert.Equal(t, "", cfg.TLSCertFile)+ assert.Equal(t, "", cfg.TLSKeyFile)+ })++ t.Run("loads tls settings from env", func(t *testing.T) {+ setEnv(t, "TLS_ENABLED", "true")+ setEnv(t, "TLS_CERT_FILE", "/etc/ssl/certs/fullchain.pem")+ setEnv(t, "TLS_KEY_FILE", "/etc/ssl/private/privkey.pem")++ cfg := Load()+ assert.True(t, cfg.TLSEnabled)+ assert.Equal(t, "/etc/ssl/certs/fullchain.pem", cfg.TLSCertFile)+ assert.Equal(t, "/etc/ssl/private/privkey.pem", cfg.TLSKeyFile)+ })+}+func TestConfig_GetManagerGRPCAddr(t *testing.T) {t.Run("uses manager api url explicit port when present", func(t *testing.T) {cfg := &Config{