From 0a5d0ecd0c10af1311636d6d1608a6395e60d8a1 Mon Sep 17 00:00:00 2001 From: Michael Schiemer Date: Sun, 2 Nov 2025 21:26:07 +0100 Subject: [PATCH] fix: Allow Docker Secrets to override empty environment variables - Update get() method to treat empty strings as 'not set' for Docker Secrets resolution - Allows Docker Secrets (*_FILE pattern) to override empty values - Preserves original behavior: explicitly set empty strings are still returned - Fixes issue where RAPIDMAIL_USERNAME and RAPIDMAIL_PASSWORD appear empty even when Docker Secrets are available --- src/Framework/Config/Environment.php | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/Framework/Config/Environment.php b/src/Framework/Config/Environment.php index 8bd8acce..fa3f8584 100644 --- a/src/Framework/Config/Environment.php +++ b/src/Framework/Config/Environment.php @@ -23,12 +23,19 @@ final readonly class Environment { $key = $this->keyToString($key); - // 1. Check if direct env var exists in internal array + // 1. Check if direct env var exists in internal array and is not empty + // Empty strings are treated as "not set" to allow Docker Secrets resolution if (isset($this->variables[$key])) { - return $this->variables[$key]; + $value = $this->variables[$key]; + // If value is not empty, return it (non-empty values take precedence) + if ($value !== '' && $value !== null) { + return $value; + } + // If value is empty, continue to check Docker Secrets as fallback } // 2. Docker Secrets support: Check for *_FILE pattern + // This allows Docker Secrets to override empty values $secretValue = $this->secretsResolver->resolve($key, $this->variables); if ($secretValue !== null) { return $secretValue; @@ -38,11 +45,17 @@ final readonly class Environment // This handles cases where environment variables are set after Environment initialization // (common in PHP-FPM where vars may be set during request processing) $systemValue = $this->getFromSystemEnvironment($key); - if ($systemValue !== null) { + if ($systemValue !== null && $systemValue !== '') { return $systemValue; } - // 4. Return default + // 4. If internal variable was set (even if empty), return it (to distinguish between "not set" and "empty") + // This preserves the original behavior: if variable is explicitly set to empty string, return it + if (isset($this->variables[$key])) { + return $this->variables[$key]; + } + + // 5. Return default return $default; }