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:
@@ -80,21 +80,14 @@ Future<ChatMachineConnection> connectChatMachine(
|
||||
);
|
||||
await client.connectAny(endpoints);
|
||||
// Each machine confirms its own password through its own connection.
|
||||
final elevation = MachineElevation(
|
||||
name: server.name,
|
||||
gateway: client,
|
||||
states: client.states,
|
||||
);
|
||||
final elevation = MachineElevation(name: server.name, gateway: client);
|
||||
return ChatMachineConnection(
|
||||
gateway: ElevatingGateway(client, elevation),
|
||||
headers: headers,
|
||||
endpoint: () => client.endpoint?.toString() ?? '',
|
||||
connected: () => client.state.kind == ConnectionKind.connected,
|
||||
states: client.states,
|
||||
close: () async {
|
||||
await elevation.dispose();
|
||||
await client.dispose();
|
||||
},
|
||||
close: client.dispose,
|
||||
retry: () => client.connectAny(endpoints),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -97,9 +97,9 @@ class _ElevationDialogState extends State<ElevationDialog> {
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
'Running commands, opening a terminal and changing files on '
|
||||
'${widget.name} need its password again. This connection stays '
|
||||
'confirmed for 15 minutes.',
|
||||
'Running commands and changing files on ${widget.name} need its '
|
||||
'password. You are asked once; it stays confirmed until you sign '
|
||||
'out (at most a day).',
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
field,
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import 'dart:async';
|
||||
|
||||
import '../../api_gateway.dart';
|
||||
import '../../error_reason.dart';
|
||||
import '../../transport/connection_state.dart';
|
||||
|
||||
/// The server refused a request until this connection re-confirms the
|
||||
/// The server refused a request until this machine's session confirms the
|
||||
/// password (step-up re-authentication).
|
||||
const elevationRequiredCode = 'elevation_required';
|
||||
|
||||
@@ -17,24 +15,21 @@ typedef ElevationPrompt = Future<bool> Function(MachineElevation machine);
|
||||
bool isElevationRequired(Object error) =>
|
||||
error is ProtocolError && error.code == elevationRequiredCode;
|
||||
|
||||
/// One machine connection's step-up state.
|
||||
/// One machine's step-up state for this app run.
|
||||
///
|
||||
/// Elevation belongs to the websocket connection that confirmed the
|
||||
/// password: it survives navigation, ends when the server's window expires
|
||||
/// and is forgotten when the connection drops (the server forgets it too).
|
||||
/// The server keys a confirmation by the signed-in web session, so it
|
||||
/// survives navigation, reconnects and new connections of the same session:
|
||||
/// the operator is asked at most once per machine while that session lasts.
|
||||
/// Only a fresh `elevation_required` refusal (the session ended, the cap
|
||||
/// passed, or an older server that elevates one connection) asks again.
|
||||
/// Each machine elevates separately through its own gateway.
|
||||
class MachineElevation {
|
||||
MachineElevation({
|
||||
required this.name,
|
||||
required this.gateway,
|
||||
Stream<ConnectionState>? states,
|
||||
this.prompt,
|
||||
DateTime Function()? clock,
|
||||
}) : _clock = clock ?? DateTime.now {
|
||||
_states = states?.listen((state) {
|
||||
if (state.kind != ConnectionKind.connected) clear();
|
||||
});
|
||||
}
|
||||
}) : _clock = clock ?? DateTime.now;
|
||||
|
||||
/// The prompt every elevation uses when none is given; the app installs
|
||||
/// its native password dialog here.
|
||||
@@ -47,7 +42,6 @@ class MachineElevation {
|
||||
final ApiGateway gateway;
|
||||
final ElevationPrompt? prompt;
|
||||
final DateTime Function() _clock;
|
||||
StreamSubscription<ConnectionState>? _states;
|
||||
String? _token;
|
||||
DateTime? _expires;
|
||||
Future<bool>? _pending;
|
||||
@@ -89,7 +83,7 @@ class MachineElevation {
|
||||
final expiresAt = DateTime.tryParse('${body['expires_at'] ?? ''}');
|
||||
_expires = seconds is num
|
||||
? _clock().add(Duration(seconds: seconds.toInt()))
|
||||
: expiresAt?.toLocal() ?? _clock().add(const Duration(minutes: 15));
|
||||
: expiresAt?.toLocal() ?? _clock().add(const Duration(hours: 24));
|
||||
final token = body['token'];
|
||||
_token = token is String ? token : null;
|
||||
return null;
|
||||
@@ -101,14 +95,9 @@ class MachineElevation {
|
||||
}
|
||||
}
|
||||
|
||||
/// Forgets the elevation (the connection dropped or the server refused).
|
||||
/// Forgets the elevation (the server refused it).
|
||||
void clear() {
|
||||
_token = null;
|
||||
_expires = null;
|
||||
}
|
||||
|
||||
Future<void> dispose() async {
|
||||
await _states?.cancel();
|
||||
_states = null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user