From 54108c263fb19740596d09f9deea92464fd3593e Mon Sep 17 00:00:00 2001 From: urania Date: Wed, 24 Jun 2026 17:29:45 +0200 Subject: [PATCH] fix: remove terminal module and implement concurrent log stream limiting --- README.md | 2 - cmd/server/server.go | 87 ++++++-- cmd/server/service.go | 12 +- cmd/server/tls.go | 47 +--- go.mod | 2 - go.sum | 4 - internal/auth/login.go | 25 ++- internal/auth/login_test.go | 160 +++++++------- internal/auth/ratelimit.go | 72 ++++++ internal/auth/session.go | 71 +++++- internal/auth/session_test.go | 19 +- internal/auth/throttle.go | 19 +- internal/auth/tokens.go | 3 + internal/auth/tokens_test.go | 6 +- internal/config/config.go | 17 +- internal/config/config_test.go | 12 +- internal/modules/groups/groups.go | 8 +- internal/modules/groups/groups_test.go | 34 ++- internal/modules/networking/command_test.go | 38 +++- internal/modules/networking/hosts.go | 30 ++- .../networking/networking_handler_test.go | 11 +- internal/modules/networking/read.go | 2 +- internal/modules/networking/rollback.go | 20 +- internal/modules/packages/packages.go | 12 + internal/modules/packages/packages_test.go | 57 +++-- internal/modules/services/logs.go | 12 + internal/modules/services/logs_test.go | 91 +++++--- internal/modules/services/services_test.go | 70 +++--- internal/modules/storage/storage.go | 39 +++- internal/modules/storage/storage_test.go | 40 ++-- internal/modules/system/power_test.go | 40 +++- internal/modules/terminal/terminal.go | 209 ------------------ internal/modules/terminal/terminal_test.go | 124 ----------- internal/modules/users/module.go | 14 +- internal/modules/users/users.go | 20 +- internal/modules/users/users_handler_test.go | 2 +- internal/modules/users/users_test.go | 50 +++-- internal/mounts/mounts_test.go | 24 +- internal/openapitest/openapi_test.go | 4 +- internal/rbac/middleware_test.go | 148 +++++++------ 40 files changed, 851 insertions(+), 806 deletions(-) create mode 100644 internal/auth/ratelimit.go delete mode 100644 internal/modules/terminal/terminal.go delete mode 100644 internal/modules/terminal/terminal_test.go diff --git a/README.md b/README.md index 8fcecb0..28f968e 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,6 @@ API and declares its own permission vocabulary. and upgrade - streamed live over SSE. Auto-detects `dnf`, `apt`, or `pacman`. - **Networking** - List network interfaces, routing tables, and DNS settings; configure IPv4 settings with temporary applying and safety auto-rollback; bring interfaces up or down. - **Audit** - Read-only trail of every privileged write (who, what, when, result). -- **Terminal** - Interactive shell access. Upgrades connection to a WebSocket and spawns a PTY shell as the logged-in user (requires `root` permission). - **Meta** - Self-description for clients: `/api/_modules`, `/api/whoami`, `/api/health`. @@ -453,7 +452,6 @@ internal/modules concrete modules: packages - dnf/apt/pacman install/remove/upgrade (streamed) audit - read-only audit trail networking - network interfaces, routing tables, DNS, and IP configurations - terminal - interactive PTY shell over WebSocket internal/oscmd shared command runner (timeouts, stderr surfacing) + helpers internal/rbac roles, permissions ("*" wildcards), HTTP middleware (RBAC + CSRF) internal/audit SQLite-backed audit log writer diff --git a/cmd/server/server.go b/cmd/server/server.go index f60f2fc..9f16e3e 100644 --- a/cmd/server/server.go +++ b/cmd/server/server.go @@ -31,7 +31,6 @@ import ( "nadir/internal/modules/services" "nadir/internal/modules/storage" "nadir/internal/modules/system" - "nadir/internal/modules/terminal" "nadir/internal/modules/users" "nadir/internal/rbac" @@ -206,13 +205,12 @@ func runServer() { mods := []module.Module{ system.New(), services.New(cfg.LogFiles), - users.New(), + users.New(sessions), groups.New(), packages.New(), networking.New(), storage.New(), audit.New(auditStore), - terminal.New(sessions), } roles := rbac.New() @@ -236,6 +234,8 @@ func runServer() { humaConfig.DocsPath = "" api := humago.New(mux, humaConfig) + rateLimiter := auth.NewRateLimiter(100, time.Minute) + api.UseMiddleware(auth.RateLimitMiddleware(api, rateLimiter)) api.UseMiddleware(rbac.RbacMiddleware(api, sessions, tokenAuth, roles, auditStore)) for _, m := range mods { @@ -277,18 +277,18 @@ func runServer() { }) mux.HandleFunc("GET /docs", func(w http.ResponseWriter, _ *http.Request) { - // /docs needs to execute the Scalar bundle, so loosen the strict CSP set - // by secHeaders for this one page: allow scripts/styles from the jsdelivr - // CDN plus inline (Scalar uses inline