pub struct AuthManager { /* private fields */ }Expand description
Credential manager for handling authentication.
Defaults to a strict security posture:
CertificateConfig::Strict— certificates are validated by libgit2 against the system trust store; a cert that fails verification rejects the fetch. The previous always-CertificateOkbehavior is gone.AuthMode::ExplicitOnly— ambient credential discovery (AuthStrategy::Default, i.e. the git credential helper,~/.gitconfig, SSH agent fallback) is refused unless the caller explicitly opts in viaAuthManager::with_auth_mode(AllowAmbient).RedirectPolicy::None— callers that build their owngit2::FetchOptionsfrom this manager’sAuthManager::create_callbacksmust also applyAuthManager::redirect_policyviaRedirectPolicy::to_git2/FetchOptions::follow_redirects. libgit2’s own default (RemoteRedirect::Initial) allows an off-site redirect on the initial request, and — per the pinned libgit2 1.9.x behavior — the credential callback still receives the original request URL after that redirect, not the effective peer. Combined with a host-scopedAuthStrategy::Token, that would let a credential bound to host A be offered to a redirect target host B. See issue #1429 Sol P1.
Implementations§
Source§impl AuthManager
impl AuthManager
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new authentication manager with no strategies, strict
certificate validation, ExplicitOnly auth mode, and no off-site
redirects.
Sourcepub fn with_strategies(strategies: Vec<AuthStrategy>) -> Self
pub fn with_strategies(strategies: Vec<AuthStrategy>) -> Self
Create authentication manager with strategies. Certificate validation
defaults to strict, auth mode to ExplicitOnly, and redirect policy to
no off-site redirects.
Sourcepub fn with_certificate_mode(self, mode: CertificateConfig) -> Self
pub fn with_certificate_mode(self, mode: CertificateConfig) -> Self
Set the certificate validation mode.
Sourcepub fn with_auth_mode(self, mode: AuthMode) -> Self
pub fn with_auth_mode(self, mode: AuthMode) -> Self
Set the authentication provenance mode.
Sourcepub fn with_redirect_policy(self, policy: RedirectPolicy) -> Self
pub fn with_redirect_policy(self, policy: RedirectPolicy) -> Self
Set the off-site redirect policy. Defaults to RedirectPolicy::None.
Callers driving a real git2::FetchOptions from this manager must
apply the result of AuthManager::redirect_policy via
follow_redirects — this struct only carries the decision; it does
not own a FetchOptions to enforce it against (see
crate::clone_options for the send-safe path that does).
Sourcepub fn redirect_policy(&self) -> RedirectPolicy
pub fn redirect_policy(&self) -> RedirectPolicy
Get the configured off-site redirect policy.
Sourcepub fn add_strategy(&mut self, strategy: AuthStrategy)
pub fn add_strategy(&mut self, strategy: AuthStrategy)
Add an authentication strategy
Sourcepub fn create_callbacks(&self) -> RemoteCallbacks<'_>
pub fn create_callbacks(&self) -> RemoteCallbacks<'_>
Create remote callbacks with authentication and certificate handling.
Security posture:
- Under
Strict(default) the certificate callback returnsCertificatePassthrough, deferring to libgit2’s built-in verification. It never returnsCertificateOkunconditionally, so an invalid or untrusted certificate fails the fetch. - Under
ExplicitOnly(default)AuthStrategy::Defaultis skipped, so ambient credential sources are not consulted.
Sourcepub fn strategy_count(&self) -> usize
pub fn strategy_count(&self) -> usize
Get the number of configured strategies (for testing)
Sourcepub fn certificate_mode(&self) -> CertificateConfig
pub fn certificate_mode(&self) -> CertificateConfig
Get the configured certificate validation mode.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AuthManager
impl RefUnwindSafe for AuthManager
impl Send for AuthManager
impl Sync for AuthManager
impl Unpin for AuthManager
impl UnsafeUnpin for AuthManager
impl UnwindSafe for AuthManager
Blanket Implementations§
§impl<T> AnySync for T
impl<T> AnySync for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more