Skip to content

atelet: constrain snapshot files to checkpoint directories - #1426

Closed
Du Bin (dubin555) wants to merge 2 commits into
agent-substrate:mainfrom
dubin555:contrib/snapshot-path-validation-public
Closed

Du Bin (dubin555) wants to merge 2 commits into
agent-substrate:mainfrom
dubin555:contrib/snapshot-path-validation-public

Conversation

@dubin555

@dubin555 Du Bin (dubin555) commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • validate snapshot file names from manifests and ateom checkpoint responses before using them as relative paths
  • confine checkpoint upload, local snapshot movement, local restore copies, and external restore writes with os.Root
  • pass already-open files to the compression helpers so path validation cannot be bypassed by reopening a symlink
  • preserve optional empty results for DATA checkpoints that do not contain runtime snapshot files

Testing

  • go test -race ./cmd/atelet ./cmd/atelet/internal/ategcs -count=1
  • focused symlink confinement tests repeated with the race detector
  • hack/verify-all.sh

@BenTheElder

Copy link
Copy Markdown
Collaborator

cc Zoe Zhao (@zoez7)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does this actually solve the problem? If an ateom is specifying invalid/evil paths, why wouldn't it just do something like checkpoint.img -> /var/run/secrets/kubernetes.io/serviceaccount/token

I think we need to be using os.Root like the rest of the defenses.

@EItanya

Copy link
Copy Markdown
Collaborator

Does this actually solve the problem? If an ateom is specifying invalid/evil paths, why wouldn't it just do something like checkpoint.img -> /var/run/secrets/kubernetes.io/serviceaccount/token

I think we need to be using os.Root like the rest of the defenses.

Agree with Ben, I think we can fairly easily add defensive tests for this.

@dubin555
Du Bin (dubin555) force-pushed the contrib/snapshot-path-validation-public branch from 1b91e32 to bc573db Compare September 8, 2026 15:02
@dubin555

Copy link
Copy Markdown
Contributor Author

Thanks, agreed. filepath.IsLocal only rejects lexical traversal and does not stop a symlink from escaping the checkpoint directory.

I updated the PR so the actual file operations are confined as well:

  • checkpoint uploads open source files through os.Root
  • external restores create destination files through os.Root
  • local restore copies use separate source and destination roots
  • local checkpoint moves stay within the Actor root
  • compression helpers now receive already-open files, so they cannot bypass the root by reopening a path

The lexical validation remains because the same names are also used to construct object-storage keys.

The new tests verify that an upload source symlink, an external restore destination symlink, and a local restore source symlink cannot access files outside their respective roots. The package race tests and the full verification suite pass.

@BenTheElder Benjamin Elder (BenTheElder) left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

AI found a few more things but I think they can be follow-ups.

Sorry for the delay, I've been catching up since being out a bit, this will need a rebase.

