Skip to content

Add Kerberos support for authentication with a flag (and appropriate dependencies being available) #11090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
08dc580
Add requests_kerberos as vendored package.
cryvate Nov 11, 2017
c936e14
Add kerberos support for authentication in sending requests.
cryvate Nov 11, 2017
87086bd
Add news entry for kerberos authentication
cryvate Nov 11, 2017
e6ce814
Add news item vendoring requests_kerberos.
cryvate Nov 11, 2017
f9391d3
Add documentation on Kerberos authentication feature.
cryvate Nov 14, 2017
6db53d1
Merge remote-tracking branch 'upstream/master'. Conflicts resolved by…
cryvate Sep 26, 2018
a8e46ef
Merge branch 'master' of https://github.com/pypa/pip
cryvate Jan 23, 2019
5965c29
Fix a few oopsies in last commit
cryvate Jan 23, 2019
dc3936b
remove linebreak introduced by hard word-wrapping
cryvate Jan 23, 2019
37fb3cf
Merge remote-tracking branch 'upstream/master'
cryvate Aug 26, 2019
84f62ad
Fix linter
cryvate Aug 26, 2019
e58196c
Merge remote-tracking branch 'upstream/master'
cryvate Jan 21, 2020
f717353
Merge remote-tracking branch 'upstream/main'
cryvate May 5, 2022
12e2840
Update vendoring
cryvate May 5, 2022
b5bd385
Improve docs
cryvate May 5, 2022
e069cb5
Better docs
cryvate May 5, 2022
fedf206
Improve docs
cryvate May 6, 2022
f53e289
Make things work?
cryvate May 6, 2022
33938dd
Fix up things
cryvate May 6, 2022
910b8a7
Make mypy happy
cryvate May 6, 2022
e2e1ba4
Satisfy vendoring
cryvate May 6, 2022
e8f8dbe
Remove vendoring
cryvate May 6, 2022
d966b5a
Remove vendoring artefacts
cryvate May 6, 2022
02cdfbf
Remove vendoring artefacts
cryvate May 6, 2022
a1049e4
Level has changed
cryvate May 6, 2022
3c24f5b
Use new PR number
cryvate May 6, 2022
c8142af
Set start
cryvate May 6, 2022
8199d81
Fix code
cryvate May 6, 2022
5acc560
Simplify
cryvate May 6, 2022
1d96d55
Simplify more
cryvate May 6, 2022
647a4f4
Don't cargo cult unnecessary changes in logging.py
cryvate Jun 6, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/html/cli/pip_install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,28 @@ overridden by using ``--cert`` option or by using ``PIP_CERT``,
``REQUESTS_CA_BUNDLE``, or ``CURL_CA_BUNDLE`` environment variables.


.. _`Kerberos Authentication`:

Kerberos Authentication
-----------------------

Starting with vXX.X, pip supports using a Kerberos ticket to authenticate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: need to fix this before merge.

with servers. To use Kerberos one must:

- Install ``requests_kerberos`` into the same environment as ``pip`` (tested with 0.14.0).
- Run ``pip`` with the flag ``--enable-kerberos``. Your system administrator
can also set this in the config files or an environment variable, see
:ref:`Configuration`.
- Have a valid Kerberos ticket.

Note that setting this flag *enforces* the connection uses Kerberos.

Bugs reported with pip in relation to Kerberos will likely not
be addressed directly by pip's maintainers. Pull Requests to fix Kerberos
only bugs will be considered, and merged (subject to normal review processes).
Note that there may be delays due to the lack of developer resources for
reviewing such pull requests.

.. _`Caching`:

Caching
Expand Down
1 change: 1 addition & 0 deletions news/11090.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add kerberos support for authentication with the ``--enable-kerberos`` flag.
11 changes: 11 additions & 0 deletions src/pip/_internal/cli/cmdoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,16 @@ class PipOption(Option):
help="Disable prompting for input.",
)

enable_kerberos: Callable[..., Option] = partial(
Option,
# Enable kerberos
"--enable-kerberos",
dest="enable_kerberos",
action="store_true",
default=False,
help="Enable Kerberos authentication.",
)

proxy: Callable[..., Option] = partial(
Option,
"--proxy",
Expand Down Expand Up @@ -1027,6 +1037,7 @@ def check_list_path_option(options: Values) -> None:
quiet,
log,
no_input,
enable_kerberos,
proxy,
retries,
timeout,
Expand Down
1 change: 1 addition & 0 deletions src/pip/_internal/cli/req_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def _build_session(
retries=retries if retries is not None else options.retries,
trusted_hosts=options.trusted_hosts,
index_urls=self._get_index_urls(options),
enable_kerberos=options.enable_kerberos,
)

# Handle custom ca-bundles from the user
Expand Down
18 changes: 17 additions & 1 deletion src/pip/_internal/network/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ def __init__(
cache: Optional[str] = None,
trusted_hosts: Sequence[str] = (),
index_urls: Optional[List[str]] = None,
enable_kerberos: bool = False,
**kwargs: Any,
) -> None:
"""
Expand All @@ -281,8 +282,23 @@ def __init__(
# Attach our User Agent to the request
self.headers["User-Agent"] = user_agent()

no_prompt = MultiDomainBasicAuth(prompting=False, index_urls=index_urls)
prompt = MultiDomainBasicAuth(prompting=True, index_urls=index_urls)
prompt.passwords = no_prompt.passwords # share same dict of passwords

# Attach our Authentication handler to the session
self.auth = MultiDomainBasicAuth(index_urls=index_urls)
if enable_kerberos:
try:
from requests_kerberos import REQUIRED, HTTPKerberosAuth
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have a benchmark of this import? If it is relatively quick, we should probably just always enable Kerberos whenever requests_kerberos is present in the environment, similar to how we handle keyring support.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this to minimise this change having any impact on existing users that do not wish or want this support. E.g. one could imagine requests_kerberos ends up raising something that is not ImportError (for whatever reason) and then this code would fail. I think going more defensive is not the way (we would want this to bubble up), but we do not want this impacting users that don't want to use kerberos (with pip).

except ImportError:
logger.critical(
"Are you sure you `requests_kerberos` and its dependencies "
"are available in the same environment as pip?"
)
raise
self.auth = HTTPKerberosAuth(REQUIRED)
else:
self.auth = MultiDomainBasicAuth(index_urls=index_urls)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that we can’t use Basic Auth when Kerberos is enabled, or does requests_kerberos handle Basic Auth for us?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct. My previous PR (see OP) did allow this but it requires a bunch more code to be added.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not work in a Kerberos environment anymore, so I am not sure how likely it is people (or CICD) are to use/want this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ll OK with adding the feature, if someone’s willing to work on it (I don’t use Kerberos either). Let’s keep this open so someone can pick it up if they’re interested.


# Create our urllib3.Retry instance which will allow us to customize
# how we handle retries.
Expand Down