chore: enable partial auth as a feature flag (#5711)

This commit is contained in:
Nishant Joshi
2024-09-02 12:44:40 +05:30
committed by GitHub
parent e4f1fbc5a5
commit c03587f9c6
5 changed files with 20 additions and 1 deletions

View File

@ -11225,6 +11225,9 @@ impl Default for super::settings::ApiKeys {
// context used for blake3
#[cfg(feature = "partial-auth")]
checksum_auth_context: String::new().into(),
#[cfg(feature = "partial-auth")]
enable_partial_auth: false,
}
}
}

View File

@ -123,6 +123,9 @@ impl SecretsHandler for settings::ApiKeys {
.get_secret(api_keys.checksum_auth_key.clone())
.await?;
#[cfg(feature = "partial-auth")]
let enable_partial_auth = api_keys.enable_partial_auth;
Ok(value.transition_state(|_| Self {
hash_key,
#[cfg(feature = "email")]
@ -132,6 +135,8 @@ impl SecretsHandler for settings::ApiKeys {
checksum_auth_key,
#[cfg(feature = "partial-auth")]
checksum_auth_context,
#[cfg(feature = "partial-auth")]
enable_partial_auth,
}))
}
}

View File

@ -669,6 +669,9 @@ pub struct ApiKeys {
#[cfg(feature = "partial-auth")]
pub checksum_auth_key: Secret<String>,
#[cfg(feature = "partial-auth")]
pub enable_partial_auth: bool,
}
#[derive(Debug, Deserialize, Clone, Default)]

View File

@ -443,6 +443,14 @@ where
request_headers: &HeaderMap,
state: &A,
) -> RouterResult<(AuthenticationData, AuthenticationType)> {
let enable_partial_auth = state.conf().api_keys.get_inner().enable_partial_auth;
// This is a early return if partial auth is disabled
// Preventing the need to go through the header extraction process
if !enable_partial_auth {
return self.0.authenticate_and_fetch(request_headers, state).await;
}
let report_failure = || {
metrics::PARTIAL_AUTH_FAILURE.add(&metrics::CONTEXT, 1, &[]);
};