Package: httpx-gssapi
HTTPX GSSAPI authentication libraryHTTPXis a full featured Python HTTP library with both sync and async APIs
designed to be a next generation HTTP client for Python. This library is a port
ofRequests GSSAPIto HTTPX which adds optional GSSAPI authentication support and
supports mutual authentication.Basic GET usage:>>>importhttpx>>>fromhttpx_gssapiimportHTTPSPNEGOAuth>>>r=httpx.get("http://example.org",auth=HTTPSPNEGOAuth())Both the sync and async HTTPX APIs should be fully supported.SetupIn order to use this library, there must already be a Kerberos Ticket-Granting
Ticket (TGT) in a credential cache (ccache).  Whether a TGT is available can
be easily determined by running theklistcommand.  If no TGT is
available, then it first must be obtained (for instance, by running thekinitcommand, or pointing the $KRB5CCNAME to a credential cache with a
valid TGT).In short, the library will handle the “negotiations” of Kerberos
authentication, but ensuring that a credentials are available and valid is the
responsibility of the user.Authentication FailuresClient authentication failures will be communicated to the caller by returning
a 401 response.  A 401 response may also be the result of expired credentials
(including the TGT).Mutual AuthenticationMutual authentication is a poorly-named feature of the GSSAPI which doesn’t
provide any additional security benefit to most possible uses of
httpx_gssapi.  Practically speaking, in most mechanism implementations
(including krb5), it requires another round-trip between the client and server
during the authentication handshake.  Many clients and servers do not properly
handle the authentication handshake taking more than one round-trip.  If you
encounter a MutualAuthenticationError, this is probably why.So long as you’re running over a TLS link whose security guarantees you trust,
there’s no benefit to mutual authentication.  If you don’t trust the link at
all, mutual authentication won’t help (since it’s not tamper-proof, and GSSAPI
isn’t being used post-authentication.  There’s some middle ground between the
two where it helps a small amount (e.g., passive adversary over
encrypted-but-unverified channel), but for Negotiate (what we’re doing here),
it’s not generally helpful.For a more technical explanation of what mutual authentication actually
guarantees, I refer you to rfc2743 (GSSAPIv2), rfc4120 (krb5 in GSSAPI),
rfc4178 (SPNEGO), and rfc4559 (HTTP Negotiate).DISABLEDBy default, there’s no need to explicitly disable mutual authentication.
However, for compatability with older versions of requests_gssapi or
requests_kerberos, you can explicitly request it not be attempted:>>>importhttpx>>>fromhttpx_gssapiimportHTTPSPNEGOAuth,DISABLED>>>gssapi_auth=HTTPSPNEGOAuth(mutual_authentication=DISABLED)>>>r=httpx.get("https://example.org",auth=gssapi_auth)...REQUIREDThis was historically the default, but no longer is.  If requested,HTTPSPNEGOAuthwill require mutual authentication from the server, and if
a server emits a non-error response which cannot be authenticated, ahttpx_gssapi.errors.MutualAuthenticationErrorwill be raised.  (See
above for what this means.)  If a server emits an error which cannot be
authenticated, it will be returned to the user but with its contents and
headers stripped.  If the response content is more important than the need for
mutual auth on errors, (eg, for certain WinRM calls) the stripping behavior
can be suppressed by settingsanitize_mutual_error_response=False:>>>importhttpx>>>fromhttpx_gssapiimportHTTPSPNEGOAuth,REQUIRED>>>gssapi_auth=HTTPSPNEGOAuth(mutual_authentication=REQUIRED,sanitize_mutual_error_response=False)>>>r=httpx.get("https://windows.example.org/wsman",auth=gssapi_auth)...OPTIONALThis will causehttpx_gssapito attempt mutual authentication if the
server advertises that it supports it, and cause a failure if authentication
fails, but not if the server does not support it at all.  This is probably not
what you want: link tampering will either cause hard failures, or silently
cause it to not happen at all.  It is retained for compatability.>>>importhttpx>>>fromhttpx_gssapiimportHTTPSPNEGOAuth,OPTIONAL>>>gssapi_auth=HTTPSPNEGOAuth(mutual_authentication=OPTIONAL)>>>r=httpx.get("https://example.org",auth=gssapi_auth)...Opportunistic AuthenticationHTTPSPNEGOAuthcan be forced to preemptively initiate the GSSAPI
exchange and present a token on the initial request (and all
subsequent). By default, authentication only occurs after a401 Unauthorizedresponse containing a Negotiate challenge
is received from the origin server. This can cause mutual authentication
failures for hosts that use a persistent connection (eg, Windows/WinRM), as
no GSSAPI challenges are sent after the initial auth handshake. This
behavior can be altered by settingopportunistic_auth=True:>>>importhttpx>>>fromhttpx_gssapiimportHTTPSPNEGOAuth,REQUIRED>>>gssapi_auth=HTTPSPNEGOAuth(mutual_authentication=REQUIRED,opportunistic_auth=True)>>>r=httpx.get("https://windows.example.org/wsman",auth=gssapi_auth)...Hostname OverrideIf communicating with a host whose DNS name doesn’t match its
hostname (eg, behind a content switch or load balancer),
the hostname used for the GSSAPI exchange can be overridden by
passing in a custom name (string orgssapi.Name):>>>importhttpx>>>fromhttpx_gssapiimportHTTPSPNEGOAuth,REQUIRED>>>gssapi_auth=HTTPSPNEGOAuth(target_name="internalhost.local")>>>r=httpx.get("https://externalhost.example.org/",auth=gssapi_auth)...Explicit PrincipalHTTPSPNEGOAuthnormally uses the default principal (ie, the user for whom
you last rankinitorkswitch, or an SSO credential if
applicable). However, an explicit credential can be in instead, if desired.>>>importgssapi>>>importhttpx>>>fromhttpx_gssapiimportHTTPSPNEGOAuth,REQUIRED>>>name=gssapi.Name("user@REALM",gssapi.NameType.hostbased_service)>>>creds=gssapi.Credentials(name=name,usage="initiate")>>>gssapi_auth=HTTPSPNEGOAuth(creds=creds)>>>r=httpx.get("http://example.org",auth=gssapi_auth)...Explicit MechanismHTTPSPNEGOAuthnormally lets the underlyinggssapilibrary decide which
negotiation mechanism to use. However, an explicit mechanism can be used instead
if desired. Themechparameter will be passed straight through togssapiwithout interference. It is expected to be an instance ofgssapi.mechs.Mechanism.>>>importgssapi>>>importhttpx>>>fromhttpx_gssapiimportHTTPSPNEGOAuth>>>try:...spnego=gssapi,mechs.Mechanism.from_sasl_name("SPNEGO")...exceptAttributeError:...spnego=gssapi.OID.from_int_seq("1.3.6.1.5.5.2")>>>gssapi_auth=HTTPSPNEGOAuth(mech=spnego)>>>r=httpx.get("http://example.org",auth=gssapi_auth)...Delegationhttpx_gssapisupports credential delegation (GSS_C_DELEG_FLAG).
To enable delegation of credentials to a server that requests delegation, passdelegate=TruetoHTTPSPNEGOAuth:>>>importhttpx>>>fromhttpx_gssapiimportHTTPSPNEGOAuth>>>r=httpx.get("http://example.org",auth=HTTPSPNEGOAuth(delegate=True))...Be careful to only allow delegation to servers you trust as they will be able
to impersonate you using the delegated credentials.LoggingThis library makes extensive use of Python’s logging facilities.Log messages are logged to thehttpx_gssapiandhttpx_gssapi.gssapinamed loggers.If you are having difficulty we suggest you configure logging. Issues with the
underlying GSSAPI libraries will be made apparent. Additionally, copious debug
information is made available which may assist in troubleshooting if you
increase your log level all the way up to debug.History0.1.0: 2021-01-27Fork project to httpx-gssapiReplace all requests handling to support HTTPXRemove HTTPKerberosAuth shim1.2.0: 2020-02-18Add support for specifing an explicit GSSAPI mech1.1.1: 2020-02-18Fix DOS bug around Negotiate regular expressoinUpdate README to include section on setup1.1.0: 2019-05-21Disable mutual authentication by defaultAdd more documentation on MutualAuthenticationError1.0.1: 2019-04-10Fix example in READMEFix license detection for PyPIFix a problem with regex escapingAdd COPR Makefile target1.0.0: 2017-12-14Fork project to requests-gssapiReplace pykerberos with python-gssapiAdd HTTPSPNEGOAuth interface.  HTTPKerberosAuth is retained as a shim, but
bump the major version anyway for clarity.0.11.0: 2016-11-02Switch dependency on Windows from kerberos-sspi/pywin32 to WinKerberos.
This brings Custom Principal support to Windows users.0.10.0: 2016-05-18Make it possible to receive errors without having their contents and headers
stripped.Resolve a bug caused by passing theprincipalkeyword argument to
kerberos-sspi on Windows.0.9.0: 2016-05-06Support for principal, hostname, and realm override.Added support for mutual auth.0.8.0: 2016-01-07Support for Kerberos delegation.Fixed problems declaring kerberos-sspi on Windows installs.0.7.0: 2015-05-04Added Windows native authentication support by adding kerberos-sspi as an
alternative backend.Prevent infinite recursion when a server returns 401 to an authorization
attempt.Reduce the logging during successful responses.0.6.1: 2014-11-14Fix HTTPKerberosAuth not to treat non-file as a filePrevent infinite recursion when GSSErrors occurs0.6: 2014-11-04Handle mutual authentication (see pull request36)All users should upgrade immediately. This has been reported tooss-securityand we are awaiting a proper CVE identifier.Update: We were issued CVE-2014-8650Distribute as a wheel.0.5: 2014-05-14Allow non-HTTP service principals with HTTPKerberosAuth using a new optional
argumentservice.Fix bug insetup.pyon distributions where thecompilermodule is
not available.Add test dependencies tosetup.pysopython setup.py testwill work.0.4: 2013-10-26Minor updates in the READMEChange requirements to depend on requests above 1.1.00.3: 2013-06-02Work with servers operating on non-standard ports0.2: 2013-03-26Not documented0.1: Never releasedInitial Release