Repository navigation
Offer to reboot when toggling sudoless Docker; show only the relevant menu entry #8098
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 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
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,44 @@ | ||
| #!/bin/bash | ||
|
|
||
| # omarchy:summary=Succeed when Docker needs sudo, fail when it can be used directly | ||
| # omarchy:args=[--configured] | ||
| # omarchy:examples=omarchy-sudo-docker && echo "needs sudo" | omarchy-sudo-docker --configured | ||
| # omarchy:hidden=true | ||
|
|
||
| # The docker group is root-equivalent, so Omarchy leaves users out of it by | ||
| # default and reaches the daemon through a prompt instead. Everything that has | ||
| # to make that choice asks here rather than testing group membership itself. | ||
| # | ||
| # Two questions, because they have different answers between toggling sudoless | ||
| # Docker and the reboot that applies it (group membership is fixed when the | ||
| # session is created): | ||
| # | ||
| # (default) Does Docker need sudo *right now*? Answered by whether this | ||
| # process can actually reach the socket, which is what decides | ||
| # if a command must elevate. Still true in the window after | ||
| # sudoless Docker is enabled but before the reboot. | ||
| # --configured Will it need sudo once the account's groups take effect? | ||
| # Answered from the account's configured groups, so the menu | ||
| # offers the toggle that can actually change state. | ||
| # | ||
| # Succeeds (exit 0) when sudo is needed, so it reads as `if omarchy-sudo-docker`. | ||
|
|
||
| DOCKER_SOCKET="${OMARCHY_DOCKER_SOCKET:-/var/run/docker.sock}" | ||
|
|
||
| case "${1:-}" in | ||
| --configured) | ||
| # An account in the docker group will not need sudo after the next login. | ||
| id -nG "$USER" 2>/dev/null | grep -qw docker && exit 1 | ||
| exit 0 | ||
| ;; | ||
| "") | ||
| # A socket we can write is a daemon we can drive without elevating. A missing | ||
| # socket counts as needing sudo: reaching it means starting it as root anyway. | ||
| [[ -w $DOCKER_SOCKET ]] && exit 1 | ||
| exit 0 | ||
| ;; | ||
| *) | ||
| echo "Usage: omarchy-sudo-docker [--configured]" >&2 | ||
| exit 2 | ||
| ;; | ||
| esac |
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
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
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,67 @@ | ||
| #!/bin/bash | ||
| # | ||
| # omarchy-sudo-docker is the single answer to "does Docker need sudo", and it | ||
| # answers two different questions on purpose. The default asks whether this | ||
| # session can reach the socket, which is what decides if a command must elevate. | ||
| # --configured asks whether the account is set up for sudoless Docker, which is | ||
| # what the menu needs so it offers the toggle that can change state. Between | ||
| # enabling sudoless Docker and the reboot that grants the group, those disagree. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" | ||
|
|
||
| TMPDIR=$(mktemp -d) | ||
| trap 'rm -rf "$TMPDIR"' EXIT | ||
|
|
||
| command="$ROOT/bin/omarchy-sudo-docker" | ||
|
|
||
| # Stub id so the configured groups are controllable. | ||
| mkdir -p "$TMPDIR/bin" | ||
| cat >"$TMPDIR/bin/id" <<'STUB' | ||
| #!/bin/bash | ||
| printf '%s\n' "${STUB_GROUPS:-wheel input}" | ||
| STUB | ||
| chmod +x "$TMPDIR/bin/id" | ||
|
|
||
| # A writable stand-in means the socket is reachable; an unwritable one means it | ||
| # is not. Test the file mode rather than a live daemon. | ||
| reachable_socket="$TMPDIR/reachable.sock" | ||
| blocked_socket="$TMPDIR/blocked.sock" | ||
| touch "$reachable_socket" "$blocked_socket" | ||
| chmod 600 "$reachable_socket" | ||
| chmod 400 "$blocked_socket" | ||
|
|
||
| run() { # SOCKET GROUPS [--configured] | ||
| env PATH="$TMPDIR/bin:$PATH" OMARCHY_DOCKER_SOCKET="$1" STUB_GROUPS="$2" USER=tester \ | ||
| bash "$command" ${3:+"$3"} | ||
| } | ||
|
|
||
| # Default mode follows the socket, not the group list. | ||
| run "$blocked_socket" "wheel input" || fail "an unreachable socket means Docker needs sudo" | ||
| run "$reachable_socket" "wheel input" && fail "a reachable socket means Docker does not need sudo" | ||
| pass "default mode answers from the socket this session can reach" | ||
|
|
||
| # A socket that isn't there at all still needs elevation (starting it is root work). | ||
| run "$TMPDIR/absent.sock" "wheel input docker" || fail "a missing socket means Docker needs sudo" | ||
| pass "a missing socket counts as needing sudo" | ||
|
|
||
| # --configured follows the account's groups, not the socket. | ||
| run "$blocked_socket" "wheel input docker" --configured && fail "a configured docker group means no sudo is needed" | ||
| run "$reachable_socket" "wheel input" --configured || fail "no docker group means sudo is needed" | ||
| pass "--configured answers from the account's groups" | ||
|
|
||
| # The window this split exists for: sudoless Docker has just been enabled, so the | ||
| # account carries the group while the running session still cannot use it. The | ||
| # menu must offer Remove (--configured says no sudo) while lazydocker and the | ||
| # Windows VM must still prompt (default says sudo). | ||
| run "$blocked_socket" "wheel input docker" || fail "the session still needs sudo before the reboot" | ||
| run "$blocked_socket" "wheel input docker" --configured && fail "the account is already configured for sudoless Docker" | ||
| pass "the two modes disagree between enabling sudoless Docker and the reboot" | ||
|
|
||
| # An unknown argument is a usage error, not a silent answer either way. | ||
| run "$reachable_socket" "wheel input" --bogus 2>/dev/null && fail "an unknown flag exits non-zero" | ||
| status=0 | ||
| run "$reachable_socket" "wheel input" --bogus >/dev/null 2>&1 || status=$? | ||
| (( status == 2 )) || fail "an unknown flag exits 2, not the boolean 1" | ||
| pass "an unknown flag is a usage error" |
Oops, something went wrong.
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.