Skip to content

Commit 46acd2d

Browse files
committed
Check both registry and schemeful URL for Docker creds
Signed-off-by: itowlson <ivan.towlson@fermyon.com>
1 parent 1d01bb4 commit 46acd2d

File tree

1 file changed

+37
-23
lines changed
  • crates/wasm-pkg-client/src/oci

1 file changed

+37
-23
lines changed

crates/wasm-pkg-client/src/oci/mod.rs

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -112,31 +112,17 @@ impl OciBackend {
112112
));
113113
}
114114

115-
match docker_credential::get_credential(&self.oci_registry) {
116-
Ok(DockerCredential::UsernamePassword(username, password)) => {
117-
return Ok(RegistryAuth::Basic(username, password));
118-
}
119-
Ok(DockerCredential::IdentityToken(_)) => {
120-
return Err(Error::CredentialError(anyhow::anyhow!(
121-
"identity tokens not supported"
122-
)));
123-
}
124-
Err(err) => {
125-
if matches!(
126-
err,
127-
CredentialRetrievalError::ConfigNotFound
128-
| CredentialRetrievalError::ConfigReadError
129-
| CredentialRetrievalError::NoCredentialConfigured
130-
| CredentialRetrievalError::HelperFailure { .. }
131-
) {
132-
tracing::debug!("Failed to look up OCI credentials: {err}");
133-
} else {
134-
tracing::warn!("Failed to look up OCI credentials: {err}");
135-
};
115+
match get_docker_credential(&self.oci_registry)? {
116+
Some(c) => Ok(c),
117+
None => {
118+
tracing::debug!("Failed to look up OCI credentials by registry, trying server URL");
119+
let server_url = format!("https://{}", self.oci_registry);
120+
match get_docker_credential(&server_url)? {
121+
Some(c) => Ok(c),
122+
None => Ok(RegistryAuth::Anonymous),
123+
}
136124
}
137125
}
138-
139-
Ok(RegistryAuth::Anonymous)
140126
}
141127

142128
pub(crate) fn make_reference(
@@ -164,3 +150,31 @@ pub(crate) fn oci_registry_error(err: OciDistributionError) -> Error {
164150
_ => Error::RegistryError(err.into()),
165151
}
166152
}
153+
154+
fn get_docker_credential(registry: &str) -> Result<Option<RegistryAuth>, Error> {
155+
match docker_credential::get_credential(registry) {
156+
Ok(DockerCredential::UsernamePassword(username, password)) => {
157+
return Ok(Some(RegistryAuth::Basic(username, password)));
158+
}
159+
Ok(DockerCredential::IdentityToken(_)) => {
160+
return Err(Error::CredentialError(anyhow::anyhow!(
161+
"identity tokens not supported"
162+
)));
163+
}
164+
Err(err) => {
165+
if matches!(
166+
err,
167+
CredentialRetrievalError::ConfigNotFound
168+
| CredentialRetrievalError::ConfigReadError
169+
| CredentialRetrievalError::NoCredentialConfigured
170+
| CredentialRetrievalError::HelperFailure { .. }
171+
) {
172+
tracing::debug!("Failed to look up OCI credentials: {err}");
173+
} else {
174+
tracing::warn!("Failed to look up OCI credentials: {err}");
175+
};
176+
}
177+
}
178+
179+
Ok(None)
180+
}

0 commit comments

Comments
 (0)