Require step-up password confirmation for shells, terminals and file changes

A new elevate request verifies the web sign-in password (scrypt hash, read-only,
rate-limited, constant time) and elevates that connection for 15 minutes.
chat_shell_run/input, rename/move/delete, terminal_open/input and POST /files
(via a per-connection upload token) are refused with code elevation_required
until then.
This commit is contained in:
2026-11-10 01:21:15 +00:00
parent a706739088
commit f11ff8650d
12 changed files with 963 additions and 1 deletions
+11 -1
View File
@@ -72,6 +72,11 @@ type Options struct {
// them so they never share the real server's tmux sessions.
TerminalTmuxSocket string
TerminalWithoutTmux bool
// WebAuthFile is the web sign-in password file step-up re-authentication
// verifies against (see elevation.go); empty disables the gate.
// ElevationTTL is how long one confirmation lasts (default 15 minutes).
WebAuthFile string
ElevationTTL time.Duration
}
// Handler serves the persistent connection with default options. Canceling ctx
@@ -188,7 +193,8 @@ func HandlerWithOptions(ctx context.Context, options Options, stores ...*pipelin
}
mux.HandleFunc("GET /discovery", serveServerDiscovery)
mux.HandleFunc("GET /files", serveHomeFile)
mux.HandleFunc("POST /files", serveHomeFileUpload)
elevation := newElevationGate(options.WebAuthFile, options.ElevationTTL)
mux.HandleFunc("POST /files", elevation.requireElevationHTTP(serveHomeFileUpload))
mux.HandleFunc("POST /chat-uploads", serveChatUpload)
mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
@@ -233,6 +239,7 @@ func HandlerWithOptions(ctx context.Context, options Options, stores ...*pipelin
// clientID is this connection's identity for chat session claims: a
// second client is refused a session another connection holds.
clientID := chatClientToken()
defer elevation.forget(clientID)
// Drop every run subscription this connection holds when the read loop
// returns, so no subscriber, goroutine or timer outlives the connection.
defer events.unsubscribeClient(clientID)
@@ -283,6 +290,9 @@ func HandlerWithOptions(ctx context.Context, options Options, stores ...*pipelin
_ = write(protocol.Message{Type: protocol.Error, ID: request.ID, Error: "pipeline authoring is disabled on this execution server; ask the operator to publish through an explicitly enabled authoring server"})
continue
}
if elevation.handle(request, clientID, write) || elevation.refuse(request, clientID, write) {
continue
}
if isChatSearch(request) {
cancelChatSearch()
searchCtx, cancel := context.WithCancel(connCtx)