common-utils: Make sudoers configuration optional - #1723
common-utils: Make sudoers configuration optional#1723Daniel Weuthen (weuthen-sipgate) wants to merge 3 commits into
Conversation
|
@microsoft-github-policy-service agree company="sipgate" |
1 similar comment
|
@microsoft-github-policy-service agree company="sipgate" |
There was a problem hiding this comment.
Hi Daniel Weuthen (@weuthen-sipgate),
Thank you for the contribution. LGTM. To be further reviewed by maintainers.
Although not a necessity, would it be possible for you to add few more tests to check the default behavior for different distros. Kindly let me know in case of any concern. I could have added them myself but don't have permission to do so.
Modifying /test/common-utils/scenarios.json file to add couple of tests:
"resolute": {
"image": "ubuntu:resolute",
"remoteUser": "devcontainer",
"features": {
"common-utils": {}
}
},
"trixie": {
"image": "debian:trixie",
"remoteUser": "devcontainer",
"features": {
"common-utils": {}
}
},
Add the following files:
/test/common-utils/resolute.sh:
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
. /etc/os-release
check "non-root user" test "$(whoami)" = "devcontainer"
check "distro" test "${VERSION_CODENAME}" = "resolute"
check "bubblewrap" bwrap --version
check "socat" socat -V
# Check if the sudoers file for the non-root user exists
check "sudoers file exists" test -f /etc/sudoers.d/$(whoami)
# Check if the sudoers entry for the non-root user is correctly configured
check "sudoers entry for non-root user" sudo grep "$(whoami) ALL=(root) NOPASSWD:ALL" /etc/sudoers.d/$(whoami)
# Report result
reportResults
/test/common-utils/trixie.sh:
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
. /etc/os-release
check "non-root user" test "$(whoami)" = "devcontainer"
check "distro" test "${VERSION_CODENAME}" = "trixie"
check "bubblewrap" bwrap --version
check "socat" socat -V
# Check if the sudoers file for the non-root user exists
check "sudoers file exists" test -f /etc/sudoers.d/$(whoami)
# Check if the sudoers entry for the non-root user is correctly configured
check "sudoers entry for non-root user" sudo grep "$(whoami) ALL=(root) NOPASSWD:ALL" /etc/sudoers.d/$(whoami)
# Report result
reportResults
Add the following snippet for sudo access check in the following file:
/test/common-utils/devcontainer-info.sh:
# Check if the sudoers file for the non-root user exists
check "sudoers file exists" test -f /etc/sudoers.d/$(whoami)
# Check if the sudoers entry for the non-root user is correctly configured
check "sudoers entry for non-root user" sudo grep "$(whoami) ALL=(root) NOPASSWD:ALL" /etc/sudoers.d/$(whoami)
/test/common-utils/fedora.sh:
# Check if the sudoers file for the non-root user exists
check "sudoers file exists" sudo test -f /etc/sudoers.d/$(whoami)
# Check if the sudoers entry for the non-root user is correctly configured
check "sudoers entry for non-root user" sudo grep "$(whoami) ALL=(root) NOPASSWD:ALL" /etc/sudoers.d/$(whoami)
This pull request adds a new configurable option to the
common-utilsfeature that allows users to control whether a non-root user is added to the passwordless sudoers list. By default, this option is enabled, but it can now be disabled if desired. The changes include updates to documentation, feature configuration, implementation logic, and new tests to verify both enabled and disabled scenarios.Feature enhancement:
sudoersboolean option todevcontainer-feature.json, allowing users to specify whether the non-root user should be added to passwordless sudoers (defaults totrue).README.mdto describe the newsudoersoption.common-utilsfeature version to2.6.0to reflect the new functionality.Implementation update:
main.shto respect the newSUDOERSenvironment variable and conditionally add the non-root user to the sudoers file only if the option is enabled. [1] [2]Testing improvements:
sudoers-trueandsudoers-false) to verify the correct behavior of thesudoersoption, ensuring the sudoers file is created or omitted as expected. [1] [2] [3]