Repository navigation
atelet: constrain snapshot files to checkpoint directories - #1426
Du Bin (dubin555) wants to merge 2 commits into
Conversation
Benjamin Elder (BenTheElder)
left a comment
There was a problem hiding this comment.
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. |
1b91e32 to
bc573db
Compare
|
Thanks, agreed. I updated the PR so the actual file operations are confined as well:
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. |
| // 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 { |
There was a problem hiding this comment.
🤖 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) { |
There was a problem hiding this comment.
🤖 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) | ||
| } |
There was a problem hiding this comment.
🤖 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.
| 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) |
There was a problem hiding this comment.
🤖 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.
| } | ||
| } | ||
|
|
||
| func TestCheckpointSnapshotFilesAllowsOptionalEmptyResult(t *testing.T) { |
There was a problem hiding this comment.
🤖 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.
bc573db to
ec25985
Compare
|
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 |
|
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. |
|
merged via #1950 (rebased + additional fixes, retained attribution) |
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>
Summary
os.RootTesting
go test -race ./cmd/atelet ./cmd/atelet/internal/ategcs -count=1hack/verify-all.sh