Skip to content

[codex] Parse path access modes in allowed paths#271

Draft
matt-dz wants to merge 4 commits into
mainfrom
codex/rshell-path-modes-poc
Draft

[codex] Parse path access modes in allowed paths#271
matt-dz wants to merge 4 commits into
mainfrom
codex/rshell-path-modes-poc

Conversation

@matt-dz
Copy link
Copy Markdown
Collaborator

@matt-dz matt-dz commented May 29, 2026

Summary

This POC refactors AllowedPaths to accept optional terminal path mode suffixes:

  • no suffix and :ro default to read-only
  • :rw is parsed and stored as read/write metadata for future write-aware actions
  • suffixes are stripped before path validation and before ALLOWED_PATHS/help-visible roots are exposed
  • overlapping roots resolve through the most specific configured path, so a narrower :ro can override a broader :rw

Current rshell write behavior remains unchanged: write-mode paths are parsed, but file opens with write flags are still denied.

Validation

  • make fmt
  • go test ./allowedpaths
  • go test ./analysis
  • go test ./interp
  • go test ./...

Notes

The commit was created unsigned in the Codex execution environment because dd-gitsign could not access an SSH agent (SSH_AUTH_SOCK was unset).

@datadog-prod-us1-3

This comment has been minimized.

Copy link
Copy Markdown
Collaborator Author

matt-dz commented May 29, 2026

@codex review

Please review this PR for correctness, security regressions around AllowedPaths path-mode parsing, most-specific root matching, write-surface preservation, cross-platform behavior, and missing test coverage.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 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".

Comment thread allowedpaths/path_mode.go Outdated
Comment on lines +25 to +26
if strings.HasSuffix(path, suffix.text) && len(path) > len(suffix.text) {
return path[:len(path)-len(suffix.text)], suffix.mode
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve literal paths ending in :rw/:ro

On POSIX filesystems : is a valid filename character, so this unconditionally treats an existing allowlist entry such as /srv/tenant:rw as the mode-suffixed path /srv/tenant. If /srv/tenant also exists, a configuration that previously confined the runner to the literal tenant:rw directory now silently widens the sandbox to its sibling/parent-named directory; if it does not exist, the intended directory is skipped. The mode parser needs an unambiguous opt-in/escape or validation path that does not reinterpret legacy literal path names.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 6fcaad31 by preserving existing literal paths that end in :ro or :rw as read-only paths. Mode parsing now only strips the suffix when the literal suffixed path is absent, so legacy POSIX directories like /srv/tenant:rw no longer widen to /srv/tenant.

Regression coverage:

  • TestResolveAllowedPathModePreservesExistingLiteralPath
  • TestAllowedPathModeDoesNotWidenExistingLiteralSuffixPath

Validation:

  • make fmt
  • go test ./allowedpaths
  • go test ./analysis
  • go test ./interp
  • go test ./...

Copy link
Copy Markdown
Collaborator Author

matt-dz commented May 29, 2026

@codex review

Pushed 6fcaad31 to address the literal :ro/:rw path compatibility finding. Existing suffixed literal paths are now preserved as read-only; suffix parsing only applies when the literal path is absent.

Validation:

  • make fmt
  • go test ./allowedpaths
  • go test ./analysis
  • go test ./interp
  • go test ./...

Copy link
Copy Markdown
Collaborator Author

matt-dz commented May 29, 2026

@codex review

Pushed 61e87e13 after the compatibility fix to skip the POSIX-only colon-literal regression tests on Windows. The production behavior is unchanged from 6fcaad31; this only avoids invalid Windows test directory names.

Validation:

  • make fmt
  • go test ./allowedpaths
  • go test ./analysis
  • go test ./interp
  • env GOTOOLCHAIN=local GOCACHE=/private/tmp/rshell-go-cache GOOS=windows GOARCH=amd64 go test -c ./allowedpaths -o /private/tmp/rshell-allowedpaths-windows.test.exe
  • go test ./...

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 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".

Comment thread allowedpaths/sandbox.go Outdated
Comment on lines +102 to +103
if _, err := os.Lstat(path); err == nil || !errors.Is(err, os.ErrNotExist) {
return path, pathModeReadOnly
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Treat invalid Windows literal probes as suffixes

On Windows, an allowed path like C:\data:rw probes the unsuffixed-looking literal first, but a colon after the final component is not a valid directory name and can make os.Lstat(path) return an invalid-name error rather than os.ErrNotExist. Because this branch preserves the path for any non-ErrNotExist error, AllowedPaths([]string{dir + ":rw"}) keeps the :rw suffix, OpenRoot then skips it, and the documented :ro/:rw syntax does not work for normal Windows directories. This should strip the suffix for Windows invalid-name literal probes while still preserving real POSIX literals.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 6cf4c4dc by making allowed-path mode resolution platform-specific. Non-Windows builds keep the literal-path preservation check for existing :ro/:rw paths, while Windows builds strip terminal mode suffixes directly so normal Windows directories like C:\data:rw parse as C:\data with rw mode instead of being skipped.

Regression coverage:

  • TestResolveAllowedPathModeStripsWindowsSuffix
  • Existing POSIX literal preservation tests remain on non-Windows

Validation:

  • make fmt
  • go test ./allowedpaths
  • go test ./analysis
  • go test ./interp
  • env GOTOOLCHAIN=local GOCACHE=/private/tmp/rshell-go-cache GOOS=windows GOARCH=amd64 go test -c ./allowedpaths -o /private/tmp/rshell-allowedpaths-windows.test.exe
  • go test ./...

Copy link
Copy Markdown
Collaborator Author

matt-dz commented May 29, 2026

@codex review

Pushed 6cf4c4dc to address the Windows path-mode suffix finding. Path-mode resolution is now split by platform: POSIX/non-Windows preserves existing literal suffixed paths, while Windows strips terminal :ro/:rw suffixes directly and has a Windows-only regression test for that behavior.

Validation:

  • make fmt
  • go test ./allowedpaths
  • go test ./analysis
  • go test ./interp
  • env GOTOOLCHAIN=local GOCACHE=/private/tmp/rshell-go-cache GOOS=windows GOARCH=amd64 go test -c ./allowedpaths -o /private/tmp/rshell-allowedpaths-windows.test.exe
  • go test ./...

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

ℹ️ 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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant