Skip to content

Commit dedee27

Browse files
committed
fix!: oci perms
existing users of config.copyToRoot quite likely need to hove the contents of this key to setup = []; - config.copyToRoot may prime the nix2container permission cache with a parent folder (e.g. /bin) and conflicting permissions'
1 parent 8f4f22d commit dedee27

File tree

3 files changed

+32
-35
lines changed

3 files changed

+32
-35
lines changed

src/lib/ops/mkOCI.nix

+22-18
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ in
3232
then l.head meta.tags
3333
else null,
3434
setup ? [],
35+
extraSetupLinks ? "",
3536
layers ? [],
3637
runtimeInputs ? [],
3738
uid ? "65534",
@@ -45,8 +46,20 @@ in
4546
setupLinks = cell.ops.mkSetup "links" [] ''
4647
mkdir -p $out/bin
4748
ln -s ${l.getExe entrypoint} $out/bin/entrypoint
49+
${extraSetupLinks}
4850
'';
4951

52+
root = nixpkgs.buildEnv {
53+
name = "root";
54+
paths =
55+
setup
56+
++ [
57+
# trick `buildEnv` and prevent the $out`/bin` to be a symlink
58+
(nixpkgs.runCommand "setupDirs" {} "mkdir -p $out/bin")
59+
setupLinks
60+
];
61+
};
62+
5063
image =
5164
l.throwIf (args ? tag && meta ? tags)
5265
"mkOCI/mkStandardOCI/mkDevOCI: use of `tag` and `meta.tags` arguments are not supported together. Remove the former."
@@ -73,23 +86,7 @@ in
7386
++ layers;
7487

7588
maxLayers = 25;
76-
copyToRoot =
77-
[
78-
(nixpkgs.buildEnv {
79-
name = "root";
80-
paths =
81-
setup
82-
++ [
83-
# trick `buildEnv` and prevent the $out`/bin` to be a symlink
84-
(nixpkgs.runCommand "setupDirs" {}
85-
''
86-
mkdir -p $out/bin
87-
'')
88-
setupLinks
89-
];
90-
})
91-
]
92-
++ options.copyToRoot or [];
89+
copyToRoot = [root] ++ options.copyToRoot or [];
9390

9491
config = l.recursiveUpdate config {
9592
User = uid;
@@ -99,7 +96,14 @@ in
9996
};
10097

10198
# Setup tasks can include permissions via the passthru.perms attribute
102-
perms = l.flatten ((l.map (s: l.optionalAttrs (s ? passthru && s.passthru ? perms) s.passthru.perms)) setup) ++ perms;
99+
perms =
100+
l.flatten ((l.map (
101+
s:
102+
l.optionals (s ? passthru && s.passthru ? perms)
103+
(l.map (p: p // {path = root;}) s.passthru.perms)
104+
))
105+
setup)
106+
++ perms;
103107
}
104108
);
105109
in let

src/lib/ops/mkSetup.nix

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ in
1515
*/
1616
name: perms: contents: let
1717
setup = nixpkgs.runCommand "oci-setup-${name}" {} contents;
18-
perms' = l.map (p: p // {path = setup;}) perms;
1918
in
2019
setup
21-
// l.optionalAttrs (perms != []) {passthru.perms = perms';}
20+
// l.optionalAttrs (perms != []) {passthru = {inherit perms;};}

src/lib/ops/mkStandardOCI.nix

+9-15
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,12 @@ in
7373
else operable;
7474

7575
inherit (nixpkgs.dockerTools) caCertificates;
76-
setupLinks =
77-
cell.ops.mkSetup "links" [
78-
{
79-
regex = "/bin";
80-
mode = "0555";
81-
}
82-
] ''
83-
mkdir -p $out/bin
84-
${runtimeEntryLink}
85-
${debugEntryLink}
86-
${livenessLink}
87-
${readinessLink}
88-
'';
76+
extraSetupLinks = ''
77+
${runtimeEntryLink}
78+
${debugEntryLink}
79+
${livenessLink}
80+
${readinessLink}
81+
'';
8982

9083
users = cell.ops.mkUser {
9184
inherit uid gid;
@@ -128,8 +121,9 @@ in
128121
++ (l.optionals hasReadinessProbe [(nix2container.buildLayer {deps = [readinessProbe];})]);
129122
})
130123
];
131-
setup = prepend [setupLinks users nss];
132-
options.copyToRoot = append [tmp caCertificates];
124+
setup = prepend [users nss caCertificates];
125+
inherit extraSetupLinks;
126+
options.copyToRoot = append [tmp];
133127
perms = prepend [
134128
{
135129
path = tmp;

0 commit comments

Comments
 (0)