Skip to content
Merged
Show file tree
Hide file tree
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
10 changes: 7 additions & 3 deletions app/puller_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use clap::Parser;

use rules_minidock_tools::container_specs::{ConfigDelta, Manifest};

// cargo run --bin puller-app -- --registry l.gcr.io --repository google/bazel --digest sha256:08434856d8196632b936dd082b8e03bae0b41346299aedf60a0d481ab427a69f
// cargo run --bin puller-app -- --registry l.gcr.io --repository google/bazel --digest sha256:08434856d8196632b936dd082b8e03bae0b41346299aedf60a0d481ab427a69f --architecture=x86_64

#[derive(Parser, Debug)]
#[clap(name = "puller app")]
Expand All @@ -23,8 +23,12 @@ struct Opt {
architecture: String,

#[clap(long)]
// List of comma separated helpers. with the registry:helper_path
//e.g. foo.gcr.io:/path/to/helper,bar.gcr.io:/path/to/helper2
// List of comma separated helpers in registry:helper_path format;
// requests will attempt to match a helper first based on the "service"
// field in the authentication challenge, and then based on the registry
// param passed to this tool.
// e.g. foo.gcr.io:/path/to/helper,bar.gcr.io:/path/to/helper2
//
docker_authorization_helpers: Option<String>,
}

Expand Down
8 changes: 6 additions & 2 deletions app/pusher_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ struct Opt {
skip_manifest_upload: bool,

#[clap(long)]
// List of comma separated helpers. with the registry:helper_path
//e.g. foo.gcr.io:/path/to/helper,bar.gcr.io:/path/to/helper2
// List of comma separated helpers in registry:helper_path format;
// requests will attempt to match a helper first based on the "service"
// field in the authentication challenge, and then based on the registry
// param passed to this tool.
// e.g. foo.gcr.io:/path/to/helper,bar.gcr.io:/path/to/helper2
//
docker_authorization_helpers: Option<String>,
}

Expand Down
8 changes: 7 additions & 1 deletion src/registry/http/http_cli/authentication_flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub async fn authenticate_request(
auth_fail: &BearerConfig,
inner_client: &Client<hyper_rustls::HttpsConnector<hyper::client::HttpConnector>>,
docker_authorization_helpers: Arc<Vec<DockerAuthenticationHelper>>,
registry: String,
) -> Result<AuthResponse, RequestFailType> {
let mut parts = auth_fail.realm.clone().into_parts();
let new_query_items = if let Some(scope) = &auth_fail.scope {
Expand Down Expand Up @@ -69,7 +70,12 @@ pub async fn authenticate_request(

let matching_helper_opt: Option<&DockerAuthenticationHelper> = docker_authorization_helpers
.iter()
.find(|e| e.registry == auth_fail.service);
.find(|e| e.registry == auth_fail.service)
// There's no guarantee that the "service" returned in the authentication challenge is
// an actual registry name, so if no match is found based on the Bearer "service" then
// we'll try to match based on the registry name.
// See https://distribution.github.io/distribution/spec/auth/token/
.or_else(|| docker_authorization_helpers.iter().find(|e| e.registry == registry));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


let basic_auth_info = if let Some(matching_helper) = matching_helper_opt {
let mut child = Command::new(&matching_helper.helper_path)
Expand Down
2 changes: 2 additions & 0 deletions src/registry/http/http_cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct HttpCli {
pub inner_client: Client<hyper_rustls::HttpsConnector<hyper::client::HttpConnector>>,
pub auth_info: Arc<Mutex<Option<AuthResponse>>>,
pub docker_authorization_helpers: Arc<Vec<DockerAuthenticationHelper>>,
pub registry: String,
}

impl HttpCli {
Expand Down Expand Up @@ -101,6 +102,7 @@ impl HttpCli {
&auth_fail,
&self.inner_client,
self.docker_authorization_helpers.clone(),
self.registry.clone(),
)
.await?;
let mut ai = self.auth_info.lock().await;
Expand Down
1 change: 1 addition & 0 deletions src/registry/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ impl HttpRegistry {
inner_client: http_client,
docker_authorization_helpers,
auth_info: Default::default(),
registry: registry_base.as_ref().to_string(),
},
};

Expand Down