Skip to content

fix(harness): keep workspace file permissions when projecting and materializing - #4276

Merged
jujn merged 3 commits into
agentscope-ai:mainfrom
ningmao-hlyz:fix/projection-file-mode
Nov 20, 2026
Merged

jujn merged 3 commits into
agentscope-ai:mainfrom
ningmao-hlyz:fix/projection-file-mode

Conversation

@ningmao-hlyz

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.1.0-SNAPSHOT

Description

Fixes #4275.

Workspace files lost their POSIX permissions on the way into the sandbox: a script that is 0755 on the host arrived 0644, and running it from the workspace failed with Permission denied. Two paths materialize host files and both dropped the mode.

Projection tar. WorkspaceProjectionApplier builds the payload the backend extracts with tar -xf, so the entry mode is exactly what the file ends up with, but every entry was created with new TarArchiveEntry(rel) and never called setMode. Entries now carry the source file's nine permission bits, and the mode participates in the projection hash, so a chmod that leaves the bytes alone re-projects instead of being skipped.

Direct materialization. WorkspaceSpecApplier copied LocalFileEntry/LocalDirEntry bytes with Files.copy and no attributes, which creates the target with the platform default permissions. It now inherits the source mode.

Both go through one package-private helper, TarFileModes (modeOf/applyTo), which WorkspaceArchiveExtractor uses as well, so every path that puts a host file into a workspace agrees on one rule:

  • inherit the source's nine permission bits;
  • fall back to 0644 where the host filesystem cannot express POSIX permissions (Windows), or when the source vanished between the read and the stat;
  • leave inline FileEntry content at the platform default — it has no source to inherit from;
  • keep directories at the platform default: inheriting a 0555 directory would reject the files copied into it here and on the next materialization.

Setuid/setgid/sticky bits are dropped, so a projected file cannot gain privilege in the sandbox. Symlinked files are still materialized and symlinked include roots are still skipped; the change is limited to the permission bits.

Out of scope, deliberately: uploads. SandboxBackedFilesystem's archive and DockerSandbox's docker-cp path write content at 0644 by existing contract ("uploads must stay readable when the container runs as a non-root user") and carry no source path to inherit from. Editing an executable through those paths still resets it to 0644; that is a separate concern from materialization and is called out in #4275 rather than silently changed here.

How to test

  • TarFileModesTest: bit packing/unpacking, inheritance, non-POSIX fallback, and the mode 0 = "not recorded" protection.
  • WorkspaceProjectionApplierTest: the tar entry carries 0755, and the payload hash changes when only the mode changes.
  • WorkspaceSpecApplierTest (new): LocalFileEntry/LocalDirEntry keep 0755, a data file in the same tree stays non-executable, inline content stays at the default.

mvn -pl agentscope-harness test on a Windows host: 1852 tests, 0 failures, 47 skipped. The POSIX assertions are guarded by assumeTrue because a Windows host has no POSIX attribute view, so the permission assertions only execute on Linux CI — that is the part the ubuntu runners need to confirm end to end.

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test)
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated (e.g. links, examples, etc.) — no user-facing doc describes workspace file permissions, so nothing needed updating
  • Code is ready for review

…erializing

Workspace files lost their POSIX permissions on the way into the sandbox, so a
script that is executable on the host arrived 0644 and `./run.sh` failed with
"Permission denied".

Two paths materialize host files into a workspace and both dropped the mode:

- The projection payload is a tar archive the backend extracts with `tar -xf`,
  but every entry was created without a mode, so the container wrote the tar
  default for files that are 0755 on the host.
- WorkspaceSpecApplier copied LocalFileEntry/LocalDirEntry bytes with
  Files.copy and no attributes, so the target was created with the platform
  default permissions.

Both now inherit the source's nine permission bits through one shared helper
(TarFileModes.modeOf/applyTo), which the reference extractor uses as well, so
every path that puts a host file into a workspace agrees. Entries whose host
filesystem cannot express POSIX permissions (the Windows host) keep 0644, and
inline FileEntry content, which has no source to inherit from, keeps the
platform default.

The projection hash now covers the mode, so a chmod that leaves the bytes alone
re-projects instead of being skipped, and the reference extractor restores the
mode the way tar does. Directory entries stay at the platform default on
purpose: inheriting a 0555 directory would reject the files copied into it here
and on the next materialization. Symlinked files are still materialized and
symlinked include roots are still skipped; this change is limited to the
permission bits.

Uploads keep writing content at 0644: SandboxBackedFilesystem's archive and
DockerSandbox's docker-cp path carry no source path to inherit from, and the
0644 default is their documented contract.
@ningmao-hlyz

Copy link
Copy Markdown
Contributor Author

CI note for review: mvn clean verify passed on both ubuntu-latest (10m6s) and windows-latest (11m55s).

On Windows the three permission assertions are skipped by assumeTrue — that host has no POSIX attribute view, so there is nothing to assert. The ubuntu run is the one that exercises them: TarFileModesTest.modeOf_readsTheSourcePermissions, applyTo_setsTheRecordedMode, applyTo_leavesTheTargetAloneWhenNoModeWasRecorded, plus WorkspaceSpecApplierTest (local file and directory tree keeping 0755) and the two projection assertions (build_keepsTheExecutableBitOnProjectedFiles, build_hashChangesWhenOnlyTheModeChanges).

@jujn

jujn commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

感谢贡献,如果对项目感兴趣,可以加仓库首页钉钉群搜我 id jujn,我们有内部交流群

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.

[Bug]: Sandbox workspace projection drops the executable bit

2 participants