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

+85
View File
@@ -0,0 +1,85 @@
import assert from "node:assert/strict";
import { HostPairingDetails } from "@clusterio/lib";
import { testMatrix, testRoundTripJsonSerialisable } from "../../common.js";
describe("lib/data/HostPairingDetails", function () {
it("should be round trip serialisable", function () {
testRoundTripJsonSerialisable(HostPairingDetails, testMatrix(
["ABC-DEF"], // code (required)
["New Host", ""], // name (required)
["10.0.0.1", "2001:db8::1"], // remoteAddress (required)
[undefined, "2.0.0"], // version
[undefined, 123456], // createdAtMs
[undefined, 999999], // updatedAtMs
[undefined, true], // isDeleted
));
});
describe("constructor", function () {
it("should set defaults correctly", function () {
const details = new HostPairingDetails("ABC-DEF", "New Host", "10.0.0.1");
assert.equal(details.code, "ABC-DEF");
assert.equal(details.name, "New Host");
assert.equal(details.remoteAddress, "10.0.0.1");
assert.equal(details.version, "");
assert.equal(details.createdAtMs, 0);
assert.equal(details.updatedAtMs, 0);
assert.equal(details.isDeleted, false);
});
it("should use the code as the id", function () {
const details = new HostPairingDetails("ABC-DEF", "New Host", "10.0.0.1");
assert.equal(details.id, "ABC-DEF");
});
});
describe(".toJSON()", function () {
it("should only include required fields when optional fields are defaults", function () {
const details = new HostPairingDetails("ABC-DEF", "New Host", "10.0.0.1", "", 0, 0, false);
assert.deepEqual(details.toJSON(), {
code: "ABC-DEF",
name: "New Host",
remoteAddress: "10.0.0.1",
});
});
it("should include all optional fields when set", function () {
const details = new HostPairingDetails("ABC-DEF", "New Host", "10.0.0.1", "2.0.0", 100, 200, true);
assert.deepEqual(details.toJSON(), {
code: "ABC-DEF",
name: "New Host",
remoteAddress: "10.0.0.1",
version: "2.0.0",
createdAtMs: 100,
updatedAtMs: 200,
isDeleted: true,
});
});
it("should not include the id getter", function () {
const details = new HostPairingDetails("ABC-DEF", "New Host", "10.0.0.1");
assert.equal(Object.hasOwn(JSON.parse(JSON.stringify(details)), "id"), false);
});
});
describe("static fromJSON()", function () {
it("should construct minimal object", function () {
const details = HostPairingDetails.fromJSON({
code: "ABC-DEF",
name: "New Host",
remoteAddress: "10.0.0.1",
});
assert.equal(details.code, "ABC-DEF");
assert.equal(details.version, "");
assert.equal(details.createdAtMs, 0);
assert.equal(details.updatedAtMs, 0);
assert.equal(details.isDeleted, false);
});
});
});