Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion packages/runtime-core/src/provider/registry_credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ fn run_helper(
"The Docker credential helper failed; its output was discarded.",
));
}
if written.is_some_and(|result| result.is_err()) {
if written.as_ref().is_some_and(helper_write_failed) {
return Err(error(
"Cannot send the server address to the Docker credential helper.",
));
Expand Down Expand Up @@ -415,6 +415,14 @@ pub(super) fn lookup(
entry.map_or(Ok(None), file_credential)
}

/// Like Go's `os/exec`, which Docker uses to run helpers, a helper that exits without
/// reading its input is not a failure: its exit status and reply decide the outcome.
fn helper_write_failed(result: &std::io::Result<()>) -> bool {
result
.as_ref()
.is_err_and(|error| error.kind() != std::io::ErrorKind::BrokenPipe)
}

#[cfg(test)]
pub(super) mod tests {
use super::*;
Expand Down Expand Up @@ -639,4 +647,19 @@ pub(super) mod tests {
.contains("PRIVATE_CANARY")
);
}

#[test]
fn a_helper_that_closes_its_input_early_is_judged_by_its_reply() {
use std::io::{Error, ErrorKind};
assert!(!helper_write_failed(&Ok(())));
assert!(!helper_write_failed(&Err(Error::from(
ErrorKind::BrokenPipe
))));
assert!(helper_write_failed(&Err(Error::from(
ErrorKind::PermissionDenied
))));
assert!(helper_write_failed(&Err(Error::from(
ErrorKind::Interrupted
))));
}
}
Loading