krbcontext / python-krbcontext

A Kerberos context manager
https://krbcontext.github.io/
GNU General Public License v3.0
25 stars 10 forks source link

Uncaught exception trying to obtain pre-existing credentials with Keytab Auth #37

Open bendemott opened 3 years ago

bendemott commented 3 years ago

The code near line 156 in context.py attempts to get existing credentials before it creates a temporary credentials cache for keytab auth.

creds = gssapi.creds.Credentials(**creds_opts)

The above line triggers the following error:

File "/usr/local/lib/python3.7/dist-packages/krbcontext-0.10-py3.7.egg/krbcontext/context.py", line 156, in init_with_keytab
  File "/usr/local/lib/python3.7/dist-packages/gssapi-1.6.12-py3.7-linux-x86_64.egg/gssapi/creds.py", line 64, in __new__
    store=store)
  File "/usr/local/lib/python3.7/dist-packages/gssapi-1.6.12-py3.7-linux-x86_64.egg/gssapi/creds.py", line 148, in acquire
    usage)
  File "gssapi/raw/ext_cred_store.pyx", line 186, in gssapi.raw.ext_cred_store.acquire_cred_from
gssapi.raw.misc.GSSError: Major (851968): Unspecified GSS failure.  Minor code may provide more information, Minor (39756032): Principal in credential cache does not match desired name

You can recreate this error by simply:

This error occurs because when gssapi looks into the existing cache with a credential of user and cannot find user2. There just needs to be a try/catch around this line to resolve the issue.

tkdchen commented 3 years ago

Hi @bendemott

After rethinking of this issue, IMO, this error should be an actual problem you should have to handle. That means, krbContext should not overwrite an existing credential which has a valid ticket with different principal. This could avoid any potential problem due to the change to the credential by accident.