mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-21 08:03:13 +09:00
Move generation of auth secret to master startup
Move the code generating the master authentication secret from the inital value function of the master.auth_secret config entry to the master startup. Having the authentication secret generated in the config library poses issues with using the config library in browser.
This commit is contained in:
1 parent
34a0ce4dc3
commit
2a7bc75929
2 files changed
+10
-11
No files matched your search
@@ -1,9 +1,6 @@
|
|||||||
// Core definitions for the configuration system
|
// Core definitions for the configuration system
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
const util = require("util");
|
|
||||||
const crypto = require("crypto");
|
|
||||||
const path = require("path");
|
|
||||||
const fs = require("fs-extra");
|
const fs = require("fs-extra");
|
||||||
|
|
||||||
const classes = require("./classes");
|
const classes = require("./classes");
|
||||||
@@ -76,12 +73,7 @@ MasterGroup.define({
|
|||||||
+" Should be a long string of random letters and numbers."
|
+" Should be a long string of random letters and numbers."
|
||||||
+" Do not share this.",
|
+" Do not share this.",
|
||||||
type: "string",
|
type: "string",
|
||||||
initial_value: async function() {
|
optional: true,
|
||||||
console.log("Generating new master authentication secret");
|
|
||||||
let asyncRandomBytes = util.promisify(crypto.randomBytes);
|
|
||||||
let bytes = await asyncRandomBytes(256);
|
|
||||||
return bytes.toString("base64");
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
MasterGroup.define({
|
MasterGroup.define({
|
||||||
name: "heartbeat_interval",
|
name: "heartbeat_interval",
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ const yargs = require("yargs");
|
|||||||
const WebSocket = require("ws");
|
const WebSocket = require("ws");
|
||||||
const JSZip = require("jszip");
|
const JSZip = require("jszip");
|
||||||
const version = require("./package").version;
|
const version = require("./package").version;
|
||||||
|
const util = require("util");
|
||||||
|
|
||||||
// ugly globals
|
// ugly globals
|
||||||
let masterConfig;
|
let masterConfig;
|
||||||
@@ -1595,6 +1596,14 @@ async function startServer() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!masterConfig.get("master.auth_secret")) {
|
||||||
|
console.log("Generating new master authentication secret");
|
||||||
|
let asyncRandomBytes = util.promisify(crypto.randomBytes);
|
||||||
|
let bytes = await asyncRandomBytes(256);
|
||||||
|
masterConfig.set("master.auth_secret", bytes.toString("base64"));
|
||||||
|
await fs.outputFile(masterConfigPath, JSON.stringify(masterConfig.serialize(), null, 4));
|
||||||
|
}
|
||||||
|
|
||||||
let command = args._[0];
|
let command = args._[0];
|
||||||
if (command === "config") {
|
if (command === "config") {
|
||||||
await config.handleConfigCommand(args, masterConfig, masterConfigPath);
|
await config.handleConfigCommand(args, masterConfig, masterConfigPath);
|
||||||
@@ -1642,8 +1651,6 @@ async function startServer() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save config in case the auth_secret was generated during this invocation.
|
|
||||||
await fs.outputFile(masterConfigPath, JSON.stringify(masterConfig.serialize(), null, 4));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user