Fix SELinux compatibility in host agent installer

Replace mv with install command to ensure correct SELinux context.
The mv command preserves the user_tmp_t label from /tmp, which
prevents systemd from executing the binary on SELinux systems.

The install command creates a new file with the correct label for
/usr/local/bin. Added automatic restorecon call for SELinux systems
to ensure policy compliance.

Related to #688
This commit is contained in:
rcourtman 2025-11-11 21:13:33 +00:00
parent f6570e18b7
commit e5dfca6c88

View file

@ -386,8 +386,18 @@ else
log_info "Checksum not available (server doesn't provide it yet)"
fi
sudo mv "$TEMP_BINARY" "$AGENT_PATH"
sudo chmod +x "$AGENT_PATH"
# Use install command instead of mv to ensure correct SELinux context
# The install command creates a new file with the correct label for the target directory
sudo install -m 0755 "$TEMP_BINARY" "$AGENT_PATH"
rm -f "$TEMP_BINARY"
# On SELinux systems, explicitly restore context to ensure policy compliance
if command -v selinuxenabled &> /dev/null && selinuxenabled 2>/dev/null; then
if command -v restorecon &> /dev/null; then
sudo restorecon -F "$AGENT_PATH" 2>/dev/null || true
fi
fi
log_success "Agent binary installed to $AGENT_PATH"
# Build reusable agent command strings