Specifying KRB5CCNAME #309
Replies: 6 comments 4 replies
-
It just calls the C api so you can specify the env var |
Beta Was this translation helpful? Give feedback.
-
Hi Jordan, I am calling two API. One is gssapi.raw.acquire_cred_with_password and the other is gssapi.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 the gssapi.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?
|
Beta Was this translation helpful? Give feedback.
-
The python-gssapi/gssapi/tests/test_raw.py Lines 472 to 473 in b056666 A few more things to point out
So for this to work you need to do import os
import gssapi
username = '...'
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').creds
if krb5ccname := os.environ.get('KRB5CCNAME', None):
store = {
'ccache': f'FILE:{krb5ccname}',
}
gssapi.raw.ext_cred_store.store_cred_into(store, creds, overwrite=True)
... |
Beta Was this translation helpful? Give feedback.
-
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):
|
Beta Was this translation helpful? Give feedback.
-
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 with https://github.com/jborean93/pykrb5. if you didn't need to persist the TGT then why are you wanting to call An example of |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
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?
Beta Was this translation helpful? Give feedback.
All reactions