Skip to content

Fix install.sh escalating to sudo for user-writable $HOME/.local/bin - #12836

Merged
sk593 merged 8 commits into
mainfrom
sk593/fix-install-sudo-local-bin
Aug 27, 2026
Merged

sk593 merged 8 commits into
mainfrom
sk593/fix-install-sudo-local-bin

Conversation

@sk593

@sk593 sk593 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Description

deploy/install.sh could install the rad CLI into a root-owned $HOME/.local/bin, which then broke any later user-owned tool install into the same directory (e.g. make install-yq) with Permission denied.

needsSudo() only checked the install dir and its immediate parent. When the default install dir is $HOME/.local/bin and neither .local/bin nor .local exists yet (common on a fresh GitHub-hosted runner), both checks fail, so the installer escalates to sudo and sudo mkdir -p creates the whole ~/.local tree root-owned — even though $HOME is writable and no elevation was actually needed.

The next user-owned install into that dir (build/scripts/install-yq.sh) then does mkdir -p (silently succeeds, dir exists) and mv into the root-owned dir, failing with Permission denied at the Load Radius contrib catalog step of the extension deploy/delete workflows.

Fix

Make needsSudo() walk up to the nearest existing ancestor and only escalate to sudo when that ancestor is not writable. For $HOME/.local/bin under a writable $HOME, the tree is created as the current user (no sudo) and stays user-owned, so later installs into it succeed.

Type of change

  • Bugfix

Fixes

Fixes #12835

Testing

Extracted the patched needsSudo() and exercised it against a temp filesystem:

Case install dir before after
Fresh writable $HOME, nested .local/bin missing $HOME/.local/bin needs sudo ❌ no sudo ✅
Existing writable install dir $HOME/.local/bin no sudo no sudo ✅
/usr/local/bin (not writable) /usr/local/bin sudo sudo ✅
Nearest existing ancestor not writable <ro>/sub/bin sudo sudo ✅

bash -n passes; behavior is unchanged for the root, already-writable, and genuinely-needs-root cases.

Why it was intermittent

install-yq.sh early-returns when a matching yq is already on PATH. Runners with a pre-baked yq skipped the failing mv entirely; runners without it hit it. Same workflow, different runner image contents.

needsSudo() only checked the install dir and its immediate parent. When the
default install dir is $HOME/.local/bin and neither .local/bin nor .local
exists yet (common on fresh GitHub-hosted runners), both checks fail and the
installer escalates to sudo, creating the whole ~/.local tree root-owned even
though $HOME is writable and no elevation was needed.

A later user-owned install into the same dir (e.g. make install-yq via
build/scripts/install-yq.sh) then fails with 'Permission denied' at the
'Load Radius contrib catalog' step of the extension deploy/delete workflows.

Walk up to the nearest existing ancestor and only escalate when that ancestor
is not writable, so $HOME/.local/bin is created as the current user and stays
user-owned.

Fixes #12835

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: sk593 <shruthikumar@microsoft.com>
Copilot AI lite review requested due to automatic review settings August 26, 2026 21:24
@sk593
sk593 requested review from a team as code owners August 26, 2026 21:24
@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes deploy/install.sh’s needsSudo() decision logic so the installer doesn’t unnecessarily escalate to sudo when installing into a user-writable nested directory (notably $HOME/.local/bin when .local/ doesn’t exist yet). This prevents creating a root-owned ~/.local tree that later breaks subsequent user-owned tool installs into the same location.

Changes:

  • Updates needsSudo() to walk up the directory tree to the nearest existing ancestor and only require sudo when that ancestor isn’t writable.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread deploy/install.sh Resolved
@codecov

codecov Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.98%. Comparing base (f00bb86) to head (c207b03).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #12836   +/-   ##
=======================================
  Coverage   59.97%   59.98%           
=======================================
  Files         776      776           
  Lines       46410    46410           
