Keep step-up elevation for the signed-in session and stop gating terminals

The proxy forwards an HMAC-derived session id (X-Pipelines-Session) on
/connect and POST /files; the server trusts it only on token-authenticated
requests and keys elevation by it, so reconnects stay elevated up to a 24 h
cap. Terminals rely on their su -l login. The app no longer forgets the
elevation on disconnect and asks again only on a fresh refusal.
This commit is contained in:
2026-11-10 03:00:45 +00:00
parent 60b4c495f1
commit 1ad85de1f1
19 changed files with 876 additions and 165 deletions
+13 -6
View File
@@ -10,12 +10,15 @@ import (
)
// requireElevationHTTP guards an HTTP route that changes the operator's files.
// The upload travels outside the websocket, so the elevated connection's token
// (protocol.ElevationHeader) authorises it; it is valid only while that
// connection stays open and elevated.
// The upload travels outside the websocket. It is allowed when the web session
// the proxy reports is elevated, or when it carries a live elevation's token
// (protocol.ElevationHeader; a connection-only elevation's token ends with its
// connection).
func (g *elevationGate) requireElevationHTTP(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
if g.tokenValid(r.Header.Get(protocol.ElevationHeader)) || !g.enabled() {
session := trustedSession(r)
if (session != "" && g.elevated(sessionElevationKey(session))) ||
g.tokenValid(r.Header.Get(protocol.ElevationHeader)) || !g.enabled() {
next(w, r)
return
}
@@ -29,11 +32,15 @@ func (g *elevationGate) requireElevationHTTP(next http.HandlerFunc) http.Handler
}
}
// ElevationTTLFromEnvironment reads PIPELINES_ELEVATION_MINUTES (1 to 720);
// maxElevationMinutes is the longest PIPELINES_ELEVATION_MINUTES accepted:
// 30 days, the longest a remembered web session lasts.
const maxElevationMinutes = 30 * 24 * 60
// ElevationTTLFromEnvironment reads PIPELINES_ELEVATION_MINUTES (1 to 43200);
// anything else keeps DefaultElevationTTL.
func ElevationTTLFromEnvironment(getenv func(string) string) time.Duration {
minutes, err := strconv.Atoi(getenv("PIPELINES_ELEVATION_MINUTES"))
if err != nil || minutes < 1 || minutes > 720 {
if err != nil || minutes < 1 || minutes > maxElevationMinutes {
return DefaultElevationTTL
}
return time.Duration(minutes) * time.Minute