fix(harbor-gc): make the garbage collector fail safe#149
Open
lfrancke wants to merge 1 commit into
Open
Conversation
- Check DELETE responses with error_for_status() instead of ignoring them, and require HARBOR_ROBOT_PASSWORD (was `.ok()`, so a missing/renamed var silently produced unauthenticated no-op deletes while exiting 0). - Guard the rust-builder cleanup against a TOCTOU race: if a new image is tagged "latest" between snapshotting its references and listing artifacts, re-check and skip the cleanup instead of deleting the current latest. - Paginate the rust-builder artifact listing (a single page_size=100 request silently ignored anything past the first 100). - Don't panic when "latest" has no references (unwrap -> unwrap_or_default). - Use a single shared reqwest client with a 30s timeout so a hung registry can't block forever (also avoids building a client per delete).
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Harbor garbage-collector safety
A garbage collector that reports success while deleting the wrong image (or nothing) is a quiet operational hazard. All in
tools/harbor-garbage-collector/src/main.rs.DELETEresponses were never status-checked, and the robot password used.ok(), so a missing/renamedHARBOR_ROBOT_PASSWORDsilently degraded to unauthenticated deletes: the tool prints "Removing…", deletes nothing (401/403), and exits 0. Now the password is required and every delete useserror_for_status().latest—latest's references were snapshotted, then the artifact list fetched separately; arust-builder:latestpushed in that window would be deleted as "dangling". Added a re-check: iflatest's digest moved during the run, skip the cleanup for that image.page_size=100request; >100 artifacts silently ignored. Now paginated like the rest of the file..references.unwrap()panicked iflatesthad no references (e.g. single-arch). Nowunwrap_or_default().reqwest::get/Client::new()with one shared client with a 30s timeout.Verification
cargo checkandcargo clippyboth clean.Scoped to this one tool; the other Rust tools' timeouts/hardening are a separate PR.