-
Notifications
You must be signed in to change notification settings - Fork 233
Add Linux installation script #1549
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Jean-Laurent de Morlhon <jeanlaurent@morlhon.net>
6b8c22a to
308dde9
Compare
| # Make executable | ||
| chmod +x "$tmp_file" | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do this with install later.
| # Make executable | |
| chmod +x "$tmp_file" |
| sudo mv "$tmp_file" "$target_path" | ||
| sudo chmod +x "$target_path" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| sudo mv "$tmp_file" "$target_path" | |
| sudo chmod +x "$target_path" | |
| sudo install -m 755 "$tmp_file" "$target_path" |
| sudo mv "$tmp_file" "$target_path" | ||
| sudo chmod +x "$target_path" | ||
| else | ||
| mv "$tmp_file" "$target_path" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| mv "$tmp_file" "$target_path" | |
| install -m 755 "$tmp_file" "$target_path" |
krissetto
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should probably check for the existence of curl as well, as folks end ip using convenience scripts like this in ci like environments where curl presence is not always a given
|
|
||
| # Try using gh CLI first if available | ||
| if command -v gh &> /dev/null; then | ||
| gh release list --repo "$REPO" --limit 1 --json tagName --jq '.[0].tagName' 2>/dev/null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think we need both options here, i'd just go straight to the rest api unless there are other reasons for using gh
| print_msg "$YELLOW" " 2. Use Homebrew: brew install cagent" | ||
| exit 1 | ||
| ;; | ||
| MINGW*|MSYS*|CYGWIN*) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: harmless, i don't think many windows users will try to run a bash script called install-linux
|
/review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Security Review
Critical Issues
- Missing checksum verification (HIGH) - The script downloads and executes binaries without cryptographic verification
- Predictable temporary file (MEDIUM) - Using PID-based temp files creates a security vulnerability
- Executing unverified binary (MEDIUM) - The verification step runs the binary before integrity checks
Additional Issues
- Fragile JSON parsing (MEDIUM) - grep/sed parsing could break or behave unexpectedly
- Unquoted variable expansion (LOW) - Could cause issues with special characters
These are all in the newly added code. Please see inline comments for details and recommended fixes.
| local tmp_file="/tmp/$BINARY_NAME-$$" | ||
|
|
||
| # Download binary | ||
| print_msg "$BLUE" "Downloading from $download_url..." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CRITICAL: No checksum or signature verification of downloaded binary
The script downloads a binary from GitHub and immediately makes it executable without any cryptographic verification. Since this installation script is designed to be piped to bash (curl | bash), a compromised download or MITM attack could lead to arbitrary code execution.
Recommendation: Verify the downloaded binary's checksum or GPG signature before executing it. Many projects publish SHA256 checksums alongside releases. Example:
# Download checksum file
curl -fsSL "${download_url}.sha256" -o "${tmp_file}.sha256"
# Verify checksum
expected_sha=$(cat "${tmp_file}.sha256" | awk '{print $1}')
actual_sha=$(sha256sum "$tmp_file" | awk '{print $1}')
if [ "$expected_sha" != "$actual_sha" ]; then
print_msg "$RED" "Error: Checksum verification failed"
exit 1
fiThis is especially critical for security-sensitive installation scripts.
| print_msg "$GREEN" "Installing cagent $version for $os/$arch..." | ||
|
|
||
| local binary_name="${BINARY_NAME}-${os}-${arch}" | ||
| local download_url="https://github.com/$REPO/releases/download/$version/$binary_name" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Predictable temporary file name creates security vulnerability
The script uses /tmp/$BINARY_NAME-$$ where $$ is the process ID. Process IDs are predictable and sequential, allowing an attacker to:
- Pre-create the file with malicious content
- Create a symlink to redirect the download and overwrite sensitive files
- Exploit TOCTOU race conditions
Recommendation: Use mktemp for secure temporary file creation:
local tmp_file=$(mktemp)mktemp creates files with unpredictable random names and secure permissions (0600), preventing these attacks.
| # Verify installation | ||
| print_msg "$BLUE" "Verifying installation..." | ||
| if command -v "$BINARY_NAME" &> /dev/null; then | ||
| local installed_version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Executes downloaded binary without prior checksum verification
The script runs "$BINARY_NAME" --version to verify installation, but executes the binary that was downloaded without any checksum verification (related to issue at line 112). If the download was compromised, this verification step itself executes malicious code.
Recommendation: Only execute the binary after cryptographic verification of its integrity. Move this verification step to occur after checksum validation is added.
| gh release list --repo "$REPO" --limit 1 --json tagName --jq '.[0].tagName' 2>/dev/null | ||
| else | ||
| # Fall back to curl and parse JSON | ||
| curl -sSfL "https://api.github.com/repos/$REPO/releases/latest" | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fragile JSON parsing could break or behave unexpectedly
The fallback version detection uses grep '"tag_name"' | sed -E 's/.*"tag_name": *"([^"]+)".*/\1/' which is brittle and could break if:
- GitHub changes JSON formatting/whitespace
- Special characters appear in tag names
- Response contains multiple tag_name fields
- JSON is minified differently
Recommendation: Since the primary path already uses jq (via gh), consider checking for jq availability in the fallback:
if command -v gh &> /dev/null; then
gh release list --repo "$REPO" --limit 1 --json tagName --jq '.[0].tagName' 2>/dev/null
elif command -v jq &> /dev/null; then
curl -sSfL "https://api.github.com/repos/$REPO/releases/latest" | jq -r '.tag_name'
else
# grep/sed fallback
curl -sSfL "https://api.github.com/repos/$REPO/releases/latest" |
grep '"tag_name"' |
sed -E 's/.*"tag_name": *"([^"]+)".*/\1/'
fiOr use Python/Node which are commonly available on Linux systems for more robust JSON parsing.
| print_msg() { | ||
| local color=$1 | ||
| shift | ||
| echo -e "${color}$@${NC}" >&2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unquoted $@ could cause pathname expansion and word splitting
The line echo -e "${color}$@${NC}" has unquoted $@ which will cause:
- Pathname expansion if messages contain glob characters (*, ?, [])
- Multiple spaces collapsed to single spaces
For example: print_msg "$RED" "Error: File *.txt not found" could expand *.txt to actual filenames.
Recommendation: Use "$*" instead to properly join all arguments:
echo -e "${color}$*${NC}" >&2This preserves the intended message without pathname expansion.
Adds a one-line installer for Linux users similar to Homebrew and Claude Code's installation experience.
Before: Linux users had to manually download binaries, chmod, rename, and configure PATH.
After: Single command installation with automatic setup and verification.