-
-
Notifications
You must be signed in to change notification settings - Fork 27
Fix: plugin/base requirements installed as web-user, invisible to root-run display service #380
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
+190
−13
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
8de7063
fix: install plugin/base requirements as root so ledmatrix.service ca…
ChuckBuilds 7558aaa
fix: invoke safe_pip_install.sh via explicit bash, matching sudoers rule
ChuckBuilds e454930
fix: harden safe_pip_install.sh invocation against bash-path drift + …
ChuckBuilds 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #!/bin/bash | ||
| # safe_pip_install.sh — Install a requirements.txt as root after validating | ||
| # that the resolved path is the project's own requirements.txt or a plugin's | ||
| # requirements.txt under plugin-repos/ or plugins/. | ||
| # | ||
| # This script is intended to be called via sudo from the web interface, so | ||
| # that packages a plugin declares end up visible to ledmatrix.service (which | ||
| # runs as root) rather than only to whichever non-root user runs the web | ||
| # interface. Plugin code already runs as root once loaded, so installing its | ||
| # declared dependencies as root is not a new trust boundary. | ||
| # | ||
| # Usage: safe_pip_install.sh <requirements_txt_path> | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| if [ $# -ne 1 ]; then | ||
| echo "Usage: $0 <requirements_txt_path>" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| TARGET="$1" | ||
|
|
||
| # Determine the project root (parent of scripts/fix_perms/) | ||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" | ||
|
|
||
| # Allowed locations (resolved, no trailing slash): | ||
| # - the project's own requirements.txt | ||
| # - any requirements.txt under plugin-repos/ or plugins/ | ||
| ALLOWED_EXACT="$(realpath --canonicalize-missing "$PROJECT_ROOT/requirements.txt")" | ||
| ALLOWED_BASES=( | ||
| "$(realpath --canonicalize-missing "$PROJECT_ROOT/plugin-repos")" | ||
| "$(realpath --canonicalize-missing "$PROJECT_ROOT/plugins")" | ||
| ) | ||
|
|
||
| # Resolve the target path (follow symlinks); works even if it doesn't exist. | ||
| RESOLVED_TARGET="$(realpath --canonicalize-missing "$TARGET")" | ||
|
|
||
| # Must be named requirements.txt — never install from an arbitrary file. | ||
| if [ "$(basename "$RESOLVED_TARGET")" != "requirements.txt" ]; then | ||
| echo "DENIED: $RESOLVED_TARGET is not a requirements.txt file" >&2 | ||
| exit 2 | ||
| fi | ||
|
|
||
| ALLOWED=false | ||
| if [ "$RESOLVED_TARGET" = "$ALLOWED_EXACT" ]; then | ||
| ALLOWED=true | ||
| else | ||
| for BASE in "${ALLOWED_BASES[@]}"; do | ||
| if [[ "$RESOLVED_TARGET" == "$BASE/"* ]]; then | ||
| ALLOWED=true | ||
| break | ||
| fi | ||
| done | ||
| fi | ||
|
|
||
| if [ "$ALLOWED" = false ]; then | ||
| echo "DENIED: $RESOLVED_TARGET is not an allowed requirements.txt location" >&2 | ||
| echo "Allowed: $ALLOWED_EXACT, or any requirements.txt under: ${ALLOWED_BASES[*]}" >&2 | ||
| exit 2 | ||
| fi | ||
|
|
||
| if [ ! -f "$RESOLVED_TARGET" ]; then | ||
| echo "ERROR: $RESOLVED_TARGET does not exist" >&2 | ||
| exit 3 | ||
| fi | ||
|
|
||
| PYTHON_PATH="$(command -v python3)" | ||
| # --ignore-installed: root's site-packages often has apt/dpkg-managed copies | ||
| # of common libraries (requests, urllib3, ...) with no pip RECORD file, which | ||
| # pip refuses to uninstall in place ("Cannot uninstall: no RECORD file was | ||
| # found"). This tells pip to install the newer version alongside rather than | ||
| # aborting the whole requirements.txt install over one such conflict. | ||
| exec "$PYTHON_PATH" -m pip install --break-system-packages --ignore-installed -r "$RESOLVED_TARGET" |
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
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.