Replace host tokens with host pairing

Hosts join the cluster by running the installer, which shows a code and
waits until the request is approved under Hosts > Add host in the web
interface or with clusterioctl host approve. An admin can pass their
user token to the installer to approve the host right away. The token
is only used for that and is not saved.

The controller only accepts hosts that have a record, and only
approving a host creates one. Revoking a host deletes its record, so
its token can no longer be used to reconnect. Hosts that have connected
before keep working.

Removes host generate-token, revoke-token and create-config from
clusterioctl, bootstrap generate-host-token, the host token messages and
the core.host.generate_token, revoke_token and create_config
permissions, which are also stripped from stored roles. Adds
clusterioctl host pending, approve, reject and revoke, and the
core.host.approve and core.host.revoke permissions.

Standalone installs add the host to the controller database directly,
since the controller is not running during the install.
This commit is contained in:
Danielv123 committed 2026-10-30 06:11:32 +01:00
1 parent fa2883d74e
commit 87d4f5c64e
49 files changed
+4855 -473

No files matched your search

+77
View File
@@ -186,6 +186,83 @@ describe("messages/controller", function() {
});
});
describe("Host pairing", function() {
const details = [
new lib.HostPairingDetails("ABC-DEF", "Host A", "10.0.0.1", "2.0.0", 100, 200),
new lib.HostPairingDetails("GHJ-KMN", "Host B", "2001:db8::1", "", 0, 300, true),
];
it("defines the pairing messages for control links approving hosts", function() {
for (const Message of [
lib.HostPairingListRequest,
lib.HostPairingApproveRequest,
lib.HostPairingRejectRequest,
]) {
assert.equal(Message.type, "request", Message.name);
assert.equal(Message.src, "control", Message.name);
assert.equal(Message.dst, "controller", Message.name);
assert.equal(Message.permission, "core.host.approve", Message.name);
assert(lib.Link._requestsByClass.has(Message), `${Message.name} is not registered`);
}
assert.equal(lib.HostPairingUpdatesEvent.type, "event");
assert.equal(lib.HostPairingUpdatesEvent.src, "controller");
assert.equal(lib.HostPairingUpdatesEvent.dst, "control");
assert.equal(lib.HostPairingUpdatesEvent.permission, "core.host.approve");
assert(lib.Link._eventsByClass.has(lib.HostPairingUpdatesEvent));
});
it("removes the host token messages", function() {
for (const name of ["HostGenerateTokenRequest", "HostConfigCreateRequest", "HostRevokeTokensRequest"]) {
assert.equal(lib[name], undefined, `${name} is still exported`);
assert(!lib.Link._requestsByName.has(name), `${name} is still registered`);
}
});
it("defines the host permissions", function() {
for (const name of ["core.host.approve", "core.host.revoke"]) {
assert(lib.permissions.has(name), `${name} is not defined`);
assert.equal(lib.permissions.get(name).grantByDefault, false, `${name} is granted by default`);
}
for (const name of ["core.host.generate_token", "core.host.revoke_token", "core.host.create_config"]) {
assert.equal(lib.permissions.has(name), false, `${name} is still defined`);
}
});
it("round trips HostPairingListRequest responses", function() {
const validate = lib.compile(lib.HostPairingListRequest.Response.jsonSchema);
const json = JSON.parse(JSON.stringify(details));
assert(validate(json), JSON.stringify(validate.errors));
assert.deepEqual(lib.HostPairingListRequest.Response.fromJSON(json), details);
});
it("round trips HostPairingUpdatesEvent", function() {
testRoundTripJsonSerialisable(lib.HostPairingUpdatesEvent, [[[]], [details]]);
});
it("round trips HostPairingApproveRequest", function() {
testRoundTripJsonSerialisable(lib.HostPairingApproveRequest, testMatrix(
["ABC-DEF", "abcdef"], // code
[undefined, "Renamed"], // name
));
const validate = lib.compile(lib.HostPairingApproveRequest.Response.jsonSchema);
assert(validate(1234));
});
it("round trips HostPairingRejectRequest", function() {
testRoundTripJsonSerialisable(lib.HostPairingRejectRequest, [["ABC-DEF"], ["abcdef"]]);
});
it("approves a pending request", async function() {
controller.config.set("controller.auth_secret", Buffer.from("TestSecretDoNotUse").toString("base64"));
const { requestId, code } = controller.hostPairing.create("Host A", "", "10.0.0.1");
const list = await controlConnection.handleHostPairingListRequest(new lib.HostPairingListRequest());
assert.deepEqual(list.map(entry => entry.code), [code]);
const hostId = await controlConnection.handleHostPairingApproveRequest(
new lib.HostPairingApproveRequest(code)
);
assert.equal(controller.hosts.get(hostId).name, "Host A");
assert.equal(controller.hostPairing.poll(requestId).hostId, hostId);
});
it("rejects a pending request", async function() {
const { requestId, code } = controller.hostPairing.create("Host A", "", "10.0.0.1");
await controlConnection.handleHostPairingRejectRequest(new lib.HostPairingRejectRequest(code));
assert.throws(() => controller.hostPairing.poll(requestId), /Request was rejected/);
});
});
describe("InstanceConfigGetRequest", function() {
it("runs", async function() {
const config = await controlConnection.handleInstanceConfigGetRequest(