Merge pull request #94243 from johanot/dockertools-fix-nixstore-perms
dockertools: fix buildLayeredImage nix-store permissions
This commit is contained in:
commit
c5a1eafc1b
@ -79,6 +79,16 @@ import ./make-test-python.nix ({ pkgs, ... }: {
|
|||||||
"docker rmi ${examples.nix.imageName}",
|
"docker rmi ${examples.nix.imageName}",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
with subtest(
|
||||||
|
"Ensure (layered) nix store has correct permissions "
|
||||||
|
"and that the container starts when its process does not have uid 0"
|
||||||
|
):
|
||||||
|
docker.succeed(
|
||||||
|
"docker load --input='${examples.bashLayeredWithUser}'",
|
||||||
|
"docker run -u somebody --rm ${examples.bashLayeredWithUser.imageName} ${pkgs.bash}/bin/bash -c 'test 555 == $(stat --format=%a /nix) && test 555 == $(stat --format=%a /nix/store)'",
|
||||||
|
"docker rmi ${examples.bashLayeredWithUser.imageName}",
|
||||||
|
)
|
||||||
|
|
||||||
with subtest("The nix binary symlinks are intact"):
|
with subtest("The nix binary symlinks are intact"):
|
||||||
docker.succeed(
|
docker.succeed(
|
||||||
"docker load --input='${examples.nix}'",
|
"docker load --input='${examples.nix}'",
|
||||||
|
@ -382,4 +382,40 @@ rec {
|
|||||||
contents = pkgs.bashInteractive;
|
contents = pkgs.bashInteractive;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# buildLayeredImage with non-root user
|
||||||
|
bashLayeredWithUser =
|
||||||
|
let
|
||||||
|
nonRootShadowSetup = { user, uid, gid ? uid }: with pkgs; [
|
||||||
|
(
|
||||||
|
writeTextDir "etc/shadow" ''
|
||||||
|
root:!x:::::::
|
||||||
|
${user}:!:::::::
|
||||||
|
''
|
||||||
|
)
|
||||||
|
(
|
||||||
|
writeTextDir "etc/passwd" ''
|
||||||
|
root:x:0:0::/root:${runtimeShell}
|
||||||
|
${user}:x:${toString uid}:${toString gid}::/home/${user}:
|
||||||
|
''
|
||||||
|
)
|
||||||
|
(
|
||||||
|
writeTextDir "etc/group" ''
|
||||||
|
root:x:0:
|
||||||
|
${user}:x:${toString gid}:
|
||||||
|
''
|
||||||
|
)
|
||||||
|
(
|
||||||
|
writeTextDir "etc/gshadow" ''
|
||||||
|
root:x::
|
||||||
|
${user}:x::
|
||||||
|
''
|
||||||
|
)
|
||||||
|
];
|
||||||
|
in
|
||||||
|
pkgs.dockerTools.buildLayeredImage {
|
||||||
|
name = "bash-layered-with-user";
|
||||||
|
tag = "latest";
|
||||||
|
contents = [ pkgs.bash pkgs.coreutils (nonRootShadowSetup { uid = 999; user = "somebody"; }) ];
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -74,6 +74,10 @@ def archive_paths_to(obj, paths, mtime, add_nix, filter=None):
|
|||||||
ti.gname = "root"
|
ti.gname = "root"
|
||||||
return filter(ti)
|
return filter(ti)
|
||||||
|
|
||||||
|
def nix_root(ti):
|
||||||
|
ti.mode = 0o0555 # r-xr-xr-x
|
||||||
|
return ti
|
||||||
|
|
||||||
def dir(path):
|
def dir(path):
|
||||||
ti = tarfile.TarInfo(path)
|
ti = tarfile.TarInfo(path)
|
||||||
ti.type = tarfile.DIRTYPE
|
ti.type = tarfile.DIRTYPE
|
||||||
@ -84,8 +88,8 @@ def archive_paths_to(obj, paths, mtime, add_nix, filter=None):
|
|||||||
# these directories first when building layer tarballs. But
|
# these directories first when building layer tarballs. But
|
||||||
# we don't need them on the customisation layer.
|
# we don't need them on the customisation layer.
|
||||||
if add_nix:
|
if add_nix:
|
||||||
tar.addfile(apply_filters(dir("/nix")))
|
tar.addfile(apply_filters(nix_root(dir("/nix"))))
|
||||||
tar.addfile(apply_filters(dir("/nix/store")))
|
tar.addfile(apply_filters(nix_root(dir("/nix/store"))))
|
||||||
|
|
||||||
for path in paths:
|
for path in paths:
|
||||||
path = pathlib.Path(path)
|
path = pathlib.Path(path)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user