=======================================
+ Hits        27836    27837    +1     
+ Misses      18574    18573    -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

Unit Tests

    2 files  ±0    459 suites  ±0   8m 42s ⏱️ +24s
6 518 tests ±0  6 516 ✅ ±0  2 💤 ±0  0 ❌ ±0 
7 794 runs  ±0  7 792 ✅ ±0  2 💤 ±0  0 ❌ ±0 

Results for commit c207b03. ± Comparison against base commit f00bb86.

♻️ This comment has been updated with latest results.

@sk593 sk593 added the pr:standard Ongoing maintenance, minor improvements, documentation updates, and routine development work label Aug 26, 2026
If the install dir exists but is not writable (e.g. a pre-created
root-owned dir) while its parent is writable, the previous walk starting
at dirname(install_dir) incorrectly decided no sudo was needed, causing
later cp/mkdir to fail with Permission denied. Start the walk at
install_dir so an existing non-writable target correctly triggers sudo.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: sk593 <shruthikumar@microsoft.com>
sk593 and others added 2 commits August 26, 2026 17:52
Update the pinned install.sh tag in setup-control-plane from v0.59.0 to
the latest stable release v0.60.1. The script is byte-identical between
these tags, so RADIUS_INSTALL_SHA256 is unchanged.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: sk593 <shruthikumar@microsoft.com>
The v0.60.1 bump did not carry the install.sh sudo fix (its install.sh is
byte-identical to v0.59.0). The pin will instead be updated to the merge
commit on main once the install.sh fix lands, so keep this PR scoped to
the install.sh change only.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: sk593 <shruthikumar@microsoft.com>
getLatestRelease() called the GitHub releases API unauthenticated, which is
rate-limited to 60 requests/hour per IP. On shared CI runners this limit is
easily exhausted, causing the Validate Bash Installer job to fail when
resolving the latest release.

Add a githubApiGet() helper that sends an Authorization header when
GITHUB_TOKEN is set, and pass github.token to the installer test steps in
validate-installers.yaml. install.ps1 already supports GITHUB_USER/GITHUB_TOKEN
Basic auth, so the PowerShell test step now passes those too.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: sk593 <shruthikumar@microsoft.com>
@sk593
sk593 requested a review from a team as a code owner August 27, 2026 01:08
…ate limits"

This reverts commit 09c8a4f.

The bash installer CI failure was caused by GitHub API rate limiting, which is
an edge case not worth addressing here. Keep this PR scoped to the sudo fix.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: sk593 <shruthikumar@microsoft.com>
Comment thread deploy/install.sh Resolved
Comment thread deploy/install.sh Resolved
Comment thread deploy/install.sh Resolved
Address review feedback:
- test_default_dir_nonroot no longer pre-creates $HOME/.local/bin, so it
  reproduces #12835 and fails without the needsSudo() ancestor-walk logic.
- test_nonwritable_dir_no_sudo_fails now chmods only the install dir (not its
  parent), pinning the 3fd9e2a fix that starts the walk at install_dir; drops
  the now-stale 'it checks both' comment.
- Generalize the needsSudo() comment: all build/scripts/install-*.sh tools
  default to $HOME/.local/bin, not just yq.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: sk593 <shruthikumar@microsoft.com>
Comment thread deploy/test-install.sh Resolved
test_default_dir_nonroot only checked -f/-x/runnable, which pass even when the
installer sudo-creates the tree root-owned on runners with passwordless sudo -
so it still passed on main. Add a bash -O (owned by effective UID) assertion on
both $HOME/.local and $HOME/.local/bin to pin the #12835 fix; -O avoids the
GNU/BSD stat split for contributors on macOS.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: sk593 <shruthikumar@microsoft.com>
@radius-functional-tests

radius-functional-tests Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Radius functional test overview

🔍 Go to test action run

