Repository navigation
Let sudo -v validate against the passwordless sudo grant
#16111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
statick88
wants to merge
3
commits into
omacom:quattro
from
statick88:fix/passwordless-sudo-verifypw
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| echo "Publish the sudoers default that lets \`sudo -v\` validate against the passwordless grant" | ||
|
|
||
| # The grant file is the only record of the passwordless sudo policy, and it | ||
| # now carries the sudoers default that makes `sudo -v` validate against the | ||
| # grant instead of every other entry in the policy. A grant published before | ||
| # that default existed is rewritten in place, keeping its rule and deadline. | ||
| helper="$OMARCHY_PATH/bin/omarchy-sudo-passwordless" | ||
| sudo "$helper" __upgrade-grant-format |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| #!/bin/bash | ||
|
|
||
| set -euo pipefail | ||
| source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" | ||
| source "$SHELL_TEST_DIR/fixtures/passwordless-sudo-test.sh" | ||
|
|
||
| # Under sudo's default verifypw=all, `sudo -v` asks for a password unless every | ||
| # entry the user has is passwordless. The installer's own admin grant is | ||
| # password-requiring, so a user who asked for passwordless sudo could not | ||
| # validate credentials without a password. The published grant therefore | ||
| # carries the sudoers default that makes validation read the grant instead of | ||
| # every other entry in the policy. The default names the account that asked | ||
| # for the grant, so it changes the rule for that account alone. | ||
|
|
||
| ( | ||
| source "$library" | ||
| enable_locked 1000 15 | ||
| head -1 "$(rule_file 1000)" | grep -qx 'Defaults:audituser verifypw = any' | ||
| tail -1 "$(rule_file 1000)" | grep -qxE 'audituser ALL=\(ALL\) NOTAFTER=[0-9]{14}Z NOPASSWD: ALL' | ||
| ) | ||
| pass "the published grant carries the sudoers default above its rule" | ||
|
|
||
| ( | ||
| source "$library" | ||
| enable_locked 1000 permanent | ||
| head -1 "$(rule_file 1000 permanent)" | grep -qx 'Defaults:audituser verifypw = any' | ||
| tail -1 "$(rule_file 1000 permanent)" | grep -qx 'audituser ALL=(ALL) NOPASSWD: ALL' | ||
| ) | ||
| pass "a permanent grant carries the sudoers default above its rule" | ||
|
|
||
| # The default is scoped to the account that asked for the grant, so it never | ||
| # changes the rule for another account on the host. | ||
| ( | ||
| source "$library" | ||
| enable_locked 1000 15 | ||
| ! grep -q '^Defaults verifypw' "$(rule_file 1000)" | ||
| ) | ||
| pass "the published default is scoped to the account that asked for the grant" | ||
|
|
||
| # A grant published before the default existed is still this command's grant, | ||
| # so it keeps working until it is rewritten. | ||
| ( | ||
| source "$library" | ||
| reset_grant | ||
| printf 'audituser ALL=(ALL) NOPASSWD: ALL\n' >"$(rule_file 1000 permanent)" | ||
| read_grant 1000 | ||
| [[ $GRANT_NAME == "audituser" ]] | ||
| ) | ||
| pass "a grant published before the default existed is still read as the user's grant" | ||
|
|
||
| # A default that names another account is not this command's grant. | ||
| ( | ||
| source "$library" | ||
| reset_grant | ||
| printf 'Defaults:root verifypw = any\naudituser ALL=(ALL) NOPASSWD: ALL\n' >"$(rule_file 1000 permanent)" | ||
| assert_status 2 read_grant 1000 | ||
| ) | ||
| pass "a default that names another account is not read as the user's grant" | ||
|
|
||
| # The upgrade rewrites such a grant in place, keeping the rule and its | ||
| # deadline exactly as they were. | ||
| ( | ||
| source "$library" | ||
| reset_grant | ||
| printf 'audituser ALL=(ALL) NOTAFTER=20261231235959Z NOPASSWD: ALL\n' >"$(rule_file 1000)" | ||
| upgrade_grant_format_locked | ||
| head -1 "$(rule_file 1000)" | grep -qx 'Defaults:audituser verifypw = any' | ||
| tail -1 "$(rule_file 1000)" | grep -qx 'audituser ALL=(ALL) NOTAFTER=20261231235959Z NOPASSWD: ALL' | ||
| [[ $(wc -l <"$(rule_file 1000)") == 2 ]] | ||
| ) | ||
| pass "the upgrade rewrites a grant published before the default existed" | ||
|
|
||
| ( | ||
| source "$library" | ||
| reset_grant | ||
| printf 'audituser ALL=(ALL) NOPASSWD: ALL\n' >"$(rule_file 1000 permanent)" | ||
| upgrade_grant_format_locked | ||
| upgrade_grant_format_locked | ||
| [[ $(wc -l <"$(rule_file 1000 permanent)") == 2 ]] | ||
| head -1 "$(rule_file 1000 permanent)" | grep -qx 'Defaults:audituser verifypw = any' | ||
| tail -1 "$(rule_file 1000 permanent)" | grep -qx 'audituser ALL=(ALL) NOPASSWD: ALL' | ||
| ) | ||
| pass "the upgrade leaves a grant that already carries the default alone" | ||
|
|
||
| # Policy this command did not generate stays untouched: it belongs to the | ||
| # administrator, and rewriting it would publish a rule nobody asked for. | ||
| ( | ||
| source "$library" | ||
| printf 'admin ALL=(ALL) NOPASSWD: /usr/bin/true\n' >"$test_tmp/etc/sudoers.d/99-omarchy-nopasswd-custom" | ||
| upgrade_grant_format_locked | ||
| [[ $(cat "$test_tmp/etc/sudoers.d/99-omarchy-nopasswd-custom") == 'admin ALL=(ALL) NOPASSWD: /usr/bin/true' ]] | ||
| ) | ||
| pass "the upgrade leaves administrator policy under the generated prefix alone" | ||
|
|
||
| # The migration reaches the upgrade through the command's own dispatch, so the | ||
| # action has to be reachable from the executable and not only from inside it. | ||
| ( | ||
| PATH="$test_tmp/bin:$PATH" TEST_EUID=0 "$test_tmp/omarchy-sudo-passwordless" __upgrade-grant-format | ||
| ) | ||
| pass "the upgrade action is reachable through the command's own dispatch" | ||
|
|
||
| # The migration itself has to run: it reaches the upgrade through that | ||
| # dispatch, and a failure there would stop the queue and leave every later | ||
| # migration pending. | ||
| mkdir -p "$test_tmp/source/bin" | ||
| ln -sf "$test_tmp/omarchy-sudo-passwordless" "$test_tmp/source/bin/omarchy-sudo-passwordless" | ||
| ( | ||
| PATH="$test_tmp/bin:$PATH" TEST_MIGRATION=1 OMARCHY_PATH="$test_tmp/source" \ | ||
| /usr/bin/bash "$ROOT/migrations/1792527479.sh" | ||
| ) | ||
| pass "the migration runs the upgrade through the command's own dispatch" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.