Repository navigation
fix(filer): don't follow symlinks in outputs - #124
Conversation
The outputs filer fails an output whose path goes through a symbolic link or has a '..' component, or a directory output with a link anywhere below it, for every protocol (HTTP, FTP, S3, file:), and logs why. Upload files are opened with O_NOFOLLOW (S3 now uploads from the open file), and the outputs filer mounts the task's paths read-only. Directory entries skip the check that their directory covers. Docs: filer and upgrade guide. Closes #114 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideData structuresAdd shared helpers to detect links and unsafe path components and open upload files without following symlinks.
APIMake transput uploads reject unsafe outputs by default while allowing directory-entry callers to skip redundant checks.
Uses of the APIApply safe opening and link checks across HTTP, FTP, S3, and file outputs, including glob matches, and handle inaccessible uploads cleanly.
ConfigurationCopy task volume mounts before mutation and make them read-only only for the outputs filer.
DocumentationDocument output symlink restrictions and the required executor upgrade behavior.
TestsCover symlink detection, safe opens, protocol behavior, glob matches, and read-only output mounts.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #124 +/- ##
==========================================
+ Coverage 94.62% 95.15% +0.52%
==========================================
Files 10 10
Lines 1377 1424 +47
==========================================
+ Hits 1303 1355 +52
+ Misses 74 69 -5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
CodeQL took the fixture's sample credentials for stored secrets. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/tesk_core/transput.py" line_range="269" />
<code_context>
self.ftype,
url_for_log(self.url),
)
+ if check_links and output_has_symlink(
+ self.path, recursive=self.ftype == Type.Directory
+ ):
</code_context>
<issue_to_address>
**Symlink replacements escape output paths**
When another process can modify the shared task volume after validation and before a path or glob match is opened or copied, `Transput.upload` uses paths after `output_has_symlink` checks them, but `open_for_upload` protects only the final component, and `file:` copies re-expand globs and follow links. A replaced ancestor or directory entry therefore lets the filer read or upload data outside the intended task paths.
Use a race-safe traversal and transfer strategy that prevents or detects symlink replacement for every path component and glob match.
Also at `src/tesk_core/transput.py:191`, `src/tesk_core/filer.py:231`, `src/tesk_core/filer.py:369-371`, `src/tesk_core/filer.py:474`, `src/tesk_core/filer_s3.py:188`.
</issue_to_address>
### Comment 2
<location path="src/tesk_core/filer.py" line_range="199" />
<code_context>
# because requests sends an empty file object with chunked encoding,
# which presigned upload URLs such as S3's reject.
- with open(self.path, "rb") as file:
+ with open_for_upload(self.path) as file:
data = file if os.fstat(file.fileno()).st_size > 0 else b""
try:
</code_context>
<issue_to_address>
**Upload open errors escape filer**
When a file open fails in the HTTP or FTP upload path, including when `O_NOFOLLOW` rejects a link introduced after validation, `open_for_upload` raises `OSError`, but the HTTP and FTP upload paths do not convert it to a failed-output result; `process_file` catches only `InvalidURL`, so the exception escapes and aborts output processing instead of reporting the affected output as failed.
Catch `OSError` in the HTTP and FTP upload paths, log the output failure, and return 1 consistently with S3.
Also at `src/tesk_core/filer.py:891`.
</issue_to_address>Linked issues
#114 fix(filer): do not follow symbolic links in outputs · 6 of 6 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Refuse symbolic links in output paths and directory contents, and open upload files with O_NOFOLLOW. | ✅ Met | The shared output check examines path components and walks directories without following links; HTTP, FTP, and S3 use open_for_upload. |
| 2 | For file: outputs, copy links as links or refuse them. | ✅ Met | FileTransput rejects linked output paths and checks each glob match before copying. |
| 3 | Apply the link handling to HTTP, S3, FTP, and file: outputs. | ✅ Met | All four output implementations use the shared output check. |
| 4 | Mount the task volume read-only in the outputs filer where possible. | ✅ Met | Filer.get_spec sets readOnly on task-volume mounts for outputs and removes it for inputs; the claim mounts are copied first. |
| 5 | Add regression tests for symlinked file and directory outputs over HTTP, S3, FTP, and file:. | ✅ Met | The new tests cover linked files, linked directories, links below directories, and each protocol. |
| 6 | Document output-link handling in the filer and upgrading docs. | ✅ Met | Both docs/filer.md and docs/upgrading.md describe the behavior. |
Sourcery assessment
Approval pending. 2 findings to address first.
Blocking findings: src/tesk_core/transput.py:269, src/tesk_core/filer.py:199
HTTP and FTP uploads log an output that can't be opened (e.g. a symbolic link refused by O_NOFOLLOW, or a missing file) and fail it with 1, as S3 uploads do, instead of raising; FTP uploads also fail an output whose read or connection fails. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
The outputs filer no longer follows symbolic links in outputs:
..component, or, for a directory, if any entry below it is a link. This holds for HTTP, FTP, S3 andfile:outputs; forfile:outputs with a glob, every match is checked.O_NOFOLLOW(open_for_upload); S3 now uploads from the open file (upload_fileobj). FTP uploads open the file read-only (wasr+b).readOnlyon the task volume's mounts inFiler.get_spec("outputs")); the filer copies the claim's mounts, so the executors' mounts are unchanged.OSError). This also covers ther+b/OSErroritem of fix(filer): harden downloads, uploads and copies #120.docs/filer.md, entry indocs/upgrading.md.Closes #114
Verification
.venv/bin/pytest -q -p no:cacheprovider: 532 passed (newtests/unit/test_filer_symlinks.py: links to files and directories, links in parent components,..after a link, links below directories, a link to/proc/self/environ, glob matches, and theO_NOFOLLOWopen with the check stubbed out, per protocol; regular outputs still upload).ruff check .,ruff format --check .,mypy: clean.mkdocs build --strict: clean.pre-commit run --all-files: passed, exceptgitleaksandactionlint, which were skipped locally (their Go toolchain download fails in the sandbox); CI runs them.Lane
Full review (adversarial + quality reviewers, two rounds).
Declined review findings
task-volumename intaskmaster.pytoo (low):taskmaster.pyis being changed in parallel by another PR; left for a follow-up./var/run): with fix(filer): mount task paths under a fixed prefix #115, task paths are mounted below a fixed prefix without links, so the case disappears.FILEoutput path blocks the open (low, round 2): unchanged from before (the oldopenblocked too) and affects only the task's own filer, which the pod timeout ends.openatper component): declined in its thread, as no executor runs while the outputs filer does.Open questions
None.
🤖 Generated with Claude Code
Summary by Sourcery
Prevent the outputs filer from following symbolic links and safely reject unsafe output paths across all supported protocols.
Bug Fixes:
..components.Enhancements:
Documentation:
Tests: