From ea28853305bb8dd0bf4c16b965c64ca4f36933f3 Mon Sep 17 00:00:00 2001 From: maximilian-walter Date: Sun, 28 Apr 2024 17:34:36 +0200 Subject: [PATCH] Don't show root warning for Podman containers (#11946) --- src/Composer/Console/Application.php | 6 +++++- src/Composer/Util/Platform.php | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index 1d34df527..7c989098f 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -217,7 +217,11 @@ class Application extends BaseApplication $needsSudoCheck = !Platform::isWindows() && function_exists('exec') && !Platform::getEnv('COMPOSER_ALLOW_SUPERUSER') - && (ini_get('open_basedir') || !file_exists('/.dockerenv')); + && (ini_get('open_basedir') || ( + !file_exists('/.dockerenv') + && !file_exists('/run/.containerenv') + && !file_exists('/var/run/.containerenv') + )); $isNonAllowedRoot = false; // Clobber sudo credentials if COMPOSER_ALLOW_SUPERUSER is not set before loading plugins diff --git a/src/Composer/Util/Platform.php b/src/Composer/Util/Platform.php index 33ff62056..45060c85c 100644 --- a/src/Composer/Util/Platform.php +++ b/src/Composer/Util/Platform.php @@ -152,7 +152,9 @@ class Platform !ini_get('open_basedir') && is_readable('/proc/version') && false !== stripos((string)Silencer::call('file_get_contents', '/proc/version'), 'microsoft') - && !file_exists('/.dockerenv') // docker running inside WSL should not be seen as WSL + && !file_exists('/.dockerenv') // Docker and Podman running inside WSL should not be seen as WSL + && !file_exists('/run/.containerenv') + && !file_exists('/var/run/.containerenv') ) { return self::$isWindowsSubsystemForLinux = true; }