From 03a3d764af3b50cfc37bd1ba11862588bf6df346 Mon Sep 17 00:00:00 2001 From: ezl-keygraph Date: Tue, 28 Apr 2026 12:43:07 +0530 Subject: [PATCH] feat(cli): block running shannon with sudo or as root (#323) --- apps/cli/src/index.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/apps/cli/src/index.ts b/apps/cli/src/index.ts index 53d8182..64c5299 100644 --- a/apps/cli/src/index.ts +++ b/apps/cli/src/index.ts @@ -25,6 +25,25 @@ import { displaySplash } from './splash.js'; const __dirname = path.dirname(fileURLToPath(import.meta.url)); +function blockSudo(): void { + const isSudo = !!process.env.SUDO_USER; + const isRoot = process.geteuid?.() === 0; + if (!isSudo && !isRoot) return; + + if (isSudo) { + console.error('ERROR: Shannon must not be run with sudo.'); + console.error('Re-run this command as your normal user.'); + } else { + console.error('ERROR: Shannon must not be run as the root user.'); + console.error('Switch to a regular user account and re-run this command.'); + } + if (process.platform === 'linux') { + console.error('Configure Docker to run without sudo first:'); + console.error('https://docs.docker.com/engine/install/linux-postinstall'); + } + process.exit(1); +} + function getVersion(): string { try { const pkgPath = path.join(__dirname, '..', 'package.json'); @@ -178,6 +197,8 @@ function parseStartArgs(argv: string[]): ParsedStartArgs { // === Main Dispatch === +blockSudo(); + const args = process.argv.slice(2); const command = args[0];