Repository navigation
fix(harness): keep workspace file permissions when projecting and materializing - #4276
Merged
Merged
Conversation
…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.
Contributor
Author
|
CI note for review: On Windows the three permission assertions are skipped by |
jujn
approved these changes
Nov 20, 2026
Collaborator
|
感谢贡献,如果对项目感兴趣,可以加仓库首页钉钉群搜我 id jujn,我们有内部交流群 |
This was referenced Nov 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
0755on the host arrived0644, and running it from the workspace failed withPermission denied. Two paths materialize host files and both dropped the mode.Projection tar.
WorkspaceProjectionApplierbuilds the payload the backend extracts withtar -xf, so the entry mode is exactly what the file ends up with, but every entry was created withnew TarArchiveEntry(rel)and never calledsetMode. Entries now carry the source file's nine permission bits, and the mode participates in the projection hash, so achmodthat leaves the bytes alone re-projects instead of being skipped.Direct materialization.
WorkspaceSpecAppliercopiedLocalFileEntry/LocalDirEntrybytes withFiles.copyand 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), whichWorkspaceArchiveExtractoruses as well, so every path that puts a host file into a workspace agrees on one rule:0644where the host filesystem cannot express POSIX permissions (Windows), or when the source vanished between the read and the stat;FileEntrycontent at the platform default — it has no source to inherit from;0555directory 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 andDockerSandbox's docker-cp path write content at0644by 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 to0644; 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 themode 0= "not recorded" protection.WorkspaceProjectionApplierTest: the tar entry carries0755, and the payload hash changes when only the mode changes.WorkspaceSpecApplierTest(new):LocalFileEntry/LocalDirEntrykeep0755, a data file in the same tree stays non-executable, inline content stays at the default.mvn -pl agentscope-harness teston a Windows host: 1852 tests, 0 failures, 47 skipped. The POSIX assertions are guarded byassumeTruebecause 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
mvn spotless:applymvn test)