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
+18 -7
View File
@@ -109,11 +109,12 @@ func TestElevationBackoffGlobalCapAndExpiry(t *testing.T) {
t.Fatalf("global cap not applied: %v", err)
}
now = now.Add(elevationGlobalWindow)
if _, err := gate.elevate("fresh", "right password here"); err != nil {
fresh := connectionElevationKey("fresh")
if _, err := gate.elevate(fresh, "right password here"); err != nil {
t.Fatalf("global window did not drain: %v", err)
}
gate.forget("fresh")
if gate.elevated("fresh") {
gate.closed(fresh)
if gate.elevated(fresh) {
t.Fatal("closed connection stayed elevated")
}
}
@@ -156,8 +157,6 @@ func TestGatedRequestsNeedElevationOnTheSameConnection(t *testing.T) {
{Type: protocol.DeletePath, ID: "delete", DeletePath: &protocol.DeletePathRequest{Path: "~/absent-elevation-test"}},
{Type: protocol.RenamePath, ID: "rename"},
{Type: protocol.MovePath, ID: "move"},
{Type: protocol.TerminalOpen, ID: "terminal"},
{Type: protocol.TerminalInput, ID: "terminal-input"},
}
for _, request := range gated {
reply := elevationRequest(t, ctx, conn, request)
@@ -165,6 +164,16 @@ func TestGatedRequestsNeedElevationOnTheSameConnection(t *testing.T) {
t.Fatalf("%s not refused: %+v", request.Type, reply)
}
}
// Terminals are not gated (su -l asks for the account password); this
// server has no store, so terminal_open fails on its own terms.
for _, request := range []protocol.Message{
{Type: protocol.TerminalOpen, ID: "terminal"},
{Type: protocol.TerminalInput, ID: "terminal-input", TerminalRequest: &protocol.TerminalRequest{TerminalID: "absent", Data: "x"}},
} {
if reply := elevationRequest(t, ctx, conn, request); reply.Code == protocol.ErrorElevationRequired {
t.Fatalf("%s gated: %+v", request.Type, reply)
}
}
// Reads are not gated.
if reply := elevationRequest(t, ctx, conn, protocol.Message{Type: protocol.Ping, ID: "ping"}); reply.Type != protocol.Pong {
t.Fatalf("ping refused: %+v", reply)
@@ -233,11 +242,13 @@ func TestElevationGateOffWithoutWebAuthFile(t *testing.T) {
// A present but unusable file keeps the gate closed.
broken := writeTestAuthJSON(t, map[string]any{"secret": "x"})
closed := newElevationGate(broken, 0)
if !closed.refuse(protocol.Message{Type: protocol.TerminalOpen}, "a", write) {
if !closed.refuse(protocol.Message{Type: protocol.ChatShellRun}, "a", write) {
t.Fatal("unusable password file opened the gate")
}
if ElevationTTLFromEnvironment(func(string) string { return "30" }) != 30*time.Minute ||
ElevationTTLFromEnvironment(func(string) string { return "0" }) != DefaultElevationTTL {
ElevationTTLFromEnvironment(func(string) string { return "1440" }) != 24*time.Hour ||
ElevationTTLFromEnvironment(func(string) string { return "43201" }) != DefaultElevationTTL ||
ElevationTTLFromEnvironment(func(string) string { return "0" }) != DefaultElevationTTL || DefaultElevationTTL != 24*time.Hour {
t.Fatal("PIPELINES_ELEVATION_MINUTES not honoured")
}
}