// validateSnapshotFiles rejects names that are not lexically local to a
// checkpoint directory. Actual file access must still use os.Root so symlinks
// cannot escape that directory.
func validateSnapshotFiles(files []string) error {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 should-fix 🟡 – manifest.json is still an accepted snapshot file name, and os.Root cannot help here: the collision is with a legitimate file in the same directory, not an escape from it.

If ateom reports snapshot_files ["checkpoint.img","manifest.json"], moveLocalCheckpoint renames it into the local snapshot dir and the root.WriteFile below truncates it with the marshaled atelet record. No error. A later LOCAL restore then hands ateom that JSON where its snapshot file should be, and the real file is gone.

Reject name == sandboxManifestName here.

// cannot escape that directory.
func validateSnapshotFiles(files []string) error {
for i, name := range files {
if !filepath.IsLocal(name) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 nit 🟢 – filepath.IsLocal is wider than what either ateom emits (both send os.ReadDir base names). It accepts ".", "a/..", and nested "a/b".

Less dangerous now that the sinks are rooted, but those names still fail on the external restore path with an error that carries no Reason, so it is retried forever, where "../x" crashes the actor. The module idiom is name == filepath.Base(name) && filepath.IsLocal(name), as in cmd/ateom-gvisor/internal/cdiinject/soname.go.

for i, name := range files {
if !filepath.IsLocal(name) {
return fmt.Errorf("snapshotFiles[%d] %q is not local to the checkpoint directory", i, name)
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 nit 🟢 – Names are neither cleaned nor de-duplicated, so "checkpoint.img" and "./checkpoint.img" both pass and resolve to the same file. goldenOnlyFiles compares raw strings, so it does not treat them as shadowing, and a DATA_ON_GOLDEN restore runs two concurrent O_TRUNC writes of different payloads into one file with g.Wait() returning nil. Rooting the opens does not prevent this.

filepath.Clean each name, reject duplicates after cleaning, and compare cleaned names in goldenOnlyFiles.

Comment thread cmd/atelet/main.go
return nil, ateerrors.NewGRPCError(ctx, codes.DataLoss, ateerrors.ReasonInvalidCheckpointResult, ateerrors.ActorCrashedMetadata(), errors.New("ateom reported no snapshot files for checkpoint"))
sandboxRec.SnapshotFiles, err = checkpointSnapshotFiles(resp, shouldHaveSnapshots(req))
if err != nil {
return nil, ateerrors.NewGRPCError(ctx, codes.DataLoss, ateerrors.ReasonInvalidCheckpointResult, ateerrors.ActorCrashedMetadata(), err)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 nit 🟢 – This failure return does not set op.failedPhase, unlike the ateom.CheckpointWorkload return just above it. recordPhases only tags the total and op.failedPhase, so the ateom_checkpoint phase sample is recorded as if it succeeded and per-phase dashboards cannot see that the ateom result was what failed.

Set op.failedPhase = ateattr.SnapshotPhaseAteomCheckpoint before returning.

Comment thread cmd/atelet/main_test.go
}
}

func TestCheckpointSnapshotFilesAllowsOptionalEmptyResult(t *testing.T) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🤖 nit 🟢 – This covers the required == false half. The len(files) == 0 && required DataLoss branch, and its mapping to codes.DataLoss + ReasonInvalidCheckpointResult + ActorCrashedMetadata, is still asserted by no test.

Dropping && required would let a FULL-scope checkpoint with no files upload as a valid empty snapshot, and the suite would stay green. A table over (files, required, wantErr) with rows {[], true, err}, {[], false, ok}, {["checkpoint.img"], true, ok}, {["../outside"], true, err} folds this and the neighbouring case into one.

@bowei Bowei Du (bowei) added kind/bug Something isn't working / bugfixes area/security Security related issue/pr area/node labels Sep 17, 2026
@dubin555
Du Bin (dubin555) force-pushed the contrib/snapshot-path-validation-public branch from bc573db to ec25985 Compare September 21, 2026 10:44
@dubin555

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I've rebased onto the latest main and resolved the conflicts.

If you agree, I can open an issue to track the remaining filename-validation and test-coverage suggestions, clarify the scope there, and follow up with an implementation.

Some of the suggestions seem reasonable, though the additional checks might be a little premature at this stage. For example, the current ateom implementations do not emit manifest.json as a checkpoint artifact under normal operation. I'd appreciate your view on whether reserving that name defensively is something we want to enforce now.

@BenTheElder

Copy link
Copy Markdown
Collaborator

Agreed, I should've spent more time reviewing the agent suggestions here. We've been hard pressed.

If you're in the CNCF slack, send me a ping next time you rebase so I can try to get this in ASAP.

Github notifications here are high noise : signal.

@BenTheElder

Copy link
Copy Markdown
Collaborator

merged via #1950 (rebased + additional fixes, retained attribution)

Benjamin Elder (BenTheElder) added a commit to BenTheElder/substrate that referenced this pull request Sep 28, 2026
Fixes agent-substrate#1426 

Rebases that PR and adjusts to changes in main since.
agent-substrate#1426 (comment)

Addresses outstanding review comments in additional commits.

I want to get this in M3. 

> It's a good idea to open an issue first for discussion.

- [x] Tests pass
- [x] Appropriate changes to documentation are included in the PR

---------

Co-authored-by: Du Bin <dubin555@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/node area/security Security related issue/pr kind/bug Something isn't working / bugfixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants