Skip to content

Commit 9277472

Browse files
authored
Fix umask=false for images without a shell entrypoint (#1298)
* test: Add umask test with image without `sh` as entrypoint * fix(umask): Explicitly set entrypoint to `sh`
1 parent 3645ea0 commit 9277472

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

src/job.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ export class Job {
469469
let chownOpt = "0:0";
470470
let chmodOpt = "a+rw";
471471
if (expanded["FF_DISABLE_UMASK_FOR_DOCKER_EXECUTOR"] === "true") {
472-
const {stdout} = await Utils.spawn(["docker", "run", "--rm", imageName, "sh", "-c", "echo \"$(id -u):$(id -g)\""]);
472+
const {stdout} = await Utils.spawn(["docker", "run", "--rm", "--entrypoint", "sh", imageName, "-c", "echo \"$(id -u):$(id -g)\""]);
473473
chownOpt = stdout;
474474
if (chownOpt == "0:0") {
475475
chmodOpt = "g-w";

tests/test-cases/umask/.gitlab-ci.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,11 @@ alpine-root:
1111
script:
1212
- stat -c "%a %n %u %g" one.txt
1313
- stat -c "%a %n %u %g" script.sh
14+
15+
kaniko-root:
16+
image:
17+
name: gcr.io/kaniko-project/executor:v1.23.0-debug
18+
entrypoint: [""]
19+
script:
20+
- stat -c "%a %n %u %g" one.txt
21+
- stat -c "%a %n %u %g" script.sh

tests/test-cases/umask/integration.umask.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,33 @@ test.concurrent("umask <alpine-root> --no-umask", async () => {
6969
];
7070
expect(writeStreams.stdoutLines).toEqual(expect.arrayContaining(expectedStdOut));
7171
});
72+
73+
test.concurrent("umask <kaniko-root> --umask", async () => {
74+
const writeStreams = new WriteStreamsMock();
75+
await handler({
76+
cwd: "tests/test-cases/umask/",
77+
umask: true,
78+
job: ["kaniko-root"],
79+
}, writeStreams);
80+
81+
const expectedStdOut = [
82+
chalk`{blueBright kaniko-root} {greenBright >} 666 one.txt 0 0`,
83+
chalk`{blueBright kaniko-root} {greenBright >} 777 script.sh 0 0`,
84+
];
85+
expect(writeStreams.stdoutLines).toEqual(expect.arrayContaining(expectedStdOut));
86+
});
87+
88+
test.concurrent("umask <kaniko-root> --no-umask", async () => {
89+
const writeStreams = new WriteStreamsMock();
90+
await handler({
91+
cwd: "tests/test-cases/umask/",
92+
umask: false,
93+
job: ["kaniko-root"],
94+
}, writeStreams);
95+
96+
const expectedStdOut = [
97+
chalk`{blueBright kaniko-root} {greenBright >} 644 one.txt 0 0`,
98+
chalk`{blueBright kaniko-root} {greenBright >} 755 script.sh 0 0`,
99+
];
100+
expect(writeStreams.stdoutLines).toEqual(expect.arrayContaining(expectedStdOut));
101+
});

0 commit comments

Comments
 (0)