fix: Replace wp --allow-root with runuser for safer command execution#27
Merged
Conversation
Replace all 'wp --allow-root' calls with 'runuser -u www-data -- wp' to execute WordPress CLI commands as the www-data user instead of root. This approach is more secure and avoids the loop error that occurs when wp-cli rejects root execution. Affected functions: - wordpress_is_installed() - wp-config.php generation - replace_url_occurrences() - install_plugin() - install_plugin_archive() - finalize_custom_plugin() This ensures the entrypoint script runs properly on container startup. Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.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.
Description
This fix replaces all
wp --allow-rootcalls withrunuser -u www-data -- wpin the WordPress entrypoint script to execute WordPress CLI commands as the www-data user instead of root.Problem
The container was failing with a loop error:
The
--allow-rootflag was not reliably preventing this error on container startup.Solution
Using
runuserto execute commands as the www-data user is a more secure approach and avoids the wp-cli root execution rejection.Changes
wordpress_is_installed(): Changed to use runuserreplace_url_occurrences(): Changed to use runuserinstall_plugin(): Changed to use runuserinstall_plugin_archive(): Changed to use runuserfinalize_custom_plugin(): Changed to use runuserTesting
After merging:
docker compose build --no-cache wordpressdocker compose up -d