-
Notifications
You must be signed in to change notification settings - Fork 3k
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
ntlm authentication #3419
ntlm authentication #3419
Conversation
Want to reuse the prompting options for ntlm.
|
@classmethod | ||
def authlib(cls): | ||
# Place holder for Authentication Class | ||
raise NotImplemented |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NotImplementedError
, NotImplemented
is something else ☺
otherwise wouldn't error until after user inputs un/pw
Added to allow the finally statement in main to run.
Thank you @xavfernandez and @Ivoz for the feedback. Implemented the requested changes. |
if HttpNtlmAuth is None: | ||
raise InstallationError( | ||
"Dependencies for Ntlm authentication are missing. Install " | ||
"dependencies via the `pip install pip['ntlm']` command." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pip[ntlm]
should be fine (without the quotes)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! fix and matched it to the upgrade message.
@@ -198,6 +203,31 @@ def parse_credentials(self, netloc): | |||
return userinfo, None | |||
return None, None | |||
|
|||
@classmethod |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since authlib
is only called on an instance AFAICT, I'm not sure why it needs to be a class method?
You could make it a @property
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially I intended to make it a class variable but had issues with the implementation and changed it a class method.
It can work as a function too; that is, no @property
. is the advantage to avoid the extra pair of parenthesis self.authlib()(....)
when it s being used?
We at least want some functional tests.
|
I been thinking about the tests for this; but I'll admit that my knowledge on testing libraries is very limited and basic. My struggle would be on setting up That aside, for the second test, I don' think the headers would be added until it receives a 401 error from the host. I was planning on basing the tests of the test for |
@vmuriart if you only have one or two Pythons installed, you can just run tox on the ones you have installed with or otherwise you can run just some particular tests using My mistake, 2nd test would probably be regarded unit (given functional is mostly testing pip run as a script). You can pass in username/password with |
Still trying to figure out how to write up the 2nd test. Not sure why i'm getting random fails on this last commit though. I'll take a look again tomorrow morning. |
Look like obnoxious network errors, I restarted those builds for you. |
42c843f
to
17cf0ea
Compare
As long as it wasn't me that broke it 😃 Though I think an Integrated tests for authentications may be needed. There aren't any tests against |
cfe3ca1
to
d586349
Compare
I think this should be vendored, precisely as we vendor requests itself. Otherwise the usual version interactions that we vendor requests to avoid, will be able to occur between our vendored version and requests_ntlm. Worse, someone behind an NTLM proxy will have no way to use pip to install the ntlm extra without presupposing the dependency is already installed. |
Could that be decided on at a later date? Depending on the usage of it, it could be vendored at a later time. |
Vendoring pywin32 is not possible, as it uses a C extension (and it's huge!) Could your PR be written to use ctypes?
I only have limited time to do tests (as I'm having to do this at work and it's not exactly core business activity :-)) so best is probably just put suggestions in the conversation here and I'll try stuff. It's slow, but I'll try to respond promptly (I'm on UK time, no idea how time differences may add to delays). |
The most basic test I can think at the moment. Using |
Apparently not :-( import requests
from requests_ntlm import HttpNtlmAuth
session = requests.Session()
session.auth = HttpNtlmAuth('DOMAIN\\USER','PASSWORD', session)
session.get('http://www.google.com') Although this code (which I got from the requests-ntlm page) doesn't include me setting my proxy anywhere, so I guess it's probably not the right code to use :-( Can you give me some sample code? Output (for what it's worth - I think all it demonstrates is that without going through the proxy, I can't get to the internet):
|
Never mind, I worked it out. Add the proxy data as per http://docs.python-requests.org/en/latest/user/advanced/#proxies and I get a successful response back from Google. |
progress! did it require it to use the |
@pfmoore unfortunately bundling I'm wondering if telling people to use something like Cntlm proxy which acts as a... proxy-proxy! :D is just easier. It's windows software they can just install. |
@Ivoz Looks like
I'm starting to incline towards the last option just because it keeps the authentication methods/code separate from |
Would an MIT License work ? I found this project that implemented their own ntlm module. |
Scratch that. The |
As @vmuriart this would likely raise flags with the security people. It basically means you have a proxy running on your PC that allows web access under your username. It runs as a service, so it's always running rather than just working for pip. Personally, I find that cntlm is a case of a cure being worse than the disease, unfortunately. (OTOH, how easy would it be to write a small proxy in pure Python with requests and requests_ntlm? If the code for that is simple enough, and it could be written to proxy only requests from pip, say by looking at the user agent string, then maybe that would be worthwhile workaround for "advanced" users, as it's totally in their control) BTW, @vmuriart have you checked whether the python-ntlm3 author would be willing to relicense? If she would, I still think that's the best option. |
I haven't checked yet. Though it was my understanding that w this license On Tuesday, February 2, 2016, Paul Moore notifications@github.com wrote:
|
@pfmoore
True, but only accessible by localhost. Not suddenly as a proxy broadcasting to the rest of the world. ntlmaps is another proxy with the same idea as Cntml, but written in python. OTOH, I have no idea why you think changing the language the intermediating proxy is in suddenly makes things ok. |
I wasn't aware of that fact, but I'm not 100% sure our security people would consider that a sufficient restriction.
There were two points:
But any locally-run proxy is likely to be a non-starter in my environment. For a long time I've been running the Forefront TMG Client, which works much like cntlm, but changes behind the scenes (that I'm not clear on, and have no way of finding out about) have resulted in that no longer working. Hence my interest in "native" NTLM support. Having said that, I think it's fair to say that my access to PyPI is no longer a good test case for this change - and the change is unlikely to help me anyway. Beyond that, my woes with corporate security rules are probably of little interest to anyone here :-) To summarise my position for the record:
|
I think all three points speak to why it needs to be vendored. #1182 describes the scenarios that most users that need ntlm have faced. While I focused on solving the I'll try to find another ntlm library, but for now sounds like we are at standstill. |
Cntlm can be run as a standard exe; it is not limited to only running as an always-on service. |
Can it? I didn't notice that option when I last tried it (it installed a service immediately from what I recall). I'll keep that in mind if I need to try it out as a possible workaround in future. |
@pfmoore I find that with my corporate firewall, curl can't get through if I specify the username explicitly, buy it works if I use the single colon option as per the manpage, ie |
Accidentally closed this, reopening. Sorry! |
Hello! As part of an effort to ease the contribution process and adopt a more standard workflow pip has switched to doing development on the If you do nothing, this Pull Request will be automatically migrated by @BrownTruck for you. If you would like to retain control over this pull request then you should resubmit it against the If you choose to migrate this Pull Request yourself, here is an example message that you can copy and paste:
If this pull request is no longer needed, please feel free to close it. |
This Pull Request has been automatically migrated to #3731 to reparent it to the |
Adding ntlm for #1182. Other authentication libraries can be added the same way (ie, kerberos)
The import statement was placed inside the method to only import when needed, and not cause an
ImportError
if package isn't installed.