DSC
DSC copied to clipboard
MacOS DSC will hang when requesting sudo password, running sudo dsc will cause homebrew to fail
Prerequisites
- [x] Write a descriptive title.
- [x] Make sure you are able to repro it on the latest version
- [x] Search the existing issues.
Summary
./dsc will hang forever awaiting sudo password input for commands. sudo ./dsh causes homebrew to fail because homebrew doesn't want to be run as root.
Steps to reproduce
$schema: https://raw.githubusercontent.com/PowerShell/DSC/refs/heads/main/schemas/v3/config/document.json
resources:
- name: Install VSCode
type: DSC.PackageManagement/Brew
properties:
packageName: visual-studio-code
- name: Install Neovim
type: DSC.PackageManagement/Brew
properties:
packageName: neovim
- name: Install PowerShell
type: DSC.PackageManagement/Brew
properties:
packageName: powershell/tap/powershell
- name: Add PowerShell to etc shells
type: Microsoft.DSC.Transitional/RunCommandOnSet
properties:
executable: /bin/zsh
arguments:
- -c
- 'PWSH_PATH=$(which pwsh); if ! grep -q "$PWSH_PATH" /etc/shells; then echo "$PWSH_PATH" | sudo tee -a /etc/shells; fi'
- name: Change Default Shell
type: Microsoft.DSC.Transitional/RunCommandOnSet
properties:
executable: /bin/zsh
arguments:
- -c
- 'PWSH_PATH=$(which pwsh); chsh -s "$PWSH_PATH" $(whoami)'
Expected behavior
no hang
Actual behavior
hang
Error details
Environment data
echo $PSVersionTable
Name Value
---- -----
PSVersion 7.5.0
PSEdition Core
GitCommitId 7.5.0
OS Darwin 24.3.0 Darwin Kernel Version 24.3.0: Thu Jan 2 20:24:16 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T6000
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Version
3.0.0
Visuals
No response
trying to su before running ./dsc doesn't work either
I think what you need is to wait for this feature: https://github.com/PowerShell/DSC/issues/666
Unless you set sudo to not prompt for a password (which is a really bad practice), you really shouldn't use sudo in a script which is what RunCommandOnSet basically does.