Click here to see the test run details
Name Value
Repository radius-project/radius
Commit ref c207b03
Unique ID funcc333b978e4
Image tag pr-funcc333b978e4
  • Dapr: 1.14.4
  • Azure KeyVault CSI driver: 1.4.2
  • Azure Workload identity webhook: 1.3.0
  • Bicep recipe location ghcr.io/radius-project/dev/test/testrecipes/test-bicep-recipes/<name>:pr-funcc333b978e4
  • Terraform recipe location http://tf-module-server.radius-test-tf-module-server.svc.cluster.local/<name>.zip (in cluster)
  • applications-rp test image location: ghcr.io/radius-project/dev/applications-rp:pr-funcc333b978e4
  • dynamic-rp test image location: ghcr.io/radius-project/dev/dynamic-rp:pr-funcc333b978e4
  • controller test image location: ghcr.io/radius-project/dev/controller:pr-funcc333b978e4
  • ucp test image location: ghcr.io/radius-project/dev/ucpd:pr-funcc333b978e4
  • deployment-engine test image location: ghcr.io/radius-project/deployment-engine:latest

Test Status

⌛ Building Radius and pushing container images for functional tests...
✅ Container images build succeeded
⌛ Publishing Bicep Recipes for functional tests...
✅ Recipe publishing succeeded
⌛ Starting ucp-cloud functional tests...
⌛ Starting corerp-cloud functional tests...
✅ ucp-cloud functional tests succeeded
✅ corerp-cloud functional tests succeeded

@sk593
sk593 added this pull request to the merge queue Aug 27, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Aug 27, 2026
@sk593
sk593 added this pull request to the merge queue Aug 27, 2026
@sk593
sk593 removed this pull request from the merge queue due to a manual request Aug 27, 2026
@sk593
sk593 added this pull request to the merge queue Aug 27, 2026
Merged via the queue into main with commit f4b4413 Aug 27, 2026
77 of 78 checks passed
@sk593
sk593 deleted the sk593/fix-install-sudo-local-bin branch August 27, 2026 15:45
sk593 added a commit that referenced this pull request Aug 27, 2026
Point the setup-control-plane install-script pin at the immutable commit
carrying the install.sh sudo fix (#12836) so the
ai-extensions workflows pick it up without waiting for a patch release.
The ref is a full commit SHA (immutable) and the fetched script is still
checksum-verified, preserving the existing security posture.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Signed-off-by: sk593 <shruthikumar@microsoft.com>
DariuszPorowski pushed a commit that referenced this pull request Aug 27, 2026
## Purpose

Unblock the extensions workflows on the `install.sh` sudo fix (#12836)
**without waiting for a patch release**.

`setup-control-plane` fetches `install.sh` from a pinned Radius ref and
checksum-verifies it. This repoints that pin from the released tag to
the **immutable commit** that carries the sudo fix, so consumers get the
fixed script immediately. A full commit SHA is immutable and the script
is still checksum-verified, so the existing security posture is
preserved.

- `RADIUS_INSTALL_REF`: `f4b44130e6cc`
- `RADIUS_INSTALL_SHA256`:
`d12f6e1101dea7911c491de14a0f0aef57518aaf573d46e225b29d6f103c2e86`

Verified locally that the workflow's fetch + `sha256sum -c` succeeds
against this ref.

## Before merging

- [ ] Merge #12836 first.
- [ ] Repoint `RADIUS_INSTALL_REF` to the **squash-merge commit of
#12836 on `main`** (the fixed `install.sh` content is unchanged, so
`RADIUS_INSTALL_SHA256` stays `6a00f7b8…`). This avoids depending on a
PR-branch commit that could be GC'd after the branch is deleted.

## Notes

Depends on #12836.

---------

Signed-off-by: sk593 <shruthikumar@microsoft.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
willdavsmith pushed a commit that referenced this pull request Sep 3, 2026
…12836)

## Description

