-
Notifications
You must be signed in to change notification settings - Fork 187
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
Add kerberos support #214
Add kerberos support #214
Conversation
Hi @psaiz, thanks for the contribution. A couple of thoughts. We need to get DCO check to pass, so could you sign off your commit with the I noticed you're importing We would need unit tests to make sure that this works for both sync and async connections. This ensures test compatibility. And it would be great if you could add this class to the |
Hi @harshavamsi, About adding kerberos as a dependency, what would you think about making it an optional dependency? I mean, the opensearch-py can still be used without kerberos. Pablo |
Hi again @harshavamsi, Regarding the testing, I'm not sure how to proceed. Note that to test it properly it requires a kerberos setup, and I'm afraid that won't be available during the pipelines. I've checked how it is done in the pykerberos, and they give a test.py file that should be run against their system. Is that what you have in mind? Cheers, |
At least exercise the code to some extent. Mock the kerberos setup. |
Hi @dblock, Best, |
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.
Close!
I made some other comments a bit more in-depth.
Thanks @dblock! I've addressed most of the comments. I left two open:
|
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.
I have some more. I know it's just a small piece of code, but let's get it right! Thanks for hanging in here with me.
Thanks @dblock ! I'm happy to do as many changes as are needed, so please, keep the comments coming. I left a reply in the three open discussions. Please, let me know if those are enough to resolve them. |
Thanks. See my two comments above, the unused variable is definitely a bug. |
@psaiz Have you considered just leveraging a standard Kerberos authentication library for requests like If you haven't, you should be able to use them this way: from opensearchpy import OpenSearch, RequestsHttpConnection
from requests_gssapi import HTTPSPNEGOAuth
opensearch = OpenSearch(
...,
connection_class=RequestsHttpConnection,
http_auth=HTTPSPNEGOAuth(),
) This is similar to the standard mechanism for authenticating with AWS IAM roles. Making dedicated Some of my personal projects are a port of requests-gssapi to HTTPX and adding Windows support to the Python |
Hi @aiudirog, thanks for the input. If that approach works, it is indeed much better than creating a new class. Let me play with it and see if it works in my case. |
Either way, I'd appreciate contributions to https://github.com/opensearch-project/opensearch-py/blob/main/GETTING_STARTED.md for this, please! We might also want to rename that to USER_GUIDE to match other clients, cc: @wbeckler - is there a campaign to standardize those things? |
Hi @aiudirog,
I get the error:
I've checked with different options, like Do you know what I'm doing wrong? |
Can you give the Edit: You can also give Edit 2: import logging
logging.basicConfig()
logging.getLogger('requests_gssapi').setLevel(logging.DEBUG) |
Hi @aiudirog , The
did the trick. And, once I knew the parameters for the mutual_authentication, I went back to
also worked. So, indeed, the new class makes no sense. Following the comment from @dblock, I'll change this MR to update the documentation. I was thinking about leaving in a test (mocking the calls), and the optional dependency for the python_requests. Please, let me know if you want me to remove those as well. |
Ready for a new round of review. Note that now, the changes are mainly on the documentation. I've just made sure that my source branch was up to date with the changes that have happened in the meantime. Please, do check the test. I'm not really happy with it. It works as an example of the code, However, it doesn't test much, since it mocks the call that does the connection. I checked if it would be better to mock something at a lower level (like the socket connect), but I didn't like that idea either. If you have any better ideas, I'm happy to look into that (or to drop the test completely if you prefer) |
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.
The docs are great, and I would be down with just merging that.
You correctly point out that the test doesn't quite test that the kerberos auth instance is actually called. What else does send
call? Is there a way to mock those other things? If it's too difficult, then I think we should just remove it. We don't need to test other people's code really, and I believe we already have tests for http_auth
being used (or we should have some).
Thanks @dblock, changes applied, and test removed |
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.
The only must have is schemas -> schemes (or methods). Schemas means something else.
Thanks for hanging in here with me! Really appreciate your help.
Thanks @dblock, ready for the next round |
Signed-off-by: Pablo Saiz <[email protected]>
Signed-off-by: Pablo Saiz <[email protected]>
Ok, sorry that I closed it. I've merged it with the changes that had happened in the mean time, and added a line to the Changelog, since one of the workflows was failing |
@harshavamsi @VachaShah 2nd pls? Let's merge this? |
Description
Provide kerberos authentication support to connect to clusters
Issues Resolved
This pull request creates a new connection class that extends the HTTP connection to support kerberos. Thanks to it, using the code below, the user can connect using kerberos for authentication:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.