mirror of
https://github.com/outline/outline.git
synced 2026-11-30 09:00:18 +03:00
fix: Explain local storage permission errors with the process uid (#14525)
* fix: Explain local storage permission errors with the process uid * fix: Check execute permission on local storage directory
This commit is contained in:
1 parent
309dd022f6
commit
dbef6ba847
2 files changed
+38
-2
No files matched your search
@@ -83,7 +83,7 @@ router.post(
|
||||
await attachment.destroy();
|
||||
if (err instanceof Error && err.message.includes("permission denied")) {
|
||||
throw Error(
|
||||
`Permission denied writing to "${key}". Check the host machine file system permissions.`
|
||||
`Permission denied writing to "${key}". Check that uid ${process.getuid?.() ?? "unknown"} can write to the storage directory on the host machine.`
|
||||
);
|
||||
}
|
||||
throw err;
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
import { existsSync, mkdirSync } from "node:fs";
|
||||
import {
|
||||
accessSync,
|
||||
constants,
|
||||
existsSync,
|
||||
mkdirSync,
|
||||
statSync,
|
||||
} from "node:fs";
|
||||
import { toError } from "@shared/utils/error";
|
||||
import env from "@server/env";
|
||||
import Logger from "@server/logging/Logger";
|
||||
@@ -16,6 +22,7 @@ if (env.FILE_STORAGE === "local") {
|
||||
mkdirSync(rootDir, { recursive: true });
|
||||
Logger.debug("utils", `Created ${rootDir} for local storage`);
|
||||
}
|
||||
checkWritable(rootDir);
|
||||
} catch (err) {
|
||||
Logger.fatal(
|
||||
`Failed to create directory for local file storage at ${env.FILE_STORAGE_LOCAL_ROOT_DIR}`,
|
||||
@@ -41,3 +48,32 @@ if (enabled) {
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs an error that explains how to fix the permissions when the process
|
||||
* cannot write to or enter the local file storage directory.
|
||||
*
|
||||
* @param rootDir the local file storage directory.
|
||||
*/
|
||||
function checkWritable(rootDir: string) {
|
||||
try {
|
||||
accessSync(rootDir, constants.W_OK | constants.X_OK);
|
||||
} catch (err) {
|
||||
if (process.getuid === undefined || process.getgid === undefined) {
|
||||
Logger.error(
|
||||
`Local file storage directory ${rootDir} is not writable`,
|
||||
toError(err)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const uid = process.getuid();
|
||||
const gid = process.getgid();
|
||||
const owner = statSync(rootDir);
|
||||
|
||||
Logger.error(
|
||||
`Local file storage directory ${rootDir} is not writable. Outline runs as uid ${uid} and gid ${gid}, but the directory is owned by uid ${owner.uid} and gid ${owner.gid}. Run "chown -R ${uid}:${gid}" on the directory on the host, or run the container as the directory owner with user: "${owner.uid}:${owner.gid}".`,
|
||||
toError(err)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user