mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-24 08:57:25 +00:00
fix: run as root by default to eliminate stack-folder permission failures (#501)
Every filesystem operation against user compose folders (save, create, deploy, update, rollback, template install, fleet snapshot restore) previously failed with EACCES whenever a stack container had chowned its own bind mount to another UID, which is extremely common with linuxserver/* images and anything that runs as root by default. Running Sencho as root eliminates the entire class of permission bugs at the source and matches the default posture of Portainer, Dockge, Komodo, and Yacht. Mounting /var/run/docker.sock is already equivalent to root-on-host, so the previous non-root hardening provided essentially no additional isolation while breaking real features. Changes: - docker-entrypoint.sh: default path stays root, no GID dance, no privilege drop. Opt-out via SENCHO_USER=sencho restores the legacy behavior bit-for-bit (chown data dir, match Docker socket GID, su-exec to the user). Fails fast if SENCHO_USER names a nonexistent account. Kubernetes / OpenShift forced-non-root compat preserved via the existing id -u = 0 guard. - FileSystemService: delete forceDeleteViaDocker (the ~40-line helper that shelled out to an alpine container to work around EACCES during deleteStack) and simplify deleteStack to a single fsPromises.rm call. Tests updated accordingly. - Dockerfile: keep the sencho user+group pre-created so the opt-out path works out of the box; comments updated to document the new default. - Docs: new "Container user" section in configuration.mdx documenting the root default and the SENCHO_USER opt-out; troubleshooting and self-hosting updated to match.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import path from 'path';
|
||||
import { promises as fsPromises } from 'fs';
|
||||
import { spawn } from 'child_process';
|
||||
import { NodeRegistry } from './NodeRegistry';
|
||||
|
||||
/**
|
||||
@@ -182,69 +181,11 @@ export class FileSystemService {
|
||||
} catch (error: unknown) {
|
||||
const fsError = error as NodeJS.ErrnoException;
|
||||
if (fsError.code === 'ENOENT') return;
|
||||
|
||||
if (fsError.code === 'EACCES' || fsError.code === 'EPERM') {
|
||||
console.warn(
|
||||
`[FileSystemService] Permission denied deleting ${stackName}, falling back to Docker-based removal`
|
||||
);
|
||||
await this.forceDeleteViaDocker(stackDir);
|
||||
// Docker removes contents but can't remove its own mount point; clean up the empty shell
|
||||
try {
|
||||
await fsPromises.rmdir(stackDir);
|
||||
} catch {
|
||||
console.warn('[FileSystemService] Could not remove empty directory after Docker fallback — may need manual cleanup');
|
||||
}
|
||||
} else {
|
||||
console.error('Error deleting stack directory:', fsError.message);
|
||||
throw new Error(`Failed to delete stack directory: ${fsError.message}`);
|
||||
}
|
||||
console.error('Error deleting stack directory:', fsError.message);
|
||||
throw new Error(`Failed to delete stack directory: ${fsError.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
private forceDeleteViaDocker(dirPath: string): Promise<void> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const timeout = 30_000;
|
||||
const child = spawn('docker', [
|
||||
'run', '--rm',
|
||||
'-v', `${dirPath}:/cleanup`,
|
||||
'alpine',
|
||||
'sh', '-c', 'find /cleanup -mindepth 1 -maxdepth 1 -exec rm -rf {} +'
|
||||
], {
|
||||
env: {
|
||||
...process.env,
|
||||
PATH: process.env.PATH || '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
|
||||
}
|
||||
});
|
||||
|
||||
let stderr = '';
|
||||
child.stderr.on('data', (data: Buffer) => { stderr += data.toString(); });
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
child.kill();
|
||||
reject(new Error(
|
||||
`Docker-based deletion timed out after 30s. You may need to manually remove the directory: ${dirPath}`
|
||||
));
|
||||
}, timeout);
|
||||
|
||||
child.on('close', (code: number | null) => {
|
||||
clearTimeout(timer);
|
||||
if (code === 0) resolve();
|
||||
else reject(new Error(
|
||||
`Failed to delete stack directory — Docker cleanup exited with code ${code}${stderr ? ': ' + stderr.trim() : ''}. ` +
|
||||
`You may need to manually remove the directory: ${dirPath}`
|
||||
));
|
||||
});
|
||||
|
||||
child.on('error', (err: Error) => {
|
||||
clearTimeout(timer);
|
||||
reject(new Error(
|
||||
`Failed to delete stack directory — could not run Docker for cleanup: ${err.message}. ` +
|
||||
`You may need to manually remove the directory: ${dirPath}`
|
||||
));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getBaseDir(): string {
|
||||
return this.baseDir;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user