Enforce AllowedPaths read/write modes#271
Conversation
|
|
@codex review Please review this PR for correctness, security regressions around |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e0fd9d8702
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Pushed Validation:
|
|
@codex review Pushed Validation:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 61e87e1375
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Pushed Validation:
|
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
6cf4c4d to
819c858
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6cfa761ad9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Pushed Validation:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2abf43382b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Pushed Validation:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3f733b9d6d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Pushed Validation:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 17902805f8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Pushed Validation:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d0ca37c562
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Pushed Validation:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 95293912e4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review Pushed Validation:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bd3174badf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
julesmcrt
left a comment
There was a problem hiding this comment.
Few nits, overall LGTM
| // AllowedPaths restricts file and directory access to the specified directories. | ||
| // Paths must be absolute directories that exist. When set, only files within | ||
| // these directories can be opened (for reading or writing), read, or executed. | ||
| // Paths must be absolute directories that exist. A path may end with :ro or :rw |
There was a problem hiding this comment.
CLI --allowed-paths help text not updated for :ro/:rw suffixes
go run ./cmd/rshell --help outputs:
...
-p, --allowed-paths string comma-separated list of directories the shell is allowed to access
...
❓ Should we make the suffix appear here?
See cmd/rshell/main.go:142,147
|
|
||
| package allowedpaths | ||
|
|
||
| func resolveAllowedPathMode(path string) (string, pathMode) { |
There was a problem hiding this comment.
Not a blocker as we don't plan on supporting Windows for now.
❓ Should we add a comment documenting that ADS-style suffixes are intentionally treated as mode suffixes on Windows, so the divergence from the Unix literal-preservation behavior is explicit.
A path like C:\data\file:rw is ambiguous with an NTFS Alternate Data Stream (file:rw), so the Windows code strips unconditionally.
However the Unix resolveAllowedPathMode carefully preserves a literal path that genuinely ends in :ro/:rw (via os.Lstat), so a real directory named tenant:rw is never silently reinterpreted as a mode.
| "os.Getuid", // 🟠 returns the numeric user id of the caller; read-only syscall. | ||
| "os.O_APPEND", // 🟢 append-on-write file flag constant; pure constant. Part of the sandbox open-flag allowlist. | ||
| "os.O_CREATE", // 🟢 create-if-missing file flag constant; pure constant. Part of the sandbox open-flag allowlist. | ||
| "os.Lstat", // 🟠 checks whether a literal AllowedPaths entry exists without following symlinks, preserving legacy paths that end in :ro/:rw. |
There was a problem hiding this comment.
Shouldn't we preserve alphabetical order here?
Summary
This updates
AllowedPathsto support and enforce optional terminal path mode suffixes::roconfigure a read-only root:rwconfigures a root that may be written when the sandbox is placed in writable/remediation mode:rooverrides a broader:rw:roor:rware preserved when the literal path exists; Windows strips terminal mode suffixes directlyThe write path now enforces those modes for both
OpenandTruncate. Write targets are checked after symlink/canonical resolution, Unix write opens use a no-followopenatwalk, Windows uses Go no-reparseos.Root.OpenFile, and canonical symlink roots are verified against the already-opened root handle before they are used for write authorization.Only the supported platform implementations are kept: Linux/macOS use the Unix
openatimplementation, and Windows uses the Windowsos.Rootimplementation. There is no generic unsupported-platform write opener.Validation
make fmtgo test ./allowedpaths ./analysisgo test ./interp ./builtins/tests/truncate ./testsgo test ./...RSHELL_BASH_TEST=1 go test ./tests/ -run TestShellScenariosAgainstBash -timeout 120senv GOTOOLCHAIN=local GOCACHE=/private/tmp/rshell-go-cache GOOS=windows GOARCH=amd64 go test -c ./allowedpaths -o /private/tmp/rshell-allowedpaths-windows.test.exegit diff --checkNotes
The commit was created unsigned in the Codex execution environment because
dd-gitsigncould not access an SSH agent (SSH_AUTH_SOCKwas unset).