cli: replace updater curl/tar with reqwest+flate2+tar, add integrity checks (#640)#641
Conversation
…checks (Tracer-Cloud#640) Replace curl/tar process spawning with native Rust download (reqwest) and extraction (flate2+tar), improving portability and error context. Harden archive extraction to reject path traversal, absolute paths, and symlinks/hardlinks—extracting only the expected tracer binary entry. Add critical security measures for self-updater: - SHA256 checksum verification of downloaded tarballs - Request timeout (30s) and redirect limit (5) to prevent hangs/attacks - Backup/rollback mechanism (.bak file) for failed updates - Graceful runtime creation error handling (no panic) Place temp files alongside the target binary to avoid cross-filesystem rename failures (EXDEV). Add comprehensive unit tests covering valid and malicious archive entries. Files changed: - Cargo.toml: Add sha2 workspace dependency - src/tracer/Cargo.toml: Add sha2 dependency - src/tracer/src/cli/handlers/update/updater.rs: Core implementation
|
hey @tiagonix, dropping a review since this PR's been sitting a while and it's substantive Rust work. two thoughts plus one nit:
let result = match tokio::runtime::Handle::try_current() {
Ok(handle) => tokio::task::block_in_place(|| handle.block_on(update_impl())),
Err(_) => Runtime::new()?.block_on(update_impl()),
};probably fine for now since update() is sync-dispatched, but worth a comment in the code for the next person.
security hardening (sha256, path traversal rejection, symlink/hardlink rejection, single-binary extraction) is solid. lgtm with the two thoughts above. |
📌 Summary
Replaces shell-based updater with native Rust implementation featuring cryptographic integrity verification, hardened archive extraction, and atomic replacement with rollback capability.
🔍 Related Issues/Tickets
Part of ongoing effort to eliminate external dependencies and harden security-critical operations.
Closes #640
✨ Changes Introduced
Security hardening:
.., absolute paths, symlinks, and hardlinkstracerbinary, ignoring other archive contentsReliability improvements:
reqwestdownload with proper HTTP status handlingflate2+tarextraction with typed error context.bakfile) for failed updatesTesting:
✨ Infrastructure Impact
None. Changes are isolated to the updater module. Downloads continue from existing S3 bucket structure.
✅ Checklist
🛠️ How to Test
tracer updateto verify download, checksum verification, and replacement succeedcargo test -p tracerto verify unit tests pass📌 Additional Notes
This eliminates runtime dependencies on
curlandtarbinaries, improving portability across minimal container images and systems with restricted PATH. The security improvements are essential for self-updater operations where compromise of the download channel could lead to arbitrary code execution.