Skip to content

feat(execd): block pseudo-filesystems and internal platform paths on /files and /directories APIs - #3091

Closed
Pangjiping wants to merge 10 commits into
opensandbox-group:mainfrom
Pangjiping:feat/execd-fs-path-guard
Closed

Pangjiping wants to merge 10 commits into
opensandbox-group:mainfrom
Pangjiping:feat/execd-fs-path-guard

Conversation

@Pangjiping

@Pangjiping Pangjiping commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Closes #3086

Adds an unconditional pseudo-filesystem and internal platform-path guard across all execd /files/* and /directories/* HTTP APIs (including identity-scoped /v1/filesystem/:uid/:gid/* workers), updates the public specs/execd-api.yaml contract, docs, and generated Python/JS SDK clients:

  • Hard-blocked pseudo-filesystems & platform internal paths: On Linux/POSIX hosts, always blocks /proc, /sys, /dev, /sys/fs/cgroup, /var/lib/execd, /etc/execd, /etc/opensandbox, /opt/opensandbox, and /var/log/opensandbox; across all platforms (including Windows), blocks dynamic upper_root, EXECD_ISOLATION_CONFIG, EXECD_LIFECYCLE_CONFIG / default $HOME/.execd/lifecycle.toml, --lifecycle-startup-status-file, ebpf.audit_file, and operator-configured [filesystem] deny_paths / deny_globs, returning 403 Forbidden (FORBIDDEN_PATH) on direct access without leaking target contents.
  • Symlink-, magic-link-, and TOCTOU-safe enforcement:
    • Component-by-component symlink resolution preserves raw target segments (applying .. against the resolved directory rather than lexically collapsing <symlink>/..), handles dangling symlinks and relative chains, and fails closed past 40 hops.
    • On Unix, guarded opens and mutations (DownloadFile, ReplaceContent, UploadFile, DeleteFile, ChmodFile, RenameFile, MakeDir, RemoveDirs, GetFileInfo) walk directory descriptors with O_NOFOLLOW — using O_PATH for directory traversal and metadata operations on Linux (preserving non-root identity worker access through traverse-only 0733 dirs and chmod on owned 0200 files / FIFOs / sockets), openat2(RESOLVE_NO_MAGICLINKS | RESOLVE_NO_SYMLINKS) (with openat fallback), renameat2(RENAME_NOREPLACE), chunked ReadDir removal, and fail-closed fstatfs pseudo-filesystem magic checks with warning logs.
    • Recursive directory deletion (DELETE /directories) and rename (POST /files/mv) refuse / and any ancestor directory of a blocked root or glob-protected descendant.
  • Compatibility-preserving & fast root walks: GET /directories/list and GET /files/search perform zero-syscall lexical checks for ordinary entries, resolve only symlink-typed entries, and check fstatfs on directories to prune bind-mounted pseudo-filesystem aliases (filepath.SkipDir) instead of failing broad walks such as path=/.
  • Identity worker propagation: Propagates normalized absolute guard policy to --filesystem-worker over fd 4 so /v1/filesystem/:uid/:gid/* enforces the same rules as the parent daemon regardless of cwd.
  • Optional operator config (isolation.toml) & Windows normalization: Adds [filesystem] with deny_paths (validated as absolute non-root subtree prefixes) and deny_globs (doublestar patterns), with cleaned, separator- and case-normalized matching on Windows.
  • Public contract, docs & SDKs: Adds 403 Forbidden (FORBIDDEN_PATH) and behavior notes to all 22 filesystem operations in specs/execd-api.yaml, regenerates Python & JavaScript execd API clients, and documents the guard and [filesystem] config in docs/guides/privilege-reduction.md, docs/architecture/data-plane/execd.md, and components/execd/configs/isolation.example.toml.

Testing

  • Not run (explain why)
  • Unit tests
  • Integration tests
  • e2e / manual verification

Verified:

  • components/execd: go test -race ./pkg/web/... ., go test -run TestLoadConfigFilesystem ./pkg/isolation (including FIFO rejection, chmod on FIFO & 0200 files, nested-.. symlink targets, ancestor delete/rename for blocked roots and anchored globs, and concurrent symlink-swap TOCTOU tests for both reads and mutations)
  • GOOS=linux GOARCH=amd64 go test -c ./pkg/web/controller ./pkg/web
  • GOOS=linux GOARCH=amd64 go vet ./... & GOOS=windows GOARCH=amd64 go vet ./...
  • sdks/sandbox/python: uv run python scripts/generate_api.py && uv run ruff check && uv run pytest tests/
  • sdks/sandbox/javascript: pnpm run gen:api && pnpm run typecheck && pnpm run test (521/521)
  • docs: pnpm docs:build

Breaking Changes

  • None
  • Yes (describe impact and migration path)

Intentional security hardening on /files/*, /directories/*, and /v1/filesystem/{uid}/{gid}/*:

  • Direct requests to pseudo-filesystems (/proc, /sys, /dev, /sys/fs/cgroup), internal platform paths (/var/lib/execd, /etc/execd, /etc/opensandbox, /opt/opensandbox, /var/log/opensandbox, and configured runtime/config/audit paths), or special non-regular files (FIFOs, devices, sockets on download/upload/replace) now return 403 FORBIDDEN_PATH.
  • DELETE /directories and POST /files/mv refuse / and any ancestor directory of a blocked root or glob-protected descendant (including shared directories such as /tmp when a blocked runtime file like the lifecycle status file resides beneath it).
  • /directories/list and /files/search omit blocked subtrees and symlinks whose target resolves to a blocked path instead of failing broad walks.

Checklist

  • Linked Issue or clearly described motivation
  • Added/updated docs (if needed)
  • Added/updated tests (if needed)
  • Security impact considered
  • Backward compatibility considered

@github-actions github-actions Bot added component/execd size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Nov 24, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T03:47:20.528454Z 53495f4 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

Copy link
Copy Markdown

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: 87cb2d197f

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@Pangjiping Pangjiping left a comment

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.

Review notes for 87cb2d1, all findings as inline comments below.

The direct-access goal works: on the base commit GET /files/download?path=/proc/1/environ&offset=1 returns 200 (177 bytes) and /directories/list?path=/dev returns 200; both are 403 here. What remains is that the guard can be bypassed and the public contract is not synced yet.

Items marked reproduced were run against this commit in a Linux container (go1.26.11, kernel 6.12, root) and on macOS, with throwaway tests that are not part of this PR.

# Severity Where Issue Status
S1 High filesystem.go:253,257 symlink/.. deletes a blocked tree via DELETE /directories reproduced, HTTP 200
S2 High filesystem_upload.go:168,179,314 symlink/.. writes into a blocked directory via upload reproduced
S3 High filesystem_download.go:65,84, utils.go:40 check-then-use race serves blocked regular files reproduced, 1965–2051 of 30000 requests
S4 Medium filesystem_guard.go:141 relative deny_paths not enforced by the identity worker reproduced, 200 with contents
S7 Medium main.go:102 default lifecycle config path is not blocked code-verified
S5 Low filesystem.go:448 list / search are lexical-only reproduced, 237 entries via a procfs alias
S6 Low filesystem_guard.go:281 more than 40 symlink hops fails open Linux relies on ELOOP, no leak
F1 High model/error.go:27 403 not in the spec; docs and generated SDKs not updated verified
F2 High filesystem_guard.go:239, filesystem.go:586 gocognit 40 / 33 / 31 and mirror turn the lint job red reproduced with gocognit
F3 High filesystem_guard_test.go:403 syscall.Mkfifo breaks the Windows go vet reproduced
F4 Medium filesystem.go:372 per-entry full path walk slows search and list measured, 15.7x
F5 Medium filesystem_guard_linux.go:71 fallback and worker-propagation paths untested 0 coverage for the fallback
F6 Medium filesystem_guard.go:214 deny rules ineffective on Windows static and pure-function check
F7 Low filesystem_guard_linux.go:71 fstatfs error fails open, dead branches code-verified
F8 Low filesystem_guard_other.go:23 FIFO open still blocks on non-Linux pre-existing on the base commit

S1, S2 and F4 have one-line or small fixes that I checked locally: os.RemoveAll(absDir), returning absPath from resolveUploadTarget, and a lexical-first check in the walks. With those, S1 and S2 no longer reproduce and the search/list allocations return to base numbers.

The Linux-only cases that CI skipped because the lint step failed first (TestIsBlockedFSMagic, TestOpenGuardedReadFileRejectsProcDescriptor, TestFilesystemControllerRejectsFIFO, the identity tests) pass when run manually in a container, as do go test and go test -race for ./pkg/web/controller, ./pkg/web and the main package.

Comment thread components/execd/main.go Resolved
Comment thread components/execd/pkg/web/model/error.go Resolved
@Pangjiping
Pangjiping requested a review from jwx0925 as a code owner November 25, 2026 08:13
@github-actions github-actions Bot added documentation Improvements or additions to documentation sdk/js sdk/python size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Nov 25, 2026

@Pangjiping Pangjiping left a comment

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.

Round-2 verification of ca1247f. Thanks, this closes most of the first round. I re-ran the earlier reproductions and the PR tests at this commit on Linux (container, root, with -race) and on macOS.

Round-1 finding Status Re-verification
S1 fixed blocked tree survives symlink/.. on DELETE /directories
S2 partial reported shape fixed; a symlink-target .. shape is still open (N1)
S3 partial reads fixed: 0 of 30000 raced requests leaked (was 1965–2051); mutations still racy (N2)
S4 fixed identity route returns 403 for a relative deny path
S5 partial list and download on a procfs alias are 403; /files/info still returns metadata (N7)
S6 fixed a 45-hop chain returns 403
S7 fixed lifecycle.ResolveConfigPath()
F1 fixed 22/22 operations declare 403; Python and JS clients match generator output; pnpm docs:build passes
F2 fixed CI lint reports 0 issues; gocognit max 29
F3 fixed GOOS=windows go vet passes; Windows CI job green
F4 fixed allocations back to base; 1.03–1.57x time (was 15.7x)
F5 partial 6 tests added; no negative test for N1 / N2
F6 partial operator rules enforced on Windows; N3 / N4 remain
F7 fixed fstatfs fails closed; dead branches removed
F8 fixed FIFO returns 403 immediately on macOS

Still blocking: N1. Every path-based mutation can still be steered into a blocked root, deterministically, through a symlink whose target contains <symlink>/..: chmod 0777, mv the file out, delete, upload (create or overwrite), rmdir, mkdir. N2 is the same endpoints under a directory-swap race. Details are in the inline comments. N3 to N7 are low or informational.

@Pangjiping Pangjiping left a comment

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.

Addendum to the round-2 review above, after a tool-assisted pass over ca1247f. Two more findings, both checked at this commit on Linux and macOS:

  • N8 (High): the guard checks only the requested path. rmdir or mv of an ancestor of a blocked root is accepted and takes the blocked subtree along. Details are inline (delete on filesystem.go, rename on utils.go).
  • N9 (Low): perm is ignored by the Unix openGuardedWriteFile; no live bug today.

The other two points from that pass (the RemoveDirs race and the uncleaned Windows deny path) are already covered by N2 and N3.

@Pangjiping

Copy link
Copy Markdown
Collaborator Author

@codex review

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

Copy link
Copy Markdown

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: abff2b2c86

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@Pangjiping

Copy link
Copy Markdown
Collaborator Author

@codex review

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

Copy link
Copy Markdown

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: 31b04331e7

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@Pangjiping

Copy link
Copy Markdown
Collaborator Author

@codex review

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

Copy link
Copy Markdown

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: 53495f4f94

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +225 to +226
if err := checkFilesystemPath(absTarget); err != nil {
return newUploadError(http.StatusForbidden, model.ErrorCodePermissionDenied, err.Error())

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 Create upload staging files through a guarded parent

When a root daemon uploads to /workspace/slot/file and sandbox code flips slot from an allowed directory to /etc/execd after this check, the later path-based createUploadTemp follows the new symlink and writes request bytes into the blocked tree; flipping it back before commit also makes cleanup miss the random staging file, enabling persistent disk pollution. The fresh evidence after the guarded-open fix is that staging creation still never uses a pinned destination directory descriptor.

AGENTS.md reference: AGENTS.md:L46-L47

Useful? React with 👍 / 👎.

return err
}
cleaned := filepath.Clean(absPath)
if g.isRootOrBlockedAncestor(cleaned) || g.hasGlobBlockedDescendant(cleaned, checkAllGlobs) {

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 Make anchored-glob rename enforcement atomic

When an anchored deny_globs rule is configured and another process adds a matching credential after this path-based descendant scan, the subsequent descriptor-based directory rename never rechecks the tree and moves the credential to a destination where the anchored pattern no longer matches, making it available through the file API. Enforce the anchored rule against the pinned source atomically, or refuse such directory renames when that guarantee cannot be maintained.

AGENTS.md reference: AGENTS.md:L46-L47

Useful? React with 👍 / 👎.

Comment on lines +126 to +128
if canonical := canonicalizeExistingPrefix(cleaned); canonical != "" &&
canonical != filepath.Dir(canonical) {
appendNormalizedRoot(&roots, seen, canonical, windowsMode, caseInsensitive)

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 Export canonical roots to identity workers

When an extra blocked path contains a symlink beneath a directory that the selected filesystem UID cannot traverse, the privileged parent resolves and blocks the canonical target here, but CurrentFilesystemGuardPolicy exports only the lexical normalizedExtras; the reduced-identity worker cannot rediscover that canonical path and can access it directly when DAC otherwise permits. Include the parent's canonical extra roots in the propagated policy so identity-prefixed routes enforce the same guard.

AGENTS.md reference: AGENTS.md:L46-L47

Useful? React with 👍 / 👎.

Comment on lines +310 to +313
return nil, statErr, newUploadError(
http.StatusInternalServerError,
model.ErrorCodeRuntimeError,
fmt.Sprintf("error opening destination file %s. not a regular file", resolvedTarget),

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 Return forbidden for special upload destinations

When the upload destination already exists as a FIFO, socket, or device, this branch explicitly returns 500 RUNTIME_ERROR, even though the new public Forbidden response classifies special device/FIFO/socket nodes as 403 FORBIDDEN_PATH. Generated consumers therefore treat this policy denial as a server failure; map these special modes to the forbidden response while retaining the appropriate handling for directories.

AGENTS.md reference: AGENTS.md:L46-L47

Useful? React with 👍 / 👎.

Comment on lines +59 to +60
default:
return false

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 Block remaining pseudo-filesystem submounts

On Linux where a submount such as /sys/firmware/efi/efivars is bind-mounted below an allowed directory, fstatfs reports EFIVARFS_MAGIC, which falls through this switch and is not covered by the /dev device-ID check, so regular efivarfs entries can be served or mutated through the alias. The fresh evidence after the reported alias fix is that the new table still omits pseudo-filesystem types mounted beneath the blocked /sys and /dev trees.

AGENTS.md reference: AGENTS.md:L46-L47

Useful? React with 👍 / 👎.

@Pangjiping Pangjiping closed this Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/execd documentation Improvements or additions to documentation sdk/js sdk/python size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(execd): block pseudo-filesystems and internal platform paths on /files and /directories APIs

1 participant