Implement basic ingress filtering on controller

Validate messages received on the controller from hosts and control
nodes before handling or forwarding them.  This should prevent
performing actions that are not allowed by the role system and block
simple attacks such as spoofing the source address of a message.
This commit is contained in:
Hornwitser committed 2023-07-25 17:21:44 +02:00
1 parent 7a9aec74b5
commit 87172dfb8d
8 files changed
+339 -52

No files matched your search

+30 -5
View File
@@ -48,6 +48,11 @@ async function deleteSave(instanceId, save) {
await getControl().send(new libData.InstanceDeleteSaveRequest(instanceId, save));
}
async function getUsers() {
let users = await getControl().send(new libData.UserListRequest());
return new Map(users.map(user => [user.name, user]));
}
describe("Integration of Clusterio", function() {
describe("clusteriocontroller", function() {
describe("bootstrap generate-user-token", function() {
@@ -455,11 +460,6 @@ describe("Integration of Clusterio", function() {
});
describe("user set-admin/whitelisted/banned", function() {
async function getUsers() {
let users = await getControl().send(new libData.UserListRequest());
return new Map(users.map(user => [user.name, user]));
}
async function getUser(name) {
return await getControl().send(new libData.UserGetRequest(name));
}
@@ -1090,6 +1090,31 @@ describe("Integration of Clusterio", function() {
assert.deepEqual(tempUser.roles, [0]);
assert.equal(getControl().userUpdates.length, 1);
});
it("should restrict actions based on roles", async function() {
await execCtl('user set-roles temp "Player"');
let tempControl;
try {
let tlsCa = await fs.readFile("test/file/tls/cert.pem");
let connector = new TestControlConnector(url, 2, tlsCa);
connector.token = jwt.sign(
{ aud: "user", user: "temp" }, Buffer.from("TestSecretDoNotUse", "base64")
);
tempControl = new TestControl(connector);
await connector.connect();
await assert.rejects(
tempControl.send(new libData.UserCreateRequest("notallowed")),
new Error("Permission denied")
);
} finally {
await tempControl.connector.disconnect();
}
let users = await getUsers();
assert(!users.has("notallowed"), "user was created when it should not be allowed");
});
});
describe("user delete", function() {