refactor: use os.userInfo when setting uid/gid in mount commands
This commit is contained in:
parent
2bee6c0751
commit
1dd43ad9f1
3 changed files with 10 additions and 7 deletions
|
|
@ -51,13 +51,14 @@ const mount = async (config: BackendConfig, mountPath: string) => {
|
||||||
await fs.mkdir(mountPath, { recursive: true });
|
await fs.mkdir(mountPath, { recursive: true });
|
||||||
await fs.mkdir(SSH_KEYS_DIR, { recursive: true });
|
await fs.mkdir(SSH_KEYS_DIR, { recursive: true });
|
||||||
|
|
||||||
|
const { uid, gid } = os.userInfo();
|
||||||
const options = [
|
const options = [
|
||||||
"reconnect",
|
"reconnect",
|
||||||
"ServerAliveInterval=15",
|
"ServerAliveInterval=15",
|
||||||
"ServerAliveCountMax=3",
|
"ServerAliveCountMax=3",
|
||||||
"allow_other",
|
"allow_other",
|
||||||
"uid=1000",
|
`uid=${uid}`,
|
||||||
"gid=1000",
|
`gid=${gid}`,
|
||||||
];
|
];
|
||||||
|
|
||||||
if (config.skipHostKeyCheck || !config.knownHosts) {
|
if (config.skipHostKeyCheck || !config.knownHosts) {
|
||||||
|
|
@ -113,7 +114,7 @@ const mount = async (config: BackendConfig, mountPath: string) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return await withTimeout(run(), OPERATION_TIMEOUT, "SFTP mount");
|
return await withTimeout(run(), OPERATION_TIMEOUT * 2, "SFTP mount");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMsg = toMessage(error);
|
const errorMsg = toMessage(error);
|
||||||
logger.error("Error mounting SFTP volume", { error: errorMsg });
|
logger.error("Error mounting SFTP volume", { error: errorMsg });
|
||||||
|
|
|
||||||
|
|
@ -39,13 +39,14 @@ const mount = async (config: BackendConfig, path: string) => {
|
||||||
const password = await cryptoUtils.resolveSecret(config.password);
|
const password = await cryptoUtils.resolveSecret(config.password);
|
||||||
|
|
||||||
const source = `//${config.server}/${config.share}`;
|
const source = `//${config.server}/${config.share}`;
|
||||||
|
const { uid, gid } = os.userInfo();
|
||||||
const options = [
|
const options = [
|
||||||
`user=${config.username}`,
|
`user=${config.username}`,
|
||||||
`pass=${password}`,
|
`pass=${password}`,
|
||||||
`vers=${config.vers}`,
|
`vers=${config.vers}`,
|
||||||
`port=${config.port}`,
|
`port=${config.port}`,
|
||||||
"uid=1000",
|
`uid=${uid}`,
|
||||||
"gid=1000",
|
`gid=${gid}`,
|
||||||
];
|
];
|
||||||
|
|
||||||
if (config.domain) {
|
if (config.domain) {
|
||||||
|
|
|
||||||
|
|
@ -43,9 +43,10 @@ const mount = async (config: BackendConfig, path: string) => {
|
||||||
const port = config.port !== defaultPort ? `:${config.port}` : "";
|
const port = config.port !== defaultPort ? `:${config.port}` : "";
|
||||||
const source = `${protocol}://${config.server}${port}${config.path}`;
|
const source = `${protocol}://${config.server}${port}${config.path}`;
|
||||||
|
|
||||||
|
const { uid, gid } = os.userInfo();
|
||||||
const options = config.readOnly
|
const options = config.readOnly
|
||||||
? ["uid=1000", "gid=1000", "file_mode=0444", "dir_mode=0555", "ro"]
|
? [`uid=${uid}`, `gid=${gid}`, "file_mode=0444", "dir_mode=0555", "ro"]
|
||||||
: ["uid=1000", "gid=1000", "file_mode=0664", "dir_mode=0775"];
|
: [`uid=${uid}`, `gid=${gid}`, "file_mode=0664", "dir_mode=0775"];
|
||||||
|
|
||||||
if (config.username && config.password) {
|
if (config.username && config.password) {
|
||||||
const password = await cryptoUtils.resolveSecret(config.password);
|
const password = await cryptoUtils.resolveSecret(config.password);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue