Skip to content

Commit aad1191

Browse files
louisgvclaude
andcommitted
fix(github-auth): add sudo availability check before use
In rootless containers or environments without sudo, the script previously failed with cryptic errors. Now fails fast with a clear error message when non-root and sudo is unavailable. Fixes #3069 Agent: security-auditor Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 4ad7213 commit aad1191

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

sh/shared/github-auth.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@ _install_gh_brew() {
3939
_install_gh_apt() {
4040
# Use sudo only when not already root (some cloud containers run as root)
4141
local SUDO=""
42-
if [[ "$(id -u)" -ne 0 ]]; then SUDO="sudo"; fi
42+
if [[ "$(id -u)" -ne 0 ]]; then
43+
if command -v sudo >/dev/null 2>&1; then
44+
SUDO="sudo"
45+
else
46+
log_error "This script requires sudo or root privileges to install gh via apt"
47+
return 1
48+
fi
49+
fi
4350

4451
log_info "Adding GitHub CLI APT repository..."
4552
curl -fsSL --proto '=https' https://cli.github.com/packages/githubcli-archive-keyring.gpg \
@@ -58,7 +65,14 @@ _install_gh_apt() {
5865
# Install gh via DNF (Fedora/RHEL)
5966
_install_gh_dnf() {
6067
local SUDO=""
61-
if [[ "$(id -u)" -ne 0 ]]; then SUDO="sudo"; fi
68+
if [[ "$(id -u)" -ne 0 ]]; then
69+
if command -v sudo >/dev/null 2>&1; then
70+
SUDO="sudo"
71+
else
72+
log_error "This script requires sudo or root privileges to install gh via dnf"
73+
return 1
74+
fi
75+
fi
6276
${SUDO} dnf install -y gh || {
6377
log_error "Failed to install gh via dnf"
6478
return 1

0 commit comments

Comments
 (0)