Skip to content
Merged
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
7 changes: 6 additions & 1 deletion src/create-remote-user/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Create Remote User",
"id": "create-remote-user",
"version": "0.0.3",
"version": "0.0.4",
"description": "A to assert the configured remote user exists in the container",
"licenseURL": "https://github.com/nils-geistmann/devcontainers-features/blob/main/LICENSE",
"options": {
Expand All @@ -19,6 +19,11 @@
"description": "Install sudo if it is not yet installed",
"type": "boolean",
"default": true
},
"passwordLessSudo": {
"description": "Configures sudo to allow the remote user to elevate permissions without password",
"type": "boolean",
"default": false
}
}
}
5 changes: 5 additions & 0 deletions src/create-remote-user/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ if [ "$INSTALLSUDO" = "true" ] && ! which sudo; then
check_and_install sudo
fi

if [ "$PASSWORDLESSSUDO" = "true" ]; then
echo "$_REMOTE_USER" ALL=\(root\) NOPASSWD:ALL > "/etc/sudoers.d/$_REMOTE_USER"
fi


clean_package_cache
1 change: 1 addition & 0 deletions test/create-remote-user/default_configuration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ check "configured user should exist" assert_user_exists "remote"
check "configured user should be in group sudo" assert_user_is_in_group "remote" "sudo"
check "sudo should be available" assert_command_is_available "sudo"
check "password for user should be set" assert_password_is_set "remote" "remote"
check "sudo should require a password" assert_sudo_requires_password "remote"

reportResults
9 changes: 9 additions & 0 deletions test/create-remote-user/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,14 @@
}
},
"remoteUser": "remote"
},
"sudo_does_not_require_a_password": {
"image": "debian:bookworm-slim",
"features": {
"create-remote-user": {
"passwordLessSudo": true
}
},
"remoteUser": "remote"
}
}
8 changes: 8 additions & 0 deletions test/create-remote-user/sudo_does_not_require_a_password.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

source dev-container-features-test-lib
source test_functions.sh

check "sudo does not require a password" assert_sudo_requires_no_password "remote"

reportResults
12 changes: 12 additions & 0 deletions test/create-remote-user/test_functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,15 @@ assert_password_is_set() {
exit 1
fi
}

assert_sudo_requires_password() {
if echo "$1" | sudo -S -l | grep NOPASSWD; then
exit 1
fi
}

assert_sudo_requires_no_password() {
if ! echo "$1" | sudo -S -l | grep NOPASSWD; then
exit 1
fi
}