mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-17 23:33:12 +09:00
Create config files with mode 0o600 (#1017)
Config files hold the auth secret and tokens, so the default 0o644 lets every user on the system read them. Config.save, the ctl config written by the controller bootstrap, ctl host create-config and the config migration in create now pass mode 0o600. safeOutputFile also applies the mode to the temporary file it writes, since writeFile only honours mode on creation and a leftover temporary from a failed write would otherwise keep its old mode. Closes #1005 Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
8c03ac15ab
commit
d4b6df4f63
7 files changed
+27
-4
No files matched your search
@@ -395,6 +395,15 @@ describe("lib/config/classes", function() {
|
||||
const json = JSON.parse(await fs.readFile(filepath, "utf8"));
|
||||
assert.deepEqual(json, testInstance.toJSON());
|
||||
});
|
||||
it("should not be readable by other users", async function() {
|
||||
if (process.platform === "win32") {
|
||||
this.skip();
|
||||
}
|
||||
const testInstance = new TestConfig("local", { "alpha.foo": "a" }, filepath);
|
||||
testInstance.set("alpha.foo", "b"); // Sets the dirty flag
|
||||
await testInstance.save();
|
||||
assert.equal((await fs.stat(filepath)).mode & 0o777, 0o600);
|
||||
});
|
||||
it("should clear the dirty flag after saving", async function() {
|
||||
const testInstance = new TestConfig("local", { "alpha.foo": "a" }, filepath);
|
||||
testInstance.set("alpha.foo", "b"); // Sets the dirty flag
|
||||
|
||||
@@ -100,6 +100,16 @@ describe("lib/file_ops", function() {
|
||||
await assert.rejects(fs.access(target.replace(".txt", ".tmp.txt")), "temporary was left behind");
|
||||
assert.equal(await fs.readFile(target, "utf8"), "current");
|
||||
});
|
||||
it("should apply mode to a leftover temporary file", async function() {
|
||||
if (process.platform === "win32") {
|
||||
this.skip();
|
||||
}
|
||||
let target = path.join(baseDir, "safe", "mode.txt");
|
||||
await fs.writeFile(target.replace(".txt", ".tmp.txt"), "stale", { mode: 0o644 });
|
||||
await lib.safeOutputFile(target, "private", { mode: 0o600 });
|
||||
assert.equal((await fs.stat(target)).mode & 0o777, 0o600);
|
||||
assert.equal(await fs.readFile(target, "utf8"), "private");
|
||||
});
|
||||
it("should handle creating file in current working directory", async function() {
|
||||
let target = "temporary-file-made-to-test-cwd.txt";
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user