- Notifications
You must be signed in to change notification settings - Fork52
Specifying KRB5CCNAME#309
-
It looks like by default python-gssapi create a ticket cache located in API:xxxxxxx. Is there a way to tell python-gssapi to create the ticket in a specific folder? |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 6 comments 4 replies
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
It just calls the C api so you can specify the env var |
BetaWas this translation helpful?Give feedback.
All reactions
-
Hi Jordan, I am calling two API. One isgssapi.raw.acquire_cred_with_password and the other isgssapi.SecurityContext. I'm thinking that the first API is the one generating the ticket. I can easily supply the KRBCCNAME env variable (I do that for other apps using the KRB5 library). I am doing this in Docker because the I believe it is expecting to look for the ticket cache in a "temp/" folder. So I need to tell to use a specific one since. If I run this within Pycharm I don't need to do anything, but when I put it in a container, it can't find the ticket. I have a separate python file called kerberos.py (below). You can see the commented out lines where I was trying to use thegssapi.raw.ext_cred_store.store_cred_into API, obviously I don't know what I'm doing! This was from an example I found online, I think it might be yours? |
BetaWas this translation helpful?Give feedback.
All reactions
-
The python-gssapi/gssapi/tests/test_raw.py Lines 472 to 473 inb056666
A few more things to point out
So for this to work you need to do importosimportgssapiusername='...'password='...'user=gssapi.Name(base=username,name_type=gssapi.NameType.user)bpass=password.encode('utf-8')creds=gssapi.raw.acquire_cred_with_password(user,bpass,usage='initiate').credsifkrb5ccname:=os.environ.get('KRB5CCNAME',None):store= {'ccache':f'FILE:{krb5ccname}', }gssapi.raw.ext_cred_store.store_cred_into(store,creds,overwrite=True)... |
BetaWas this translation helpful?Give feedback.
All reactions
-
I gave this a try today and I am running into this issue: gssapi.raw.ext_cred_store.store_cred_into(store, creds, overwrite=True) I commented out the AttributeError catch block and let the code fall through to the next general exception catch. That's how I got the details above. I've checked the docs and there indeed is an 'ext_cred_store' attribute. Do I need to import something else? Here's the code I used: def kinit(username=None, password=None, realm=None, exe=None, keytab=None, verbose=False): |
BetaWas this translation helpful?Give feedback.
All reactions
-
This means that your GSSAPI C library doesn't have the extension methods present so you won't be able to call it in python-gssapi. There's little that we can do about that unfortunately. If the C library doesn't have it Python can't call it. I believe this has only been recently added to Heimdal based GSSAPI libs but that hasn't made it into an actual release. Considering your default is Unfortunately your options are limited, if you really need to persist the credentials to a file you might be better off using the krb5 APIs directly withhttps://github.com/jborean93/pykrb5. if you didn't need to persist the TGT then why are you wanting to call An example of |
BetaWas this translation helpful?Give feedback.
All reactions
-
Hi Jordan, |
BetaWas this translation helpful?Give feedback.
All reactions
-
But if you are using an explicit credential at runtime you don't need to store the TGT at all. You have an in memory credential acquired by |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
The main reason I am trying to assert some kind of control is that within a container it doesn't seem to work. Like I said, outside of a Docker container it works great (using memory credential). But when that same code is running within a Docker container, it doesn't know where to find the ticket. I get an error like this. Note that it is looking for the ticket in FILE:/tmp/krbcc_0. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Ah ok I think I see now, you don't control the code that creates the security context so you can't provide it the credentials retrieved from
|
BetaWas this translation helpful?Give feedback.
All reactions
-
Yeah, it's not the end of the working to call kinit as a sub-process, but requires I install kinit into the container. Also, not a big deal. All I'm trying to solve for now is to be able to use a service account to make connections to the db and that requires kerberos. It's the curse of working in a serverless environment. The containers (in AWS) are not domain-joined so they have no awareness of AD/KDC. You have to do this manually. With Fargate, which allows multiple containers to run in the same task, I use a sidecar that does all the KDC Auth and brings the TGT back to the container and shares the ticket with the application container. Unfortunately the new service I am using, AWS Batch, only a single container to run so that's what I am trying to create now: one image that get an ticket for a given service principal and password, and then running some processing against a SQL Server db (uses a trusted connection) then exiting the container. |
BetaWas this translation helpful?Give feedback.