{"id":15546722,"url":"https://github.com/pythongssapi/requests-gssapi","last_synced_at":"2025-04-06T15:12:52.433Z","repository":{"id":44948201,"uuid":"111729713","full_name":"pythongssapi/requests-gssapi","owner":"pythongssapi","description":" An authentication handler for using GSSAPI with Python Requests.  Drop-in replacement for old requests-kerberos.","archived":false,"fork":false,"pushed_at":"2024-04-12T09:00:53.000Z","size":171,"stargazers_count":32,"open_issues_count":6,"forks_count":21,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-10-09T13:13:34.279Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pythongssapi.png","metadata":{"files":{"readme":"README.rst","changelog":"HISTORY.rst","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-22T20:33:43.000Z","updated_at":"2024-05-26T15:52:55.000Z","dependencies_parsed_at":"2024-02-16T02:25:31.850Z","dependency_job_id":"48fb8cfe-fba6-4779-8e93-e3f8d3937dc3","html_url":"https://github.com/pythongssapi/requests-gssapi","commit_stats":{"total_commits":150,"total_committers":35,"mean_commits":4.285714285714286,"dds":0.7266666666666667,"last_synced_commit":"84e052b3fa4ffd00f81c067b27c70461e6494c76"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pythongssapi%2Frequests-gssapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pythongssapi%2Frequests-gssapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pythongssapi%2Frequests-gssapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pythongssapi%2Frequests-gssapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pythongssapi","download_url":"https://codeload.github.com/pythongssapi/requests-gssapi/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247500469,"owners_count":20948880,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T13:03:53.491Z","updated_at":"2025-04-06T15:12:52.403Z","avatar_url":"https://github.com/pythongssapi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"requests GSSAPI authentication library\n===============================================\n\nRequests is an HTTP library, written in Python, for human beings. This library\nadds optional GSSAPI authentication support and supports mutual\nauthentication.\n\nIt provides a fully backward-compatible shim for the old\npython-requests-kerberos library: simply replace ``import requests_kerberos``\nwith ``import requests_gssapi``.  A more powerful interface is provided by the\nHTTPSPNEGOAuth component, but this is of course not guaranteed to be\ncompatible.  Documentation below is written toward the new interface.\n\nBasic GET usage:\n\n\n.. code-block:: python\n\n    \u003e\u003e\u003e import requests\n    \u003e\u003e\u003e from requests_gssapi import HTTPSPNEGOAuth\n    \u003e\u003e\u003e r = requests.get(\"http://example.org\", auth=HTTPSPNEGOAuth())\n    ...\n\nThe entire ``requests.api`` should be supported.\n\nSetup\n-----\n\nIn order to use this library, there must already be a Kerberos Ticket-Granting\nTicket (TGT) in a credential cache (ccache).  Whether a TGT is available can\nbe easily determined by running the ``klist`` command.  If no TGT is\navailable, then it first must be obtained (for instance, by running the\n``kinit`` command, or pointing the $KRB5CCNAME to a credential cache with a\nvalid TGT).\n\nIn short, the library will handle the \"negotiations\" of Kerberos\nauthentication, but ensuring that a credentials are available and valid is the\nresponsibility of the user.\n\nAuthentication Failures\n-----------------------\n\nClient authentication failures will be communicated to the caller by returning\na 401 response.  A 401 response may also be the result of expired credentials\n(including the TGT).\n\nMutual Authentication\n---------------------\n\nMutual authentication is a poorly-named feature of the GSSAPI which doesn't\nprovide any additional security benefit to most possible uses of\nrequests_gssapi.  Practically speaking, in most mechanism implementations\n(including krb5), it requires another round-trip between the client and server\nduring the authentication handshake.  Many clients and servers do not properly\nhandle the authentication handshake taking more than one round-trip.  If you\nencounter a MutualAuthenticationError, this is probably why.\n\nSo long as you're running over a TLS link whose security guarantees you trust,\nthere's no benefit to mutual authentication.  If you don't trust the link at\nall, mutual authentication won't help (since it's not tamper-proof, and GSSAPI\nisn't being used post-authentication.  There's some middle ground between the\ntwo where it helps a small amount (e.g., passive adversary over\nencrypted-but-unverified channel), but for Negotiate (what we're doing here),\nit's not generally helpful.\n\nFor a more technical explanation of what mutual authentication actually\nguarantees, I refer you to rfc2743 (GSSAPIv2), rfc4120 (krb5 in GSSAPI),\nrfc4178 (SPNEGO), and rfc4559 (HTTP Negotiate).\n\n\nDISABLED\n^^^^^^^^\n\nBy default, there's no need to explicitly disable mutual authentication.\nHowever, for compatability with older versions of request_gssapi or\nrequests_kerberos, you can explicitly request it not be attempted:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e import requests\n    \u003e\u003e\u003e from requests_gssapi import HTTPSPNEGOAuth, DISABLED\n    \u003e\u003e\u003e gssapi_auth = HTTPSPNEGOAuth(mutual_authentication=DISABLED)\n    \u003e\u003e\u003e r = requests.get(\"https://example.org\", auth=gssapi_auth)\n    ...\n\nREQUIRED\n^^^^^^^^\n\nThis was historically the default, but no longer is.  If requested,\n``HTTPSPNEGOAuth`` will require mutual authentication from the server, and if\na server emits a non-error response which cannot be authenticated, a\n``requests_gssapi.errors.MutualAuthenticationError`` will be raised.  (See\nabove for what this means.)  If a server emits an error which cannot be\nauthenticated, it will be returned to the user but with its contents and\nheaders stripped.  If the response content is more important than the need for\nmutual auth on errors, (eg, for certain WinRM calls) the stripping behavior\ncan be suppressed by setting ``sanitize_mutual_error_response=False``:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e import requests\n    \u003e\u003e\u003e from requests_gssapi import HTTPSPNEGOAuth, REQUIRED\n    \u003e\u003e\u003e gssapi_auth = HTTPSPNEGOAuth(mutual_authentication=REQUIRED, sanitize_mutual_error_response=False)\n    \u003e\u003e\u003e r = requests.get(\"https://windows.example.org/wsman\", auth=gssapi_auth)\n    ...\n\nOPTIONAL\n^^^^^^^^\n\nThis will cause ``requests_gssapi`` to attempt mutual authentication if the\nserver advertises that it supports it, and cause a failure if authentication\nfails, but not if the server does not support it at all.  This is probably not\nwhat you want: link tampering will either cause hard failures, or silently\ncause it to not happen at all.  It is retained for compatability.\n\n.. code-block:: python\n\n    \u003e\u003e\u003e import requests\n    \u003e\u003e\u003e from requests_gssapi import HTTPSPNEGOAuth, OPTIONAL\n    \u003e\u003e\u003e gssapi_auth = HTTPSPNEGOAuth(mutual_authentication=OPTIONAL)\n    \u003e\u003e\u003e r = requests.get(\"https://example.org\", auth=gssapi_auth)\n    ...\n\nOpportunistic Authentication\n----------------------------\n\n``HTTPSPNEGOAuth`` can be forced to preemptively initiate the GSSAPI\nexchange and present a token on the initial request (and all\nsubsequent). By default, authentication only occurs after a\n``401 Unauthorized`` response containing a Negotiate challenge\nis received from the origin server. This can cause mutual authentication\nfailures for hosts that use a persistent connection (eg, Windows/WinRM), as\nno GSSAPI challenges are sent after the initial auth handshake. This\nbehavior can be altered by setting  ``opportunistic_auth=True``:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e import requests\n    \u003e\u003e\u003e from requests_gssapi import HTTPSPNEGOAuth\n    \u003e\u003e\u003e gssapi_auth = HTTPSPNEGOAuth(opportunistic_auth=True)\n    \u003e\u003e\u003e r = requests.get(\"https://windows.example.org/wsman\", auth=gssapi_auth)\n    ...\n\n`Expect-Continue`\n^^^^^^^^^^^^^^^^^\n\nSince `httplib \u003chttps://bugs.python.org/issue1346874\u003e`_ does not support the\n`Expect-Continue` header, a request with a body will fail with\n``401 Unauthorized`` and must be repeated with a GSSAPI exchange. This causes\nseveral issues:\n\n* Additional overhead for request retransmission\n* Requests with non-repeatable bodies will fail\n* Some servers will already send the approriate error response while your\n  client is still streaming the request. Not all reverse proxies can handle that\n  properly and will rather fail.\n\nTherefore, in such cases you must enable opportunistic authentication.\n\nHostname Override\n-----------------\n\nIf communicating with a host whose DNS name doesn't match its\nhostname (eg, behind a content switch or load balancer),\nthe hostname used for the GSSAPI exchange can be overridden by\npassing in a custom name (string or ``gssapi.Name``):\n\n.. code-block:: python\n\n    \u003e\u003e\u003e import requests\n    \u003e\u003e\u003e from requests_gssapi import HTTPSPNEGOAuth\n    \u003e\u003e\u003e gssapi_auth = HTTPSPNEGOAuth(target_name=\"internalhost.local\")\n    \u003e\u003e\u003e r = requests.get(\"https://externalhost.example.org/\", auth=gssapi_auth)\n    ...\n\nExplicit Principal\n------------------\n\n``HTTPSPNEGOAuth`` normally uses the default principal (ie, the user for whom\nyou last ran ``kinit`` or ``kswitch``, or an SSO credential if\napplicable). However, an explicit credential can be in instead, if desired.\n\n.. code-block:: python\n\n    \u003e\u003e\u003e import gssapi\n    \u003e\u003e\u003e import requests\n    \u003e\u003e\u003e from requests_gssapi import HTTPSPNEGOAuth\n    \u003e\u003e\u003e name = gssapi.Name(\"user@REALM\", gssapi.NameType.user)\n    \u003e\u003e\u003e creds = gssapi.Credentials(name=name, usage=\"initiate\")\n    \u003e\u003e\u003e gssapi_auth = HTTPSPNEGOAuth(creds=creds)\n    \u003e\u003e\u003e r = requests.get(\"http://example.org\", auth=gssapi_auth)\n    ...\n\nExplicit Mechanism\n------------------\n\n``HTTPSPNEGOAuth`` normally lets SPNEGO decide which negotiation mechanism to use.\nHowever, an explicit mechanism can be used instead if desired. The ``mech``\nparameter will be passed straight through to ``gssapi`` without interference.\nIt is expected to be an instance of ``gssapi.mechs.Mechanism``.\n\n.. code-block:: python\n\n    \u003e\u003e\u003e import gssapi\n    \u003e\u003e\u003e import requests\n    \u003e\u003e\u003e from requests_gssapi import HTTPSPNEGOAuth\n    \u003e\u003e\u003e try:\n    ...   krb5 = gssapi.mechs.Mechanism.from_sasl_name(\"GS2-KRB5\")\n    ... except AttributeError:\n    ...   krb5 = gssapi.OID.from_int_seq(\"1.2.840.113554.1.2.2\")\n    \u003e\u003e\u003e gssapi_auth = HTTPSPNEGOAuth(mech=krb5)\n    \u003e\u003e\u003e r = requests.get(\"http://example.org\", auth=gssapi_auth)\n    ...\n\nDelegation\n----------\n\n``requests_gssapi`` supports credential delegation (``GSS_C_DELEG_FLAG``).\nTo enable delegation of credentials to a server that requests delegation, pass\n``delegate=True`` to ``HTTPSPNEGOAuth``:\n\n.. code-block:: python\n\n    \u003e\u003e\u003e import requests\n    \u003e\u003e\u003e from requests_gssapi import HTTPSPNEGOAuth\n    \u003e\u003e\u003e r = requests.get(\"http://example.org\", auth=HTTPSPNEGOAuth(delegate=True))\n    ...\n\nBe careful to only allow delegation to servers you trust as they will be able\nto impersonate you using the delegated credentials.\n\nLogging\n-------\n\nThis library makes extensive use of Python's logging facilities.\n\nLog messages are logged to the ``requests_gssapi`` and\n``requests_gssapi.gssapi`` named loggers.\n\nIf you are having difficulty we suggest you configure logging. Issues with the\nunderlying GSSAPI libraries will be made apparent. Additionally, copious debug\ninformation is made available which may assist in troubleshooting if you\nincrease your log level all the way up to debug.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpythongssapi%2Frequests-gssapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpythongssapi%2Frequests-gssapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpythongssapi%2Frequests-gssapi/lists"}