fix: comprehensive security, performance, and quality hardening

Security: apply AdminOnly middleware to mutating routes, require
ENCRYPTION_KEY and ADMIN_PASSWORD (no insecure defaults), restrict
CORS to same-origin, fix OIDC token delivery via cookie instead of
URL query param, add rate limiting on login, add MaxBytesReader,
validate volume paths against traversal, add security headers,
validate user roles, add Secure flag to OIDC cookie.

Performance: set SQLite MaxOpenConns(1) to prevent SQLITE_BUSY,
add FK indexes on 8 columns, track notifier goroutines with
WaitGroup for graceful shutdown, use GetRegistryByName instead of
GetAllRegistries in deployer, pass basePath param to avoid redundant
settings query, return empty slices from store to remove reflection.

Quality: refactor TriggerDeploy to delegate to runDeploy (~100 lines
removed), consolidate duplicated utilities (extractPort, boolToInt,
now, isTerminalStatus) into shared exports, migrate all log.Printf
to slog structured logging, use consistent webhook response envelope,
remove dead code (parseEnvVars, duplicate auth types).

UX: clean up NPM proxy on instance removal via API, add README with
quickstart guide, add .env.example, require ADMIN_PASSWORD in
docker-compose, document staging-net prerequisite.
This commit is contained in:
2026-03-29 12:49:24 +03:00
parent c5bfc586c1
commit be6ad15efc
32 changed files with 519 additions and 392 deletions
+4 -24
View File
@@ -3,10 +3,10 @@ package webhook
import (
"context"
"fmt"
"log"
"strconv"
"log/slog"
"strings"
"github.com/alexei/docker-watcher/internal/docker"
"github.com/alexei/docker-watcher/internal/store"
)
@@ -37,9 +37,9 @@ func AutoCreateProject(
if inspector != nil {
info, err := inspector.InspectImage(ctx, imageRef)
if err != nil {
log.Printf("[webhook] image inspection failed for %s (using defaults): %v", imageRef, err)
slog.Warn("webhook: image inspection failed, using defaults", "image", imageRef, "error", err)
} else {
port = extractPort(info.ExposedPorts)
port = docker.ExtractPort(info.ExposedPorts)
healthcheck = info.Healthcheck
}
}
@@ -89,23 +89,3 @@ func buildImageRef(parsed ParsedImage) string {
return ref
}
// extractPort parses the first exposed port from Docker EXPOSE entries.
// Entries are in the form "8080/tcp" or "8080". Returns 0 if none found.
func extractPort(exposedPorts []string) int {
if len(exposedPorts) == 0 {
return 0
}
// Take the first port entry.
raw := exposedPorts[0]
// Strip protocol suffix (e.g. "/tcp", "/udp").
if idx := strings.Index(raw, "/"); idx != -1 {
raw = raw[:idx]
}
port, err := strconv.Atoi(raw)
if err != nil {
return 0
}
return port
}