Skip to content

Commit

Permalink
daemon: add even more logging to trusted user logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sandydoo committed Jan 9, 2024
1 parent 11a95a7 commit a7c8acb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
7 changes: 5 additions & 2 deletions dist/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8001,12 +8001,15 @@ async function isTrustedUser() {
// Chech if Nix is installed in single-user mode.
let isStoreWritable = await isWritable('/nix/store');
core.debug(`Is store writable: ${isStoreWritable}`);
return isStoreWritable
let isTrustedUser = isStoreWritable
|| trustedUsers.includes(user)
|| trustedGroups.some((group) => userGroups.includes(group));
core.debug(`User ${user} is trusted: ${isTrustedUser}`);
return isTrustedUser;
}
catch (error) {
catch (err) {
core.warning('Failed to determine if the user is trusted. Assuming untrusted user.');
core.debug(`error: ${err}`);
return false;
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ async function isTrustedUser(): Promise<boolean> {
try {
let user = os.userInfo().username;
core.debug(`Checking if user ${user} is trusted`);

let userGroups = await execToVariable('id', ['-Gn', user], { silent: true }).then((str) => str.trim().split(' '));
core.debug(`User ${user} is in groups ${userGroups}`);

Expand All @@ -322,11 +323,17 @@ async function isTrustedUser(): Promise<boolean> {
let isStoreWritable = await isWritable('/nix/store');
core.debug(`Is store writable: ${isStoreWritable}`);

return isStoreWritable
let isTrustedUser =
isStoreWritable
|| trustedUsers.includes(user)
|| trustedGroups.some((group) => userGroups.includes(group));
} catch (error) {

core.debug(`User ${user} is trusted: ${isTrustedUser}`);

return isTrustedUser;
} catch (err) {
core.warning('Failed to determine if the user is trusted. Assuming untrusted user.');
core.debug(`error: ${err}`);
return false;
}
}
Expand Down

0 comments on commit a7c8acb

Please sign in to comment.