-
Notifications
You must be signed in to change notification settings - Fork 0
fix: if user script is executable, execute it #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Chris Gianelloni <wolf31o2@blinklabs.io>
📝 WalkthroughWalkthroughThe Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Possibly related PRs
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 1 file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
bin/entrypoint(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: cubic · AI code reviewer
🔇 Additional comments (1)
bin/entrypoint (1)
38-40: Verify intended behavior when user script fails.The entrypoint continues execution and starts OpenVPN even when the user startup script exits with a non-zero code. Is this the intended behavior, or should the entrypoint exit with an error when the user script fails?
If the entrypoint should fail when the user script fails, apply this diff:
if [[ ${__ret} -ne 0 ]]; then echo "WARN: User startup script exited with error code ${__ret}" >&2 + exit ${__ret} fiOtherwise, if the current behavior is intentional (allowing OpenVPN to start regardless), consider changing "WARN:" to "INFO:" to better reflect that this is an expected scenario where startup continues.
| if [[ -x ${USER_STARTUP_SCRIPT} ]]; then | ||
| ${USER_STARTUP_SCRIPT} | ||
| __ret=$? | ||
| else | ||
| chmod a+x ${USER_STARTUP_SCRIPT} || ls -l ${USER_STARTUP_SCRIPT} | ||
| ${USER_STARTUP_SCRIPT} | ||
| __ret=$? | ||
| fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix chmod failure handling and improve security.
The current implementation has several issues:
-
Logic error: If
chmodfails on line 34, the|| ls -lruns for debugging, but execution continues to line 35 where the non-executable script will fail. The fallback should either exit or skip execution. -
Overly permissive:
chmod a+xgrants execute permission to all users. Usechmod +xinstead. -
Missing quotes:
${USER_STARTUP_SCRIPT}should be quoted to handle paths with spaces.
Apply this diff to fix the issues:
__ret=0
if [[ -x ${USER_STARTUP_SCRIPT} ]]; then
- ${USER_STARTUP_SCRIPT}
+ "${USER_STARTUP_SCRIPT}"
__ret=$?
else
- chmod a+x ${USER_STARTUP_SCRIPT} || ls -l ${USER_STARTUP_SCRIPT}
- ${USER_STARTUP_SCRIPT}
- __ret=$?
+ if chmod +x "${USER_STARTUP_SCRIPT}"; then
+ "${USER_STARTUP_SCRIPT}"
+ __ret=$?
+ else
+ echo "ERROR: Failed to make user startup script executable" >&2
+ ls -l "${USER_STARTUP_SCRIPT}" >&2
+ __ret=1
+ fi
fi📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if [[ -x ${USER_STARTUP_SCRIPT} ]]; then | |
| ${USER_STARTUP_SCRIPT} | |
| __ret=$? | |
| else | |
| chmod a+x ${USER_STARTUP_SCRIPT} || ls -l ${USER_STARTUP_SCRIPT} | |
| ${USER_STARTUP_SCRIPT} | |
| __ret=$? | |
| fi | |
| __ret=0 | |
| if [[ -x ${USER_STARTUP_SCRIPT} ]]; then | |
| "${USER_STARTUP_SCRIPT}" | |
| __ret=$? | |
| else | |
| if chmod +x "${USER_STARTUP_SCRIPT}"; then | |
| "${USER_STARTUP_SCRIPT}" | |
| __ret=$? | |
| else | |
| echo "ERROR: Failed to make user startup script executable" >&2 | |
| ls -l "${USER_STARTUP_SCRIPT}" >&2 | |
| __ret=1 | |
| fi | |
| fi |
🤖 Prompt for AI Agents
In bin/entrypoint around lines 30 to 37, the block attempts to chmod and run the
USER_STARTUP_SCRIPT but has logic and security issues: replace chmod a+x with
chmod +x, quote "${USER_STARTUP_SCRIPT}" everywhere, and change the flow so that
after attempting chmod +x "${USER_STARTUP_SCRIPT}" you check its exit status and
if chmod fails run ls -l "${USER_STARTUP_SCRIPT}" and exit with a non-zero code
(or skip execution) instead of proceeding to run a non-executable file; finally
only execute the script if it is -x "${USER_STARTUP_SCRIPT}" and propagate its
exit code to __ret.
Summary by cubic
Execute the user startup script directly, respecting its shebang, instead of forcing bash. If it isn’t executable, set +x and run it; log a warning if the script exits non-zero.
Written for commit 1170325. Summary will update automatically on new commits.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.