Fix: common-utils configureZshAsDefaultShell option not working on alpine 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
This commit is contained in:
Krikchai Pongtaveewould 2023-08-03 05:12:14 +07:00 committed by GitHub
parent 836ea1e9fa
commit 685fa2e0f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 3 deletions

View file

@ -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.",

View file

@ -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

View file

@ -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

View file

@ -143,6 +143,7 @@
"build": {
"dockerfile": "Dockerfile"
},
"remoteUser": "vscode",
"features": {
"common-utils": {
"username": "vscode",
@ -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
}
}
}
}