Skip to content

Commit 76cba32

Browse files
authored
ocispec: make gVisor durable directory root mode 0777 (agent-substrate#3457)
Part of agent-substrate#3226. The API guide says a `durableDir` is created `0777`, like an emptyDir. On gVisor its root is `01777`. The volume is a tmpfs inside the sandbox, and its mount hint sets no mode, so it gets the tmpfs default. With the sticky bit, a user can't delete or rename another user's files in the volume's root. A durable dir created before this keeps `01777` when it is restored from a VOLUMES or ROOTFS snapshot, since the snapshot records its mode. Breaking Change: A gVisor actor whose template has a `durableDir` can't restore a MEMORY snapshot taken before this change. On a MEMORY restore, runsc checks that the sandbox spec's mount hints match the checkpoint, except `.source`. The new `dev.gvisor.spec.mount.<volume>.options` key doesn't match, so `runsc restore` fails and the actor goes to `CRASHED`. This includes MEMORY golden snapshots of these templates, and actors suspended while their worker rolls during the upgrade. No API restores such a snapshot without its memory. On upgrade: - Recreate affected templates so they take new golden snapshots. - Delete and recreate affected actors that hold a MEMORY snapshot from before the upgrade. A rollback breaks the same way. MEMORY snapshots taken after the upgrade fail to restore on the old worker. From v1.0.0, changes must keep upgrades and rollbacks working, so this has to land before then. AI use: AI-assisted, I reviewed and tested it. - [x] Tests pass - [ ] Docs updated Signed-off-by: Nayana Bidari <[email protected]>
1 parent 1b8f2e0 commit 76cba32

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

‎internal/ocispec/gvisor.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ func ShapeGVisor(spec *specs.Spec, o GVisorOptions) {
6363
spec.Annotations["dev.gvisor.spec.mount."+v+".type"] = "tmpfs"
6464
spec.Annotations["dev.gvisor.spec.mount."+v+".share"] = "container"
6565
spec.Annotations["dev.gvisor.spec.mount."+v+".source"] = filepath.Join(o.ActorDirs.GetDurableDirVolumeMountsDir(), v)
66+
// A tmpfs root is 01777 by default. Make it 0777, as Kubernetes
67+
// creates an emptyDir.
68+
spec.Annotations["dev.gvisor.spec.mount."+v+".options"] = "mode=0777"
6669
}
6770
} else {
6871
spec.Annotations["io.kubernetes.cri.container-type"] = "container"

‎internal/ocispec/parity_test.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ func TestShapeGVisor_Sandbox(t *testing.T) {
228228
if got, want := spec.Annotations["dev.gvisor.spec.mount.data.source"], "/node/actors/a/durable-dir/data"; got != want {
229229
t.Errorf("durable-dir mount source annotation = %q, want %q", got, want)
230230
}
231+
if got, want := spec.Annotations["dev.gvisor.spec.mount.data.options"], "mode=0777"; got != want {
232+
t.Errorf("durable-dir mount options annotation = %q, want %q", got, want)
233+
}
231234
}
232235

233236
// gVisor sizes the container's cgroup leaf from the actor-level limits: one

0 commit comments

Comments
 (0)