guest: use OCIBundlePath as sandbox root source of truth#2653
guest: use OCIBundlePath as sandbox root source of truth#2653shreyanshjain7174 wants to merge 1 commit intomicrosoft:mainfrom
Conversation
bbc4d4d to
7deb168
Compare
a67564e to
9de87ec
Compare
rawahars
left a comment
There was a problem hiding this comment.
Overall love the simplification of the virtual pod vs normal pod differentiation.
Major comments are regarding keeping existing utility methods, while removing virtual pod specific ones and then changing these methods to return paths/values which you are creating on the fly. That would make it easier to review too.
|
@anmaxvl Can you please take a look too to see if any invariant of Security Policy gets impacted with this change. As I see it that should not change but please do confirm that. |
|
@micromaomao as well. |
I will have a closer look tomorrow, but I think this is probably good because #2581 added validation to |
c7fcebd to
e1f8a6f
Compare
|
@rawahars Addressed all 8 review comments. Also added Do you think this script is worth keeping in the repo for manual validation, or should it go in a separate PR / be dropped from this one? |
rawahars
left a comment
There was a problem hiding this comment.
Major driving comment are that for the current change, try to align as close to original code structure as possible.
e1f8a6f to
0fb9f0b
Compare
|
Thanks for the detailed round 2 review. Pushed an update addressing all the comments:
All tests pass locally (unit + E2E via crictl). |
08c0b9e to
7c4f900
Compare
helsaawy
left a comment
There was a problem hiding this comment.
Can we switch entirely to the *FromRoot functions and delete the [VirtualPodAware]*MountsDir/Source functions in internal/guest/spec?
| func updateSandboxMounts(sandboxRoot string, spec *oci.Spec) error { | ||
| mountsDir := specGuest.SandboxMountsDirFromRoot(sandboxRoot) | ||
| tmpfsMountsDir := specGuest.SandboxTmpfsMountsDirFromRoot(sandboxRoot) | ||
|
|
There was a problem hiding this comment.
Might be worthwhile to add Sandbox[Tmpfs]MountsSourceFromRoot or something similar.
There was a problem hiding this comment.
Added SandboxMountSourceFromRoot, SandboxTmpfsMountSourceFromRoot, and HugePagesMountSourceFromRoot to spec.go. The updateSandboxMounts and updateHugePageMounts functions in workload_container.go now use these instead of inline filepath.Join + TrimPrefix.
7c4f900 to
003e8b3
Compare
Replace heuristic sandbox path derivation (hard-coded /run/gcs/c prefix + ID) with host-provided OCIBundlePath as the canonical sandbox root directory. This change prepares the guest-side GCS for Shim v2 and multi-pod UVM support, where the host may use a different path layout than the legacy /run/gcs/c/<id>. Key changes: - Add sandboxRoots mapping on Host to store resolved sandbox root per sandbox ID - Sandbox containers: register OCIBundlePath as sandbox root - Virtual pods: derive sandbox root from OCIBundlePath parent + /virtual-pods/<id> - Workload containers: resolve sandbox root from Host mapping (fallback to legacy) - Standalone containers: use OCIBundlePath directly as root - Container.Delete: use stored sandboxRoot for cleanup paths - Remove duplicate setup functions (setupVirtualPod* merged into unified setup*) The refactor produces identical paths when the old shim sends OCIBundlePath in the legacy format, ensuring zero behavior change for existing deployments. Security: virtualPodID is validated against path traversal before use. Signed-off-by: Shreyansh Sancheti <shsancheti@microsoft.com>
003e8b3 to
c73b7f3
Compare
| } | ||
|
|
||
| // remove user mounts in sandbox container - use virtual pod aware paths | ||
| if err := storage.UnmountAllInPath(ctx, specGuest.VirtualPodAwareSandboxMountsDir(c.id, virtualSandboxID), true); err != nil { |
There was a problem hiding this comment.
Are we planning on removing VirtualPodAwareSandboxMountsDir and other utility methods in next PR?
There was a problem hiding this comment.
Yes, the follow-up PR (guest-pod-unification branch) removes VirtualPodAwareSandboxMountsDir and the other VirtualPod* methods as part of the unified pod model.
| // Set cgroup path | ||
| virtualSandboxID := spec.Annotations[annotations.VirtualPodID] | ||
| if virtualSandboxID != "" { | ||
| // Standalone container in virtual pod goes under /containers/virtual-pods/{virtualSandboxID}/{containerID} |
There was a problem hiding this comment.
nit: Consider adding this comment in next PR when you do the refactoring.
There was a problem hiding this comment.
Will add in the follow-up.
| // sandboxRoots maps sandboxID to the resolved sandbox root directory. | ||
| // Populated via RegisterSandboxRoot during sandbox creation using | ||
| // the host-provided OCIBundlePath as source of truth. | ||
| sandboxRootsMutex sync.RWMutex |
There was a problem hiding this comment.
nit: Why not just use the containersMutex? If sandboxRoots is always used under containersMutex then you can skip sandboxRootsMutex.
There was a problem hiding this comment.
Good point — sandboxRoots is only accessed within CreateContainer and RemoveContainer which both hold containersMutex. I'll consolidate to use containersMutex only in the follow-up to keep this PR minimal.
Guest-side GCS currently derives sandbox paths by combining a hard-coded prefix (/run/gcs/c) with the sandbox ID, ignoring the OCIBundlePath the host already sends. This breaks with Shim v2 path layouts and multi-pod UVMs.
This PR stores settings.OCIBundlePath as the canonical sandbox root on the Host struct (sandboxRoots map), and threads the resolved root through all setup and cleanup functions instead of re-deriving it.
For virtual pods, the sandbox root is derived from OCIBundlePath's parent directory (preserving the virtual-pods/ layout). For workload containers, it's looked up from the mapping. A legacy fallback ensures backwards compatibility with shim v1.
When the old shim sends OCIBundlePath in the legacy format, all paths are identical to before — verified by parity tests and a full CRI lifecycle (crictl runp/create/start/stop/rm) on a Hyper-V UVM.
Depends on: #2655 (bug fix for leaked LCOW resources) — both PRs modify uvm.go cleanup paths. Will rebase after #2655 merges.