Skip to content

Commit

Permalink
Fix: common-utils configureZshAsDefaultShell option not working on al…
Browse files Browse the repository at this point in the history
…pine linux image (#557)

* alpine defaultZsh fix

* common-utils: replace pam.d/chsh permission with `sufficient`

* common-utils: revert match auth sufficient

* common-utils: append auth string instead of replacing a whole file

* fix grep 2nd param

* fix: line checking condition
  • Loading branch information
krikchaip authored Aug 2, 2023
1 parent 836ea1e commit 685fa2e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 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.0.10",
"version": "2.0.11",
"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
8 changes: 8 additions & 0 deletions src/common-utils/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,14 @@ if [ "${INSTALL_ZSH}" = "true" ]; then
fi

if [ "${CONFIGURE_ZSH_AS_DEFAULT_SHELL}" == "true" ]; then
# Fixing chsh always asking for a password on alpine linux
# ref: https://askubuntu.com/questions/812420/chsh-always-asking-a-password-and-get-pam-authentication-failure.
if [ ! -f "/etc/pam.d/chsh" ] || ! grep -Eq '^auth(.*)pam_rootok\.so$' /etc/pam.d/chsh; then
echo "auth sufficient pam_rootok.so" >> /etc/pam.d/chsh
elif [[ -n "$(awk '/^auth(.*)pam_rootok\.so$/ && !/^auth[[:blank:]]+sufficient[[:blank:]]+pam_rootok\.so$/' /etc/pam.d/chsh)" ]]; then
awk '/^auth(.*)pam_rootok\.so$/ { $2 = "sufficient" } { print }' /etc/pam.d/chsh > /tmp/chsh.tmp && mv /tmp/chsh.tmp /etc/pam.d/chsh
fi

chsh --shell /bin/zsh ${USERNAME}
fi

Expand Down
13 changes: 13 additions & 0 deletions test/common-utils/alpine-base-zsh-default.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

set -e

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

# Definition specific tests
check "alpine default shell zsh" \
bash -c "getent passwd $(whoami) | awk -F : '{ print $7 }' | grep '/bin/zsh'"

# Report result
reportResults
13 changes: 11 additions & 2 deletions test/common-utils/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
"build": {
"dockerfile": "Dockerfile"
},
"remoteUser": "vscode",
"features": {
"common-utils": {
"username": "vscode",
Expand All @@ -151,7 +152,15 @@
"upgradePackages": true,
"installZsh": true
}
},
"remoteUser": "vscode"
}
},
"alpine-base-zsh-default": {
"image": "mcr.microsoft.com/devcontainers/base:alpine",
"remoteUser": "vscode",
"features": {
"common-utils": {
"configureZshAsDefaultShell": true
}
}
}
}

0 comments on commit 685fa2e

Please sign in to comment.