Skip to content

common-utils: Make sudoers configuration optional - #1723

Open
Daniel Weuthen (weuthen-sipgate) wants to merge 3 commits into
devcontainers:mainfrom
weuthen-sipgate:main
Open

common-utils: Make sudoers configuration optional#1723
Daniel Weuthen (weuthen-sipgate) wants to merge 3 commits into
devcontainers:mainfrom
weuthen-sipgate:main

Conversation

@weuthen-sipgate

Copy link
Copy Markdown

This pull request adds a new configurable option to the common-utils feature 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:

  • Added a new sudoers boolean option to devcontainer-feature.json, allowing users to specify whether the non-root user should be added to passwordless sudoers (defaults to true).
  • Updated the documentation in README.md to describe the new sudoers option.
  • Bumped the common-utils feature version to 2.6.0 to reflect the new functionality.

Implementation update:

  • Modified main.sh to respect the new SUDOERS environment variable and conditionally add the non-root user to the sudoers file only if the option is enabled. [1] [2]

Testing improvements:

  • Added new test scenarios and scripts (sudoers-true and sudoers-false) to verify the correct behavior of the sudoers option, ensuring the sudoers file is created or omitted as expected. [1] [2] [3]

@weuthen-sipgate

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree company="sipgate"

1 similar comment
@weuthen-sipgate

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree company="sipgate"

@Kaniska244 Kaniska (Kaniska244) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants