Skip to content

Make entrypoint .env parsing safer - #2463

Open
lancepioch wants to merge 2 commits into
mainfrom
docker/entrypoint
Open

Make entrypoint .env parsing safer#2463
lancepioch wants to merge 2 commits into
mainfrom
docker/entrypoint

Conversation

@lancepioch

Copy link
Copy Markdown
Member

The entrypoint grepped .env without anchoring, so a comment line or another variable containing the same name could match and crash the container on boot. Now it only matches real assignments, container env wins over .env, generated keys use the normal base64: format, and there's a SKIP_MIGRATIONS flag for people running more than one replica.

The .env loader used unanchored greps, so a comment containing a variable
name, or another variable that merely contains the name (e.g.
SOME_APP_KEY_BACKUP), matched too. With multiple matching lines the
export received a multiline string, failed, and 'ash -e' killed the
container at boot.

- match only real assignments anchored at the start of a line
- let container environment variables take precedence over .env for the
  entrypoint's own vars, matching Laravel's precedence and the comment's
  stated intent
- generate APP_KEY in the standard base64: format (32 random bytes)
  instead of a hand-rolled alphanumeric string
- add a SKIP_MIGRATIONS escape hatch for multi-replica deployments where
  automatic 'migrate --force' on every boot would race
@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: d850b006-fafc-44a5-9d17-a85b677713fd

📥 Commits

Reviewing files that changed from the base of the PR and between 717370e and d7b6914.

📒 Files selected for processing (1)
  • docker/entrypoint.sh
🚧 Files skipped from review as they are similar to previous changes (1)
  • docker/entrypoint.sh

📝 Walkthrough

Walkthrough

The Docker entrypoint selectively loads sanitized Laravel environment variables, generates a base64: APP_KEY from 32 random bytes when missing, and conditionally runs migrations based on SKIP_MIGRATIONS.

Changes

Entrypoint startup behavior

Layer / File(s) Summary
Environment loading and application key generation
docker/entrypoint.sh
Preserves selected container variables, loads the first matching .env assignments while skipping command substitutions and backticks, strips carriage returns and quotes, and generates a base64: APP_KEY from random bytes when needed.
Conditional migration execution
docker/entrypoint.sh
Runs forced migrations unless SKIP_MIGRATIONS=true, logging when migration execution is skipped.

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change to safer .env parsing in the entrypoint.
Description check ✅ Passed The description matches the changes, covering safer .env parsing, env precedence, key generation, and migration skipping.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
docker/entrypoint.sh (1)

52-54: 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Preserve APP_INSTALLED if it is passed via the container environment.

If a user provides APP_INSTALLED=true via a container environment variable during a fully automated fresh start (where no .env file exists), this line will unconditionally append APP_INSTALLED=false to the newly generated .env file. While Laravel's environment precedence handles this gracefully at runtime, it leaves the .env file in a contradictory state.

Consider mirroring the fallback behavior used for APP_KEY above to keep the .env file consistent with the container environment.

💡 Proposed fix
   # enable installer
-  echo "APP_INSTALLED=false" >> /pelican-data/.env
+  echo "APP_INSTALLED=${APP_INSTALLED:-false}" >> /pelican-data/.env
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docker/entrypoint.sh` around lines 52 - 54, Update the APP_INSTALLED
initialization in the docker entrypoint flow to preserve an existing container
environment value when generating the .env file, mirroring the fallback behavior
used for APP_KEY. Only write APP_INSTALLED=false when no APP_INSTALLED value was
provided, keeping the generated file consistent with the container environment.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docker/entrypoint.sh`:
- Around line 33-34: Update the export command in the .env loading loop to make
its sed transformation remove double quotes, single quotes, and carriage returns
before exporting each variable. Preserve the existing LINE-based parsing and
export behavior while ensuring values from CRLF files and single-quoted entries
are cleaned.

---

Outside diff comments:
In `@docker/entrypoint.sh`:
- Around line 52-54: Update the APP_INSTALLED initialization in the docker
entrypoint flow to preserve an existing container environment value when
generating the .env file, mirroring the fallback behavior used for APP_KEY. Only
write APP_INSTALLED=false when no APP_INSTALLED value was provided, keeping the
generated file consistent with the container environment.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 29552101-056c-4818-9a74-70ea26283c29

📥 Commits

Reviewing files that changed from the base of the PR and between 21d125d and 717370e.

📒 Files selected for processing (1)
  • docker/entrypoint.sh

Comment thread docker/entrypoint.sh Outdated
A .env edited on Windows leaves a trailing \r in exported values, which
breaks the APP_INSTALLED comparison and the DB_HOST wait, and single
quoted values kept their quotes. Strip both along with double quotes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant