Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/common-utils/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Installs a set of common command line utilities, Oh My Zsh!, and sets up a non-r
| username | Enter name of a non-root user to configure or none to skip | string | automatic |
| userUid | Enter UID for non-root user | string | automatic |
| userGid | Enter GID for non-root user | string | automatic |
| sudoers | Add sudoers entry for the non-root user | boolean | true |
| nonFreePackages | Add packages from non-free Debian repository? (Debian only) | boolean | false |

## OS Support
Expand Down
7 changes: 6 additions & 1 deletion src/common-utils/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "common-utils",
"version": "2.5.9",
"version": "2.6.0",
"name": "Common Utilities",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/common-utils",
"description": "Installs a set of common command line utilities, Oh My Zsh!, and sets up a non-root user.",
Expand Down Expand Up @@ -60,6 +60,11 @@
"default": "automatic",
"description": "Enter GID for non-root user"
},
"sudoers": {
"type": "boolean",
"default": true,
"description": "Add non-root user to passwordless sudoers?"
},
"nonFreePackages": {
"type": "boolean",
"default": false,
Expand Down
11 changes: 7 additions & 4 deletions src/common-utils/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ UPGRADE_PACKAGES="${UPGRADEPACKAGES:-"true"}"
USERNAME="${USERNAME:-"automatic"}"
USER_UID="${USERUID:-"automatic"}"
USER_GID="${USERGID:-"automatic"}"
SUDOERS="${SUDOERS:-"true"}"
ADD_NON_FREE_PACKAGES="${NONFREEPACKAGES:-"false"}"
INSTALL_SSL="${INSTALLSSL:-"true"}"

Expand Down Expand Up @@ -471,10 +472,12 @@ else
fi

# Add add sudo support for non-root user
if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then
echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME
chmod 0440 /etc/sudoers.d/$USERNAME
EXISTING_NON_ROOT_USER="${USERNAME}"
if [ "$SUDOERS" = "true" ]; then
if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then
echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME
chmod 0440 /etc/sudoers.d/$USERNAME
EXISTING_NON_ROOT_USER="${USERNAME}"
fi
fi

# *********************************
Expand Down
18 changes: 18 additions & 0 deletions test/common-utils/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,24 @@
"common-utils": {}
}
},
"sudoers-true": {
"image": "debian:bullseye",
"remoteUser": "vscode",
"features": {
"common-utils": {
"sudoers": true
}
}
},
"sudoers-false": {
"image": "debian:bullseye",
"remoteUser": "vscode",
"features": {
"common-utils": {
"sudoers": false
}
}
},
"terminal-title-on-xterm": {
"image": "node",
"features": {
Expand Down
16 changes: 16 additions & 0 deletions test/common-utils/sudoers-false.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -e

# Optional: Import test library
source dev-container-features-test-lib

# Always run these checks as the non-root user
user="$(whoami)"
check "user" grep vscode <<< "$user"

# Check that the sudoers file for the non-root user does not exist
check "sudoers file does not exist" test ! -f /etc/sudoers.d/$user

# Report result
reportResults
19 changes: 19 additions & 0 deletions test/common-utils/sudoers-true.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -e

# Optional: Import test library
source dev-container-features-test-lib

# Always run these checks as the non-root user
user="$(whoami)"
check "user" grep vscode <<< "$user"

# Check if the sudoers file for the non-root user exists
check "sudoers file exists" test -f /etc/sudoers.d/$user

# Check if the sudoers entry for the non-root user is correctly configured
check "sudoers entry for non-root user" sudo grep "$user ALL=(root) NOPASSWD:ALL" /etc/sudoers.d/$user

# Report result
reportResults
Loading