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:
@@ -90,27 +90,53 @@ the server-wide window still applies.
|
||||
native app accept both names.
|
||||
|
||||
**Step-up re-authentication.** A session alone can no longer run a shell. The
|
||||
following now need a password confirmation on the same websocket connection
|
||||
within the last 15 minutes (`PIPELINES_ELEVATION_MINUTES`, 1–720):
|
||||
following need one password confirmation per signed-in web session:
|
||||
- `chat_shell_run`, `chat_shell_input`;
|
||||
- `rename_path`, `move_path`, `delete_path`;
|
||||
- `terminal_open`, `terminal_input`;
|
||||
- `POST /files`.
|
||||
|
||||
Terminals (`terminal_open`, `terminal_input`) are not gated: each terminal
|
||||
starts `su -l`, which asks for the OS account password itself.
|
||||
|
||||
The flow:
|
||||
- The client sends `{"type":"elevate","password":…}`. The Go server reads the
|
||||
auth file read-only: it must be a regular file, owned by the user, mode 0600.
|
||||
- On success the reply is `elevated` with `{expires_at, seconds, token}`.
|
||||
- A refused request gets `{"type":"error","code":"elevation_required"}`.
|
||||
- A wrong password gets `elevation_failed`. Each wrong password doubles that
|
||||
connection's wait (1 s, up to 1 min). 10 failures per 5 min across the server
|
||||
session's wait (1 s, up to 1 min). 10 failures per 5 min across the server
|
||||
block all attempts. Only one scrypt check runs at a time.
|
||||
|
||||
Uploads travel outside the websocket. They carry the token in
|
||||
`X-Pipelines-Elevation`. The token lives only in memory and dies when its
|
||||
connection closes or expires. A refused upload gets 403
|
||||
`{"code":"elevation_required"}`. The peer relay forwards the header, so each
|
||||
machine elevates through its own gateway with its own password.
|
||||
How long it lasts (2026-11-10 change):
|
||||
- The Go server cannot see the cookie, so the proxy tells it which session a
|
||||
request belongs to. On `/connect` upgrades and `POST /files` the proxy sets
|
||||
`X-Pipelines-Session` to `AuthStore.sessionId(token)`: an HMAC, under the
|
||||
cookie secret, of the token's generation, the revoke-all time and the token
|
||||
id. It is never the cookie. Any client-supplied copy of the header is dropped.
|
||||
- The server trusts the header only on a request that carried the configured
|
||||
server token (`request_boundary.go`); otherwise it is removed and ignored.
|
||||
- Elevation is keyed by that id. Every connection and reconnect of the same
|
||||
browser or app sign-in stays elevated, up to a cap of 24 hours
|
||||
(`PIPELINES_ELEVATION_MINUTES`, 1–43200).
|
||||
- The session ending ends it. Logout revokes the token id. A password change
|
||||
bumps the generation and secret. Revoke-all invalidates every older token.
|
||||
In each case the proxy closes the session's sockets and refuses its cookie,
|
||||
and the next sign-in derives a new id, so the old elevation is never named
|
||||
again. It expires in server memory at the cap; a server restart forgets it.
|
||||
- A connection without a trusted session id (no server token configured, or a
|
||||
direct local client) elevates only itself, until it closes, as before.
|
||||
|
||||
Uploads travel outside the websocket. An elevated session's upload is allowed
|
||||
through its `X-Pipelines-Session`. The `X-Pipelines-Elevation` token also still
|
||||
works. It lives only in memory and lasts as long as its elevation: a session's
|
||||
token survives reconnects, a connection-only token dies with its connection. A
|
||||
refused upload gets 403 `{"code":"elevation_required"}`.
|
||||
|
||||
Peer relay: the relay sends a remote machine only its own peer cookie and a
|
||||
fixed header list, never `X-Pipelines-Session`. The remote proxy derives its
|
||||
own id from that cookie, so each machine elevates through its own gateway with
|
||||
its own password. It stays elevated for as long as the relay's sign-in to that
|
||||
machine lasts.
|
||||
|
||||
When does the gate apply?
|
||||
- **Auth file exists**: the gate is on.
|
||||
@@ -119,9 +145,12 @@ When does the gate apply?
|
||||
- **Auth file exists but is unusable**: the gate stays closed (fail closed).
|
||||
|
||||
In the app, one native dialog per machine (Material, or Cupertino on Apple
|
||||
platforms) asks for the password once. The app then retries the refused request.
|
||||
Concurrent refusals share one dialog. The elevation is forgotten when the
|
||||
connection drops.
|
||||
platforms) asks for the password. The app then retries the refused request.
|
||||
Concurrent refusals share one dialog. The app no longer forgets the elevation
|
||||
when the connection drops. It asks again only when the server answers a fresh
|
||||
`elevation_required`: the session ended, the cap passed, or an older server
|
||||
that elevates one connection. So it asks at most once per machine per app run
|
||||
while the session is valid.
|
||||
|
||||
## What the operator must do on the live install
|
||||
|
||||
@@ -151,8 +180,12 @@ for on the terminal.
|
||||
|
||||
## Not covered / residual
|
||||
|
||||
- `terminal_output` (attaching to and reading an existing terminal) is not
|
||||
gated. Typing into one (`terminal_input`) is.
|
||||
- Terminals are not gated by elevation (since 2026-11-10). A terminal's `su -l`
|
||||
login is the barrier. Once a terminal is logged in, any connection of a
|
||||
signed-in session can read it (`terminal_output`) and type into it
|
||||
(`terminal_input`).
|
||||
- Session elevation lives in server memory keyed by the derived id. A revoked
|
||||
session's entry is never named again, but it stays in memory until its cap.
|
||||
- `/chat-uploads` (chat attachments into the chat's upload area) is not gated.
|
||||
- The server-wide login window can lock the real operator out during an attack.
|
||||
That is the trade-off that bounds guessing.
|
||||
@@ -212,3 +245,49 @@ logged-out cookie still signed in: false
|
||||
Every browser and device was signed out; sign in again with the same password.
|
||||
password occurrences in server.log / web.log: 0 / 0
|
||||
```
|
||||
|
||||
## Session-long elevation, terminals ungated (2026-11-10, later)
|
||||
|
||||
The operator asked to be asked for the password once, not for every command,
|
||||
and not before opening a terminal. The change is described under "Step-up
|
||||
re-authentication" above.
|
||||
|
||||
Checks:
|
||||
- `umask 022 && go test ./internal/server ./internal/protocol ./internal/servertoken ./cmd/...`:
|
||||
ok (server 97 s). New: `elevation_session_test.go`. It covers: elevation
|
||||
survives a new connection of the same session, a different or absent
|
||||
session is not elevated, the header is ignored without the proxy token,
|
||||
the boundary strips the header, and the cap expires. `elevation_test.go`
|
||||
now checks that terminals are not gated.
|
||||
- `cd web && node --test test/`: tests 51, pass 51. New: `test/sessionId.test.mjs`.
|
||||
It covers: the id is derived and stable per token, a forged header is dropped,
|
||||
the id is sent on `/connect` and `POST /files` but not on `GET /files`, and
|
||||
the id changes after another sign-in, a logout and a password change.
|
||||
- `cd app && tool/analyze.sh`: clean.
|
||||
- `tool/memwatch/full.sh 'test/core test/features/chat/files test/features/terminal test/features/settings/security'`:
|
||||
PASS, 217 passed. New: `test/core/servers/elevation/session_elevation_test.dart`.
|
||||
It covers: no prompt on reconnect, and one prompt per run per machine with a
|
||||
second prompt only after a fresh refusal.
|
||||
- `test/application` still has its 51 baseline failures (pending timers).
|
||||
|
||||
Scratch end-to-end:
|
||||
- an isolated `HOME`;
|
||||
- a scratch DB;
|
||||
- OS-chosen loopback ports;
|
||||
- the built server plus `web/serve.mjs` with a scratch server token;
|
||||
- a tagged operator session.
|
||||
|
||||
```
|
||||
login: 303 pipelines_session
|
||||
connection 1: chat_shell_run before elevate: {"type":"error","code":"elevation_required",...}
|
||||
connection 1: elevate: {"type":"elevated","elevation":{"seconds":86400,"token":"<redacted>"}}
|
||||
connection 1: chat_shell_run after elevate: chat_shell_run running
|
||||
connection 1 closed
|
||||
connection 2 (reconnect, no elevate sent): chat_shell_run: chat_shell_run running
|
||||
chat_shell_runs: [{"command":"echo first-connection-ok","status":"exited","exit_code":0,"output":"first-connection-ok"},{"command":"echo reconnected-no-elevate-ok","status":"exited","exit_code":0,"output":"reconnected-no-elevate-ok"}]
|
||||
fresh sign-in: chat_shell_run is still gated: elevation_required
|
||||
fresh sign-in, no elevate: terminal_open: terminal_open running
|
||||
terminal output: "Password:"
|
||||
terminal_close: terminal_close closed
|
||||
password occurrences in server.log / web.log: 0 / 0
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user