composer: warn when running as root - #12090
Conversation
felixfontein
left a comment
There was a problem hiding this comment.
I'm not sure this is the right approach. I think it would be better to surface warnings emitted by composer to the user, instead of ignoring them.
In particular, https://getcomposer.org/doc/faqs/how-to-install-untrusted-packages-safely.md#running-composer-inside-docker-podman-containers shows that emitting a warning when root is used is simply wrong in general.
Especially after reading that, I really don't think we should try to second-guess composer, but simply pass its warnings on.
Fixes ansible-collections#2388 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The composer_as_root test case still expected the pre-rebase command format (working-dir as a separate trailing option) instead of the current --working-dir=<path> token placed before the subcommand.
d18f41a to
38b8fe3
Compare
|
Rebased (fixing conflict) |
This comment was marked as outdated.
This comment was marked as outdated.
…f reimplementing it Per review feedback, stop independently deciding when running as root is unsafe (which is wrong in cases like official containers) and instead surface composer's own warning as an Ansible warning. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Agree. I have rewritten the changes. |
…ble-core versions CI on ansible-core 2.18 failed: module.warn() serializes warnings as plain strings there, but as structured WarningSummary/Event dicts on 2.19+. Assert via substring match instead of exact equality so the test passes on both. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Backport to stable-13: 💚 backport PR created✅ Backport PR branch: Backported as #12722 🤖 @patchback |
|
@russoz thanks for implementing this! |
…as root (#12722) composer: warn when running as root (#12090) * feat(composer): warn when running as root Fixes #2388 * feat(changelog): add fragment for PR 12090 * fix(test_composer): update expected working-dir command format The composer_as_root test case still expected the pre-rebase command format (working-dir as a separate trailing option) instead of the current --working-dir=<path> token placed before the subcommand. * reformat * fix(composer): relay composer's own root/super-user warning instead of reimplementing it Per review feedback, stop independently deciding when running as root is unsafe (which is wrong in cases like official containers) and instead surface composer's own warning as an Ansible warning. * fix(test_composer): make root-warning assertion resilient across ansible-core versions CI on ansible-core 2.18 failed: module.warn() serializes warnings as plain strings there, but as structured WarningSummary/Event dicts on 2.19+. Assert via substring match instead of exact equality so the test passes on both. --------- (cherry picked from commit 9bb7aee) Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
SUMMARY
When the
community.general.composermodule runs as root, composer itself emits a security warning that is currently silently swallowed. This PR adds amodule.warn()call when the effective UID is 0, so operators are made aware of the issue. TheCOMPOSER_ALLOW_SUPERUSERenvironment variable is documented in the module notes as the upstream escape hatch.Fixes #2388
ISSUE TYPE
COMPONENT NAME
composer
ADDITIONAL INFORMATION
N/A