mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 07:43:12 +09:00
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:
49 files changed
+4855
-473
No files matched your search
@@ -3,25 +3,36 @@ import events from "node:events";
|
||||
import jwt from "jsonwebtoken";
|
||||
|
||||
import {
|
||||
TestControlConnector, TestHostConnector, TestControl, url, controlToken, getControl,
|
||||
TestControlConnector, TestHostConnector, TestControl, url, controlToken, getControl, hostId, pairTestHost,
|
||||
} from "./index.js";
|
||||
import * as lib from "@clusterio/lib";
|
||||
import { ConnectionClosed, ProtocolError, PolicyViolation, AuthenticationFailed } from "@clusterio/lib";
|
||||
import { slowTest } from "../common.js";
|
||||
|
||||
let tokenHost = jwt.sign({ aud: "host", host: 0 }, Buffer.from("TestSecretDoNotUse", "base64"));
|
||||
// Valid token for a host id that was never approved
|
||||
let tokenUnregistered = jwt.sign({ aud: "host", host: 0 }, Buffer.from("TestSecretDoNotUse", "base64"));
|
||||
|
||||
describe("Integration of lib/link", function() {
|
||||
let control;
|
||||
let controlConnector;
|
||||
let hostConnector;
|
||||
// Hosts can only connect once approved, so the host connections use a paired host
|
||||
let linkHost;
|
||||
before(async function() {
|
||||
linkHost = await pairTestHost("link-test");
|
||||
});
|
||||
after(async function() {
|
||||
if (linkHost) {
|
||||
await getControl().send(new lib.HostRevokeRequest(linkHost.hostId));
|
||||
}
|
||||
});
|
||||
beforeEach(async function() {
|
||||
controlConnector = new TestControlConnector(url, 0.2);
|
||||
controlConnector.token = controlToken;
|
||||
control = new TestControl(controlConnector, false);
|
||||
hostConnector = new TestHostConnector(url, 0.2);
|
||||
hostConnector.token = tokenHost;
|
||||
hostConnector.hostId = 0;
|
||||
hostConnector.token = linkHost.token;
|
||||
hostConnector.hostId = linkHost.hostId;
|
||||
});
|
||||
afterEach(async function() {
|
||||
await controlConnector.disconnect();
|
||||
@@ -138,13 +149,24 @@ describe("Integration of lib/link", function() {
|
||||
});
|
||||
|
||||
it("should refuse connection with mismatched ids", async function() {
|
||||
hostConnector.hostId = 1;
|
||||
hostConnector.hostId = linkHost.hostId + 1;
|
||||
await assert.rejects(
|
||||
hostConnector.connect(),
|
||||
new Error("Authentication failed: missmatched host id")
|
||||
);
|
||||
});
|
||||
|
||||
it("should refuse connection for a host that is not registered", async function() {
|
||||
hostConnector.token = tokenUnregistered;
|
||||
hostConnector.hostId = 0;
|
||||
await assert.rejects(
|
||||
hostConnector.connect(),
|
||||
new Error(
|
||||
"Authentication failed: host is not registered, run the installer again in the host directory"
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
it("should close old connections from the same address", async function() {
|
||||
slowTest(this);
|
||||
const hostConnectorFirst = new TestHostConnector(url, 0.2);
|
||||
@@ -163,8 +185,8 @@ describe("Integration of lib/link", function() {
|
||||
it("should refuse duplicate host connections", async function() {
|
||||
this.skip(); // Can't be checked because the remote address for both connections is the same
|
||||
|
||||
hostConnector.token = jwt.sign({ aud: "host", host: 4 }, Buffer.from("TestSecretDoNotUse", "base64"));
|
||||
hostConnector.hostId = 4; // Same as already running host
|
||||
hostConnector.token = jwt.sign({ aud: "host", host: hostId }, Buffer.from("TestSecretDoNotUse", "base64"));
|
||||
hostConnector.hostId = hostId; // Same as already running host
|
||||
await assert.rejects(
|
||||
hostConnector.connect(),
|
||||
new Error("Authentication failed: missmatched host id")
|
||||
|
||||
Reference in new issue
Block a user