`deploy/install.sh` could install the `rad` CLI into a **root-owned**
`$HOME/.local/bin`, which then broke any later user-owned tool install
into the same directory (e.g. `make install-yq`) with `Permission
denied`.

`needsSudo()` only checked the install dir and its **immediate** parent.
When the default install dir is `$HOME/.local/bin` and neither
`.local/bin` nor `.local` exists yet (common on a fresh GitHub-hosted
runner), both checks fail, so the installer escalates to `sudo` and
`sudo mkdir -p` creates the whole `~/.local` tree **root-owned** — even
though `$HOME` is writable and no elevation was actually needed.

The next user-owned install into that dir
(`build/scripts/install-yq.sh`) then does `mkdir -p` (silently succeeds,
dir exists) and `mv` into the root-owned dir, failing with `Permission
denied` at the **Load Radius contrib catalog** step of the extension
deploy/delete workflows.

### Fix

Make `needsSudo()` walk up to the nearest **existing** ancestor and only
escalate to `sudo` when that ancestor is not writable. For
`$HOME/.local/bin` under a writable `$HOME`, the tree is created as the
current user (no sudo) and stays user-owned, so later installs into it
succeed.

## Type of change

- Bugfix

## Fixes

Fixes #12835

## Testing

Extracted the patched `needsSudo()` and exercised it against a temp
filesystem:

| Case | install dir | before | after |
|------|-------------|--------|-------|
| Fresh writable `$HOME`, nested `.local/bin` missing |
`$HOME/.local/bin` | needs sudo ❌ | **no sudo** ✅ |
| Existing writable install dir | `$HOME/.local/bin` | no sudo | no sudo
✅ |
| `/usr/local/bin` (not writable) | `/usr/local/bin` | sudo | sudo ✅ |
| Nearest existing ancestor not writable | `<ro>/sub/bin` | sudo | sudo
✅ |

`bash -n` passes; behavior is unchanged for the root, already-writable,
and genuinely-needs-root cases.

## Why it was intermittent

`install-yq.sh` early-returns when a matching `yq` is already on `PATH`.
Runners with a pre-baked `yq` skipped the failing `mv` entirely; runners
without it hit it. Same workflow, different runner image contents.

---------

Signed-off-by: sk593 <shruthikumar@microsoft.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
(cherry picked from commit f4b4413)
nithyatsu pushed a commit to zachcasper/radius that referenced this pull request Sep 29, 2026
…taller (radius-project#12852)

## Description

`rad bicep download` (invoked by `deploy/install.ps1`) streams a large
(~110MB) binary with no client-side timeout, so a stalled network
transfer hangs the installer indefinitely. This surfaced during radius-project#12836
as the **Validate PowerShell Installer** CI job burning its full
10-minute budget at `Installing bicep...` and being cancelled, with no
application error in the logs.

Since bicep is optional (its failure is already non-fatal in the
installer), this bounds the download: `rad bicep download` now runs as a
child process with a 300s timeout. On timeout the process is stopped and
the installer warns and continues instead of hanging.

This is a **script-level mitigation**. The underlying root cause — the
missing HTTP timeout in the rad CLI's shared bicep download code
(`pkg/cli/bicep/tools/download_tools.go` uses `http.Get` + `io.Copy`
with no deadline) — is tracked in radius-project#12851.

## Type of change

This pull request fixes a bug in Radius and has an approved issue
(radius-project#12851).

## Notes

- Surfaced during radius-project#12836.
- Verified the timeout/kill and success paths locally with `pwsh` (parse
check + simulated hang).
- No unit-test framework exists for the installer shell scripts;
validated via the `Validate PowerShell Installer` job.

---------

Signed-off-by: sk593 <shruthikumar@microsoft.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

github-copilot pr:standard Ongoing maintenance, minor improvements, documentation updates, and routine development work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

install.sh escalates to sudo for $HOME/.local/bin when .local doesn't exist, leaving it root-owned and breaking later user-owned tool installs (yq)

5 participants