How can I get a Kerberos ticket in Python

Keith Adler picture Keith Adler · Oct 23, 2014 · Viewed 9.2k times · Source

Is there a way to create a Kerberos ticket in Python if you know the username/password?

I have MIT Kerberos in place and I can do this interactively through KINIT but want to do it from Python.

Answer

Rafael Saraiva picture Rafael Saraiva · Oct 24, 2014

From what i learned when working with kerberos (although in my work i used C) is that you can hardly replace KINIT. There are two ways you can simulate KINIT behaviour using programming and those are: Calling kinit shell command from python with the appropriate arguments or (as I did) calling one method that pretty much does everything:

krb5_get_init_creds_password(k5ctx, &cred, k5princ, password, NULL, NULL, 0, NULL, NULL);

So this is a C primitive but you should find one for python(i assume) that will do the same. Basically this method will receive the kerberos session, a principal(built from the username) and the password. In order to fully replace KINIT behaviour you do need a bit more than this though(start session, build principal, etc). Sorry, since i did not work with python my answer may not be what you want but i hope i shed you some light. Feel free to ask any conceptual question about how kerberized-applications work.