Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Bound control-plane request reads

pulse-triage[bot]ba4c157aa2b8
diff --git a/internal/cloudcp/server.go b/internal/cloudcp/server.go
index 28d3835a42..80ccc94e70 100644
--- a/internal/cloudcp/server.go
+++ b/internal/cloudcp/server.go
@@ -19,6 +19,25 @@ import (
"github.com/rs/zerolog/log"
)
+const (
+ controlPlaneReadHeaderTimeout = 15 * time.Second
+ controlPlaneReadTimeout = 30 * time.Second
+ controlPlaneIdleTimeout = 120 * time.Second
+)
+
+func newControlPlaneHTTPServer(addr string, handler http.Handler) *http.Server {
+ return &http.Server{
+ Addr: addr,
+ Handler: handler,
+ ReadHeaderTimeout: controlPlaneReadHeaderTimeout,
+ // The control plane has no streaming request bodies. Bound the complete
+ // request read so a client cannot retain a handler indefinitely after
+ // sending valid headers and then stalling a small JSON body.
+ ReadTimeout: controlPlaneReadTimeout,
+ IdleTimeout: controlPlaneIdleTimeout,
+ }
+}
+
// Run starts the control plane HTTP server with graceful shutdown.
func Run(ctx context.Context, version string) error {
logging.Init(logging.Config{
@@ -141,12 +160,7 @@ func Run(ctx context.Context, version string) error {
RegisterRoutes(mux, deps)
addr := fmt.Sprintf("%s:%d", cfg.BindAddress, cfg.Port)
- srv := &http.Server{
- Addr: addr,
- Handler: CPSecurityHeaders(mux),
- ReadHeaderTimeout: 15 * time.Second,
- IdleTimeout: 120 * time.Second,
- }
+ srv := newControlPlaneHTTPServer(addr, CPSecurityHeaders(mux))
// Create derived context for background goroutines
ctx, cancel := context.WithCancel(ctx)
diff --git a/internal/cloudcp/server_test.go b/internal/cloudcp/server_test.go
index f36642077f..31f26f701b 100644
--- a/internal/cloudcp/server_test.go
+++ b/internal/cloudcp/server_test.go
@@ -2,12 +2,37 @@ package cloudcp
import (
"context"
+ "net/http"
"os"
"path/filepath"
"strings"
"testing"
)
+func TestNewControlPlaneHTTPServerBoundsRequestReads(t *testing.T) {
+ handler := http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})
+ server := newControlPlaneHTTPServer("127.0.0.1:7656", handler)
+
+ if server.Addr != "127.0.0.1:7656" {
+ t.Fatalf("Addr = %q, want %q", server.Addr, "127.0.0.1:7656")
+ }
+ if server.Handler == nil {
+ t.Fatal("Handler = nil, want configured handler")
+ }
+ if server.ReadHeaderTimeout != controlPlaneReadHeaderTimeout {
+ t.Fatalf("ReadHeaderTimeout = %s, want %s", server.ReadHeaderTimeout, controlPlaneReadHeaderTimeout)
+ }
+ if server.ReadTimeout != controlPlaneReadTimeout {
+ t.Fatalf("ReadTimeout = %s, want %s", server.ReadTimeout, controlPlaneReadTimeout)
+ }
+ if server.ReadTimeout <= server.ReadHeaderTimeout {
+ t.Fatalf("ReadTimeout = %s, want longer than header timeout %s", server.ReadTimeout, server.ReadHeaderTimeout)
+ }
+ if server.IdleTimeout != controlPlaneIdleTimeout {
+ t.Fatalf("IdleTimeout = %s, want %s", server.IdleTimeout, controlPlaneIdleTimeout)
+ }
+}
+
func TestBaseDomainFromURL(t *testing.T) {
tests := []struct {
name string