Skip to content

Commit ac227fe

Browse files
committed
fix(runtime): initialize mapped user namespace
1 parent c318688 commit ac227fe

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

‎scripts/contained-rootless-spec.mjs‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,11 +1561,19 @@ export function sanitizeContainedRootlessSpec({
15611561
}
15621562
// The repository may live on a filesystem that cannot persist POSIX mode
15631563
// changes. Map the fixed non-root container identity to the already-rootless
1564-
// runtime owner so read-only bind inputs remain readable without granting an
1565-
// inner UID 0 mapping or widening their host permissions.
1564+
// runtime owner so read-only bind inputs remain readable without widening
1565+
// their host permissions. Runc also requires container ID 0 to be mapped to
1566+
// initialize the namespace; keep that ID isolated on the outer subordinate
1567+
// identity while the executed process remains the fixed non-root image user.
15661568
linux.namespaces.push({ type: "user" });
1567-
linux.uidMappings = [{ containerID: runtimeUser.uid, hostID: 0, size: 1 }];
1568-
linux.gidMappings = [{ containerID: runtimeUser.gid, hostID: 0, size: 1 }];
1569+
linux.uidMappings = [
1570+
{ containerID: 0, hostID: 1, size: 1 },
1571+
{ containerID: runtimeUser.uid, hostID: 0, size: 1 },
1572+
];
1573+
linux.gidMappings = [
1574+
{ containerID: 0, hostID: 1, size: 1 },
1575+
{ containerID: runtimeUser.gid, hostID: 0, size: 1 },
1576+
];
15691577
// RootlessKit delegates the cgroup namespace root. Use an absolute leaf so
15701578
// runc and the independent observer resolve the same cgroup regardless of
15711579
// whether the runtime coordinator itself was evacuated to /containerd.

‎scripts/contained-runtime.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,9 +1938,11 @@ describe("contained runtime command policy", () => {
19381938
expect(sanitized.linux.cgroupsPath).not.toContain("/containerd/");
19391939
expect(sanitized.linux.namespaces).toContainEqual({ type: "user" });
19401940
expect(sanitized.linux.uidMappings).toEqual([
1941+
{ containerID: 0, hostID: 1, size: 1 },
19411942
{ containerID: fixture.authority.process.uid, hostID: 0, size: 1 },
19421943
]);
19431944
expect(sanitized.linux.gidMappings).toEqual([
1945+
{ containerID: 0, hostID: 1, size: 1 },
19441946
{ containerID: fixture.authority.process.gid, hostID: 0, size: 1 },
19451947
]);
19461948
expect(sanitized.linux.resources).toEqual(original.linux.resources);

0 commit comments

Comments
 (0)