Conversation
When os.Rename fails with a permission error (e.g., binary in /usr/local/bin and run without sudo), the previous code fell back to installViaDestDir which tried to create a temp file in the same protected directory — producing a confusing "check write permissions" error. Now: EXDEV (cross-device link) errors still use the installViaDestDir fallback, while permission errors surface a clear "try running with elevated privileges, e.g. sudo" message. Adds TestDownloadAndInstallPermissionDenied to cover this code path. Co-authored-by: 403-html <57900160+403-html@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix permission denied error during nillsec upgrade
fix: don't fall back to dest-dir install on permission-denied upgrade errors
Mar 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the binary lives in a privileged directory (e.g.
/usr/local/bin),nillsec upgradeproduced a confusing internal error about temp file creation rather than telling the user to usesudo.Root cause:
downloadAndInstallfell back toinstallViaDestDiron anyos.Renamefailure.installViaDestDirworks by staging a temp file inside the destination directory — useless when the failure isEACCES, since that directory isn't writable either.Changes:
upgrade.go: Inspect theos.Renameerror before deciding on a fallback:EXDEV(cross-device link) → proceed withinstallViaDestDiras beforeEACCES/ permission error → return immediately with an actionable messageupgrade_test.go: AddedTestDownloadAndInstallPermissionDenied— chmod 555 on the destination directory, asserts the error contains"elevated privileges"and not"check write permissions", and verifies the original binary is untouched.🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.