fix: don't forward host LOCALSTACK_* env that clobbers container PATH#379
Closed
gtsiolis wants to merge 1 commit into
Closed
fix: don't forward host LOCALSTACK_* env that clobbers container PATH#379gtsiolis wants to merge 1 commit into
gtsiolis wants to merge 1 commit into
Conversation
… (DEVX-984) LocalStack's docker-entrypoint.sh re-exports every LOCALSTACK_<NAME> variable as <NAME> (stripping the prefix) and relies on the image's own PATH. lstk forwarded all host LOCALSTACK_* variables verbatim, so a host LOCALSTACK_PATH became `export PATH=...` inside the container, blanking PATH — and the entrypoint's next command (`mkdir -p ...`) failed with "mkdir: command not found", crashing the emulator on startup. filterHostEnv now drops LOCALSTACK_* variables whose entrypoint-stripped name is a reserved shell variable (PATH, HOME, LD_PRELOAD, ...) and any value containing a newline/carriage return (which could inject spurious export lines through the entrypoint's line-oriented pipeline). Generated with [Linear](https://linear.app/localstack/issue/DEVX-984/lstk-exits-unexpectedly-with-mkdir-command-not-found#agent-session-dc304e8b) Co-authored-by: linear-code[bot] <222613912+linear-code[bot]@users.noreply.github.com>
gtsiolis
added a commit
that referenced
this pull request
Jul 9, 2026
…ocklist (DEVX-984) Folds in the two improvements from #379: a multi-line value is split by the entrypoint's line-oriented env pipeline and can inject rogue exports (e.g. an embedded 'LOCALSTACK_PATH=' line blanks PATH), and IFS/SHELL/ ENV/BASH_ENV join the reserved set (the entrypoint sources the stripped exports mid-script, so IFS corrupts its word splitting). Unlike #379, both drops surface a warning instead of happening silently.
Member
Author
|
Closing in favor of #378. |
gtsiolis
added a commit
that referenced
this pull request
Jul 9, 2026
…ocklist (DEVX-984) Folds in the two improvements from #379: a multi-line value is split by the entrypoint's line-oriented env pipeline and can inject rogue exports (e.g. an embedded 'LOCALSTACK_PATH=' line blanks PATH), and IFS/SHELL/ ENV/BASH_ENV join the reserved set (the entrypoint sources the stripped exports mid-script, so IFS corrupts its word splitting). Unlike #379, both drops surface a warning instead of happening silently. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
lstk startcrashed immediately with:mkdir: command not foundmeans the container'sPATHwas empty when the entrypoint ran.Root cause
LocalStack's
docker-entrypoint.shre-exports everyLOCALSTACK_<NAME>variable as<NAME>(stripping the prefix) via a line-orientedsource <(env | … | sed …), and does not setPATHitself — it relies on the image's ownENV PATH.Since #161, lstk forwards all host
LOCALSTACK_*variables into the container verbatim (filterHostEnv). So a hostLOCALSTACK_PATHbecameexport PATH=…inside the container, blankingPATH. The entrypoint's very next command (mkdir -p /var/lib/localstack/logs) then failed withmkdir: command not foundand the emulator exited on startup — independent of config file and image tag, matching the report.Fix
filterHostEnvnow drops:LOCALSTACK_*variables whose entrypoint-stripped name is a reserved shell variable (PATH,HOME,SHELL,IFS,ENV,BASH_ENV,LD_PRELOAD,LD_LIBRARY_PATH,PYTHONPATH,PYTHONHOME); andexportlines through the entrypoint's line-oriented pipeline (a second, distinct way to blankPATH).LOCALSTACK_AUTH_TOKENfiltering and normalCI/LOCALSTACK_*forwarding are unchanged.Compared to #378, this PR additionally: (1) sanitizes newline/CR values, and (2) covers a slightly wider reserved set. #378 additionally emits a user-facing warning for each dropped var, which is a nice touch this PR lacks and worth keeping.
Tests
TestFilterHostEnvnow assertsLOCALSTACK_PATH, other reserved-name vars, and newline-containing values are not forwarded.TestStartCommandIgnoresPathClobberingHostEnvstarts the emulator withLOCALSTACK_PATHset and asserts it comes up healthy (fails with themkdir: command not foundcrash before the fix). Needs Docker +LOCALSTACK_AUTH_TOKEN, so it runs in CI.Separately worth filing upstream: excluding
PATHand friends from prefix-stripping in the image entrypoint itself, which would also protect compose users who exportLOCALSTACK_PATHwithout lstk involved.