Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions dist/main.js

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions src/dropSudo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,15 +456,19 @@ async function isSocketWritable(
identity.supplementaryGroupIds.length === 0
? "--clear-groups"
: `--groups=${identity.supplementaryGroupIds.join(",")}`;
// The shell's test builtin asks the kernel (faccessat), which applies ACLs.
// The uutils /usr/bin/test on Ubuntu 26.04 only reads the mode bits.
const result = await execCommand(
"/usr/bin/setpriv",
[
`--reuid=${credentials.userId}`,
`--regid=${identity.primaryGroupId}`,
groupArgument,
"--",
"/usr/bin/test",
"-w",
"/bin/sh",
"-c",
'test -w "$1"',
"sh",
"/proc/self/fd/3",
],
{
Expand Down
27 changes: 12 additions & 15 deletions test/dropSudo.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ const canTestSocketAcls =
canTestLinuxIsolation &&
spawnSync("/usr/bin/setfacl", ["--version"], { stdio: "ignore" }).status === 0;

// The uutils test on Ubuntu 26.04 ignores ACLs; the shell builtin asks the kernel.
function testWritable(target) {
return ["/bin/sh", "-c", 'test -w "$1"', "sh", target];
}

function sudo(args, options = {}) {
const result = spawnSync("sudo", ["-n", "--", ...args], {
encoding: "utf8",
Expand Down Expand Up @@ -345,17 +350,15 @@ test(
...(canTestSocketAcls ? [namedUserAclSocket] : []),
...(canTestSocketAcls && scenario.staleGroups ? [staleAclSocket] : []),
]) {
sudo(["/usr/bin/sudo", "-n", "-u", user, "--", "test", "-w", socket]);
sudo(["/usr/bin/sudo", "-n", "-u", user, "--", ...testWritable(socket)]);
}
assert.notEqual(
spawnSync("sudo", [
"-n",
"-u",
user,
"--",
"test",
"-w",
fallbackSocket,
...testWritable(fallbackSocket),
]).status,
0
);
Expand All @@ -366,9 +369,7 @@ test(
"-u",
user,
"--",
"test",
"-w",
fallbackAclSocket,
...testWritable(fallbackAclSocket),
]).status,
0
);
Expand All @@ -378,9 +379,7 @@ test(
`--regid=${safeGroup}`,
"--clear-groups",
"--",
"/usr/bin/test",
"-w",
fallbackAclSocket,
...testWritable(fallbackAclSocket),
]);
}

Expand Down Expand Up @@ -529,7 +528,7 @@ fs.writeFileSync(${JSON.stringify(originalCredentialsPath)}, JSON.stringify({
? [
...command.slice(0, 4),
"/bin/sh", "-ec",
'/usr/bin/sudo -n /usr/bin/gpasswd -d "$1" "$2"; /usr/bin/id -G > "$3"; /usr/bin/sudo -n -u "$1" -- /usr/bin/test -w "$4"; shift 4; exec "$@"',
'/usr/bin/sudo -n /usr/bin/gpasswd -d "$1" "$2"; /usr/bin/id -G > "$3"; /usr/bin/sudo -n -u "$1" -- /bin/sh -c \'test -w "$1"\' sh "$4"; shift 4; exec "$@"',
"codex-stale-groups", user, privilegedGroup, liveGroupsPath, shadowSocket,
...command.slice(4),
]
Expand Down Expand Up @@ -739,9 +738,7 @@ fs.writeFileSync(${JSON.stringify(originalCredentialsPath)}, JSON.stringify({
"-u",
user,
"--",
"test",
"-w",
socket,
...testWritable(socket),
]);
assert.notEqual(access.status, 0);
const originalAccess = spawnSync("sudo", [
Expand All @@ -751,7 +748,7 @@ fs.writeFileSync(${JSON.stringify(originalCredentialsPath)}, JSON.stringify({
originalCredentials.supplementaryGroupIds.length === 0
? "--clear-groups"
: `--groups=${originalCredentials.supplementaryGroupIds.join(",")}`,
"--", "/usr/bin/test", "-w", socket,
"--", ...testWritable(socket),
], { encoding: "utf8", timeout: 5_000 });
assert.equal(originalAccess.status, 1,
`original runner credentials retained access to ${socket}: ${originalAccess.stderr}`);
Expand Down
Loading