Address review of host pairing

Revoking a host now unassigns its instances instead of being refused
while it has any, and removes its system metrics.

Approving and revoking no longer force a save. Hosts are saved by
autosave and on exit like everything else, which also removes the
approving state from pairing requests.

The approval code and link are logged as warnings so they show up in
the systemd service, which only prints warnings and above. The pairing
limits are now the controller.host_pairing_timeout and
controller.host_pairing_max_pending config values, 0 removes the limit.

Subscribers take an optional permitted function, used for the pairing
requests instead of overrides in a subclass.
This commit is contained in:
Danielv123 committed 2026-10-31 16:31:45 +01:00
1 parent e5701a8dae
commit 49a0b27d29
29 files changed
+356 -418

No files matched your search

@@ -104,16 +104,11 @@ function RevokeHostButton({ host, instances }: RevokeHostButtonProps) {
const navigate = useNavigate();
const assigned = [...instances.values()].map(instance => instance.name);
if (assigned.length) {
return <Tooltip title={`Unassign or delete the instances on this host first: ${assigned.join(", ")}`}>
<Button danger disabled>Revoke host access</Button>
</Tooltip>;
}
return <Popconfirm
title={`Revoke access for ${host.name}?`}
description={<>
The host is removed from the cluster and disconnected.<br />
{assigned.length > 0 && <>Its instances become unassigned: {assigned.join(", ")}<br /></>}
To add it back, start the host again and approve it.
</>}
placement="bottomRight"
+2 -8
View File
@@ -1,6 +1,5 @@
import { useCallback, useContext, useSyncExternalStore } from "react";
import ControlContext from "../components/ControlContext";
import { useAccount } from "./account";
export function useHost(id?: number) {
const [hosts, synced] = useHosts();
@@ -13,14 +12,9 @@ export function useHosts() {
return useSyncExternalStore(subscribe, () => control.hosts.getSnapshot());
}
/** Requests from host installers waiting to be approved, empty if the account may not approve hosts */
/** Requests from hosts waiting to be approved, empty if the account may not approve hosts */
export function useHostPairings() {
const control = useContext(ControlContext);
const account = useAccount();
const permitted = Boolean(account.hasPermission("core.host.approve"));
const subscribe = useCallback(
(callback: () => void) => (permitted ? control.hostPairings.subscribe(callback) : () => {}),
[control, permitted],
);
const subscribe = useCallback((callback: () => void) => control.hostPairings.subscribe(callback), [control]);
return useSyncExternalStore(subscribe, () => control.hostPairings.getSnapshot());
}
+5 -35
View File
@@ -1,19 +1,13 @@
import * as lib from "@clusterio/lib";
/**
* Subscriber for the requests from host installers waiting to be approved
* Subscriber for the requests from hosts waiting to be approved
*
* Only accounts that may approve hosts can subscribe to the requests, so
* this does not resubscribe on connect or account changes for other
* accounts, which would fail with a permission error. The requests only
* live in the controller's memory and it does not tell a new session about
* requests removed before it started, so the requests are cleared when a
* new session starts and fetched again. The same applies to requests removed
* while nothing was subscribed, so they are also cleared when subscribing
* again after the last handler unsubscribed.
* The requests only live in the controller's memory and it does not tell
* subscribers about requests removed while nothing was subscribed, so they
* are cleared when subscribing again after the last handler unsubscribed.
*/
export class HostPairingSubscriber extends lib.MapSubscriber<lib.HostPairingUpdatesEvent> {
private _permitted: () => boolean;
private _handlers = 0;
/**
@@ -21,31 +15,7 @@ export class HostPairingSubscriber extends lib.MapSubscriber<lib.HostPairingUpda
* @param permitted - Returns true if the account may approve hosts.
*/
constructor(control: lib.Link, permitted: () => boolean) {
super(lib.HostPairingUpdatesEvent, control);
this._permitted = permitted;
}
override handleConnectionEvent(event: "connect" | "drop" | "resume" | "close") {
if (event === "connect") {
this.values.clear();
this.lastUpdatedMs = -1;
}
if (event === "connect" || event === "resume") {
// The account of a new session is reported after the connect event.
queueMicrotask(() => {
if (this._permitted()) {
super.handleConnectionEvent(event);
}
});
return;
}
super.handleConnectionEvent(event);
}
override handleAccountEvent() {
if (this._permitted()) {
super.handleAccountEvent();
}
super(lib.HostPairingUpdatesEvent, control, undefined, permitted);
}
override subscribe(handler: lib.EventSubscriberCallback<lib.HostPairingUpdatesEvent>) {