Skip to content

fix: don't let LOCALSTACK_PATH clobber emulator PATH#378

Open
gtsiolis wants to merge 2 commits into
mainfrom
devx-984-lstk-exits-unexpectedly-with-mkdir-command-not-found
Open

fix: don't let LOCALSTACK_PATH clobber emulator PATH#378
gtsiolis wants to merge 2 commits into
mainfrom
devx-984-lstk-exits-unexpectedly-with-mkdir-command-not-found

Conversation

@gtsiolis

@gtsiolis gtsiolis commented Jul 9, 2026

Copy link
Copy Markdown
Member

Motivation

Reported in DEVX-984 (Slack, patrick.lafond): lstk start died with /usr/local/bin/docker-entrypoint.sh: line 22: mkdir: command not found on any config, tag, and lstk version, but only on one machine. Root cause since confirmed by the reporter: a LOCALSTACK_PATH var exported in his zsh config (pointing agents at a localstack source checkout); env -u LOCALSTACK_PATH lstk starts cleanly.

Why it breaks: since #161 lstk forwards every host LOCALSTACK_* env var into the emulator. The emulator image's docker-entrypoint.sh strips the LOCALSTACK_ prefix and re-exports the remainder (only LOCALSTACK_HOST/LOCALSTACK_HOSTNAME are excluded), so LOCALSTACK_PATH=/home/user/repos/localstack becomes export PATH=/home/user/repos/localstack inside the emulator. The entrypoint itself is started by absolute path, so the first command that needs PATH is mkdir — exactly the reported failure — and set -eo pipefail kills startup.

Changes

  • filterHostEnv drops LOCALSTACK_* vars whose prefix-stripped name collides with a critical runtime variable: PATH, HOME, SHELL, IFS, ENV, BASH_ENV, LD_PRELOAD, LD_LIBRARY_PATH, PYTHONPATH, PYTHONHOME (criticalContainerVar). Matching is on the exact stripped name (LOCALSTACK_PATHFINDER still forwards); LOCALSTACK_HOSTNAME still forwards since the entrypoint excludes it from stripping.
  • filterHostEnv also drops forwarded values containing a newline/CR: the entrypoint re-exports vars through a line-oriented env | sed pipeline, so an embedded line like LOCALSTACK_PATH= injects a rogue export PATH= that blanks PATH — a second, independent way to hit the same crash (adopted from fix: don't forward host LOCALSTACK_* env that clobbers container PATH #379).
  • Dropped vars are returned as droppedHostEnv{name, overrides} and Start emits a warning for each, with the reason (…it would override PATH inside the emulator / …its value contains line breaks), so neither drop is silent. The long-standing LOCALSTACK_AUTH_TOKEN drop stays silent as before.

Testing

  • Extended TestFilterHostEnv unit test covering both drop reasons and the reported drop metadata (fails before the fix).
  • Extended the TestStartCommandPassesCIAndLocalStackEnvVars integration test to start with LOCALSTACK_PATH set: before the fix the emulator dies exactly as reported; after it, start succeeds, the warning is printed, and the var is absent from the container env. Needs Docker + LOCALSTACK_AUTH_TOKEN, so it runs in CI.

Supersedes #379 (its multiline guard and wider reserved set are folded in here, with warnings added on top).

A follow-up worth filing separately: excluding PATH and friends from prefix-stripping in the image entrypoint itself, which would also protect compose users who export LOCALSTACK_PATH without lstk involved.

Fixes DEVX-984

…lator env (DEVX-984)

The emulator image's docker-entrypoint.sh strips the LOCALSTACK_ prefix
from environment variables and re-exports the remainder, so a host shell
var like LOCALSTACK_PATH forwarded by filterHostEnv became PATH inside
the emulator and killed startup with 'mkdir: command not found'.

Drop LOCALSTACK_* vars whose stripped name collides with a critical
runtime variable (PATH, HOME, LD_PRELOAD, LD_LIBRARY_PATH, PYTHONPATH,
PYTHONHOME) and emit a warning so the drop is visible to the user.
@gtsiolis gtsiolis requested a review from a team as a code owner July 9, 2026 13:56
@gtsiolis gtsiolis marked this pull request as draft July 9, 2026 13:56
@gtsiolis gtsiolis added semver: patch docs: skip Pull request does not require documentation changes labels Jul 9, 2026
@gtsiolis gtsiolis marked this pull request as ready for review July 9, 2026 15:04
@gtsiolis gtsiolis changed the title fix: stop forwarding LOCALSTACK_* host vars that clobber critical emulator env (DEVX-984) fix: don't forward LOCALSTACK_* env vars that clobber emulator PATH Jul 9, 2026
@gtsiolis gtsiolis changed the title fix: don't forward LOCALSTACK_* env vars that clobber emulator PATH fix: don't let LOCALSTACK_PATH clobber emulator PATH 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>
@gtsiolis gtsiolis force-pushed the devx-984-lstk-exits-unexpectedly-with-mkdir-command-not-found branch from 393cc72 to 695098d Compare July 9, 2026 15:06
@gtsiolis

gtsiolis commented Jul 9, 2026

Copy link
Copy Markdown
Member Author

I'd appreciate a check from @anisaoshafi before merging. 🏓

@gtsiolis gtsiolis requested a review from anisaoshafi July 9, 2026 15:08
@gtsiolis gtsiolis self-assigned this Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs: skip Pull request does not require documentation changes semver: patch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant