Repository navigation
fix chat guardrails blocking package installs under a restrictive umask - #18567
Conversation
The world-readable permission check in the chat guardrails denied reads of any file lacking the o+r bit, unconditionally. In environments with a restrictive umask (e.g. Workbench sessions in hardened containers with umask 077), every file the session creates is private, so agent code tripped over files R itself had just written -- most visibly the installed.packages() cache in tempdir(), which fails dependency resolution inside install.packages(). Three changes: - Skip the world-readable check for files within the allowed roots (tempdir, working directory, project, scratch path, library paths, R user dirs) -- locations the agent is already allowed to write to. - Skip the check entirely when the umask itself strips world-read from new files, since then a missing o+r bit is the environment's default and carries no signal about a file's sensitivity. - Allow edits within a not-yet-created user library (R_LIBS_USER), so first-time personal library creation works. The deny-path patterns (credentials, .env, .Renviron, system files) still apply everywhere, including within the allowed roots. Addresses rstudio/rstudio-pro#11975.
|
thank you! nice fix |
Code review findingsActionable items from an automated review of this PR. Critical
Important
Suggestions
Checked and found correct: |
RStudio E2E - all platforms1 test(s) failed
View / download the full reportView report online -- opens in the browser, no download needed. Available for 14 days. Download playwright-report.zip -- extract and open
All platforms - commit |
…e roots - generalize the .ssh deny-read pattern to all non-.pub files, so private keys under any name (deploy_key, etc.) stay blocked - exclude the home directory itself from the read-exemption roots: it is the fallback working directory when no project is open, and exempting it would hide mode-600 dotfiles from the permission check - sample the umask once (Sys.umask(NA) briefly zeroes the process umask, and a live query would let agent code disable the check) - memoize allowedRoots() on its dynamic inputs; it runs on every hooked file operation and the scratch-path lookup touches the filesystem
|
All four findings were real; addressed in d115b76.
New tests cover each: pattern gaps and a readable |
Summary
Posit Assistant's
install.packages()fails in Workbench sessions running under a restrictive umask (common in hardened containers), with repeated "One or more agent file operations were blocked" errors that eventually push the model to work around the sandbox viaRscriptin the terminal.Root cause: the guardrails' world-readable check in
.rs.chat.isFileReadAllowed()denied reads of any file lacking the o+r permission bit, unconditionally. Under umask 077 every file the session creates is mode 600, so agent code was blocked from reading files R itself had just written. The most visible victim is theinstalled.packages()cache (tempdir()/libloc_*.rds): the cache gets seeded by the IDE or an earlier command, and the next read -- duringinstall.packages()dependency resolution -- hits the hookedreadRDS()and errors. The same check also blocked the agent from reading any user-owned file (project files included) in such environments. Thechat.safeFunctionstrusted-caller allowlist did not help, because trust only bypasses the deny-path patterns, not the permission check.Changes
.libPaths(), R user dirs). These are locations the agent may already write to, so denying reads there was incoherent -- and they are exactly where the session's own non-world-readable files live. The allowed roots are now enumerated in one place (chat.allowedRoots()), shared by the edit check and the read check.R_LIBS_USER), soinstall.packages()can create the personal library on first use (a nonexistent user library is not in.libPaths(), so it was previously denied).The deny-path patterns (credentials,
.env,.Renviron,~/.ssh, system files) still apply everywhere, including within the allowed roots and regardless of umask.Security trade-offs
These guardrails target accidental misuse, not malicious code (per the note at the top of
SessionChat.R). Two deliberate loosenings here:.sshread-deny pattern covers all non-public files.Rscriptsubprocess where no checks apply at all.Testing
test-chat-guardrails.Rfor the allowed-roots exemption, the umask neutralization, the not-yet-created user library, pattern denials still applying within allowed roots, and an end-to-endinstalled.packages()-twice regression test under umask 077 (the exact failure from the report). All six new tests fail before the fix and pass after; the pre-existing 89 assertions pass unchanged.libloc_*.rdscache, agent-driveninstall.packages("desc")(source, with dependencies) andinstall.packages("praise")(macOS in-process binary) both failed before the fix and now succeed; reads of~/.aws/credentialsand/etc/passwdremain blocked.No NEWS.md entry here since the affected feature ships in rstudio-pro; release notes are tracked in the pro repository.
Fixes rstudio/rstudio-pro#11975.