fix: prevent double sudo in parseCommandsByLineForSudo#9781
fix: prevent double sudo in parseCommandsByLineForSudo#9781jeroenvdmeer wants to merge 1 commit intocoollabsio:v4.xfrom
Conversation
|
Howdy, this needs a couple of fixes before merge. First, this PR currently targets Second, the new tests currently don't work. After Pest sanitizes the operator-only names. Running the test file hits a fatal redeclare for the There is also a behavior mismatch under those tests: several fixtures already start with When I ran the test I got the following. Also Coolify only supports installation and full operation as a root user, see https://coolify.io/docs/get-started/installation#_1-prepare-your-server |
Changes
rootaccount.bootstrap/helpers/sudo.phpwhereparseCommandsByLineForSudo()inadvertently generated doublesudo sudocommands.&&,||, and|were naive string replacements. If a previous step already prependedsudo(e.g.&& sudo chown -R ...), the third pass would turn this into&& sudo sudo chown .... This causes execution to fail when PTY is required.preg_replacestatements for&&,||, and|, ensuringsudois only injected if the subsequent token is not alreadysudo.Additional Context for Documentation:
Defaults log_input, log_outputorrequirettyin sudoers will cause programmatic Coolify deployments to fail silently becausesudoallocates a PTY and consumes the bash heredoc stdin. It is highly recommended to add!use_pty,!log_input, and!log_outputto the Coolify user's sudoers configuration to ensure smooth proxy startups and queue job executions./data/coolify/proxy/must be owned by the SSH user executing Coolify, otherwise the SSH session will encounter permission denied errors when attempting to writedocker-compose.yml.Issues
Category
Preview
N/A - backend logic change.
AI Assistance
If AI was used:
parseCommandsByLineForSudopipeline, write the negative lookahead regular expressions, update the Pest tests, and format the PR description. I (human) thoroughly verified the findings and architecture on my VPS.Testing
tests/Unit/ParseCommandsByLineForSudoTest.phpconfirming the negative lookahead correctly prevents doublesudoinjection.sudoexecution chain, creates thedocker-compose.ymlwith the correct ownership via the SSH session, and successfully starts thecoolify-proxycontainer without exiting silently.Contributor Agreement
Important