Skip to content

Commit 3d01b05

Browse files
authored
[registry] Add skip_http_fallback config option (#18)
Allow disabling the automatic HTTPS-to-HTTP downgrade that occurs on TLS connection errors. When skip_http_fallback is set to true, TLS errors propagate as-is instead of silently falling back to plaintext HTTP. Defaults to false to preserve backward compatibility.
1 parent c2d8415 commit 3d01b05

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

api/src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,9 @@ pub struct RegistryConfig {
638638
/// Disable background token refresh thread. Defaults to false.
639639
#[serde(skip_deserializing)]
640640
pub disable_token_refresh: bool,
641+
/// Prevent automatic fallback from HTTPS to HTTP on TLS errors.
642+
#[serde(default)]
643+
pub skip_http_fallback: bool,
641644
/// Enable mirrors for the read request.
642645
#[serde(default)]
643646
pub mirrors: Vec<MirrorConfig>,

storage/src/backend/registry.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ struct RegistryState {
203203
blob_url_scheme: String,
204204
// Replace registry redirected url host with the given host
205205
blob_redirected_host: String,
206+
// Prevent automatic fallback from HTTPS to HTTP on TLS errors
207+
skip_http_fallback: bool,
206208
// Cache bearer token (get from registry authentication server) or basic authentication auth string.
207209
// We need use it to reduce the pressure on token authentication server or reduce the base64 compute workload for every request.
208210
// Use RwLock here to avoid using mut backend trait object.
@@ -238,6 +240,9 @@ impl RegistryState {
238240
}
239241

240242
fn needs_fallback_http(&self, e: &dyn Error) -> bool {
243+
if self.skip_http_fallback {
244+
return false;
245+
}
241246
match e.source() {
242247
Some(err) => match err.source() {
243248
Some(err) => {
@@ -886,6 +891,7 @@ impl Registry {
886891
retry_limit,
887892
blob_url_scheme: config.blob_url_scheme.clone(),
888893
blob_redirected_host: config.blob_redirected_host.clone(),
894+
skip_http_fallback: config.skip_http_fallback,
889895
cached_auth_using_http_get: HashCache::new(),
890896
cached_redirect: HashCache::new(),
891897
token_expired_at: ArcSwapOption::new(None),
@@ -1072,6 +1078,7 @@ mod tests {
10721078
retry_limit: 5,
10731079
blob_url_scheme: "https".to_string(),
10741080
blob_redirected_host: "oss.alibaba-inc.com".to_string(),
1081+
skip_http_fallback: false,
10751082
cached_auth_using_http_get: Default::default(),
10761083
cached_auth: Default::default(),
10771084
cached_redirect: Default::default(),

0 commit comments

Comments
 (0)