Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1689908

Summary: crash if old ccache is left from earlier deployment
Product: Red Hat Enterprise Linux 8 Reporter: Kaleem <ksiddiqu>
Component: ipaAssignee: IPA Maintainers <ipa-maint>
Status: CLOSED DEFERRED QA Contact: ipa-qe <ipa-qe>
Severity: low Docs Contact:
Priority: unspecified    
Version: 8.0CC: abokovoy, cheimes, pasik, pcech, pvoborni, rcritten, tscherf, twoerner
Target Milestone: rcFlags: pm-rhel: mirror+
Target Release: 8.2   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-05-26 04:41:59 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Kaleem 2019-03-18 12:21:30 UTC
Description of problem:

Following crash is seen when old ccache is left from earlier IPA deployment

http://faf.lab.eng.brq.redhat.com/faf/reports/10838/


Version-Release number of selected component (if applicable):
[root@ad-test ~]# rpm -q ipa-server
ipa-server-4.7.1-11.module+el8+2842+7481110c.x86_64
[root@ad-test ~]# 


How reproducible:
Always

Steps to Reproduce:
1. Establish a one-way trust with an AD env
2. Remove one trust
3. Establish a one-way trust again with another AD env

Actual results:
Crash is seen

Expected results:
There should be no crash 

Additional info:

Comment 1 Alexander Bokovoy 2019-03-18 12:32:06 UTC
For convenience, the reported unhandled python exception is this:

ext_cred_store.pyx:182: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

Traceback (most recent call last):
  File "/usr/libexec/ipa/oddjob/com.redhat.idm.trust-fetch-domains", line 129, in <module>
    cred = kinit_keytab(principal, keytab_name, ccache_name)
  File "/usr/lib/python3.6/site-packages/ipalib/install/kinit.py", line 47, in kinit_keytab
    cred = gssapi.Credentials(name=name, store=store, usage='initiate')
  File "/usr/local/lib64/python3.6/site-packages/gssapi/creds.py", line 64, in __new__
    store=store)
  File "/usr/local/lib64/python3.6/site-packages/gssapi/creds.py", line 148, in acquire
    usage)
  File "gssapi/raw/ext_cred_store.pyx", line 182, 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

Local variables in innermost frame:
__name__: 'gssapi.raw.ext_cred_store'
__doc__: 'Credential Store Extension'
__package__: 'gssapi.raw'
__loader__: <_frozen_importlib_external.ExtensionFileLoader object at 0x7f4d8eb82320>
__spec__: ModuleSpec(name='gssapi.raw.ext_cred_store', loader=<_frozen_importlib_external.ExtensionFileLoader object at 0x7f4d8eb82320>, origin='/usr/local/lib64/python3.6/site-packages/gssapi/raw/ext_cred_store.cpython-36m-x86_64-linux-gnu.so')
__builtins__: <module 'builtins' (built-in)>
GSSAPI: 'BASE'
namedtuple: <function namedtuple at 0x7f4da78291e0>
AddCredResult: <class 'gssapi.raw.named_tuples.AddCredResult'>
AcquireCredResult: <class 'gssapi.raw.named_tuples.AcquireCredResult'>
StoreCredResult: <class 'gssapi.raw.named_tuples.StoreCredResult'>
GSSError: <class 'gssapi.raw.misc.GSSError'>
acquire_cred_from: <built-in function acquire_cred_from>
add_cred_from: <built-in function add_cred_from>
store_cred_into: <built-in function store_cred_into>
__test__: {}
__file__: '/usr/local/lib64/python3.6/site-packages/gssapi/raw/ext_cred_store.cpython-36m-x86_64-linux-gnu.so'

The reason it happened is because we have the following code in the oddjob helper:
---------------------
keytab_name = '/etc/samba/samba.keytab'

principal = str('cifs/' + api.env.host)

oneway_ccache_name = '/var/run/ipa/krb5cc_oddjob_trusts_fetch'
ccache_name = '/var/run/ipa/krb5cc_oddjob_trusts'

# Standard sequence:
# - check if ccache exists
#   - if not, initialize it from Samba's keytab
# - check if ccache contains valid TGT
#   - if not, initialize it from Samba's keytab
# - refer the correct ccache object for further use
#
have_ccache = False
try:
    cred = kinit_keytab(principal, keytab_name, ccache_name)
    if cred.lifetime > 0:
        have_ccache = True
except gssapi.exceptions.ExpiredCredentialsError:
    pass
if not have_ccache:
    # delete stale ccache and try again
    if os.path.exists(oneway_ccache_name):
        os.unlink(ccache_name)
    cred = kinit_keytab(principal, keytab_name, ccache_name)
---------------------

if kinit_keytab() raises any other exception, we fail to delete stale ccache because we never reach that code path.

On the test system we had
[root@ad-test ~]# klist -k -t /etc/samba/samba.keytab 
Keytab name: FILE:/etc/samba/samba.keytab
KVNO Timestamp           Principal
---- ------------------- ------------------------------------------------------
   1 07.03.2019 04.01.14 cifs/ad-test.testrelm.test
   1 07.03.2019 04.01.14 cifs/ad-test.testrelm.test
[root@ad-test ~]# ll /var/run/ipa/krb5cc_oddjob_trusts
-rw-------. 1 root root 1845 26. 2. 01:01 /var/run/ipa/krb5cc_oddjob_trusts
[root@ad-test ~]# klist -c /var/run/ipa/krb5cc_oddjob_trusts
Ticket cache: FILE:/var/run/ipa/krb5cc_oddjob_trusts
Default principal: cifs/ad-test.trustcli16.test

Valid starting       Expires              Service principal
26.02.2019 01.01.11  27.02.2019 01.01.11  krbtgt/TRUSTCLI16.TEST


So there was stale ccache from old installation which used completely different Kerberos realm, thus the issue reported by gssapi code.

A solution is to treat all gssapi errors during kinit as a sign that we should clean up the stale ccache.

Comment 6 Petr Čech 2020-05-26 04:39:43 UTC
Upstream ticket:
https://pagure.io/freeipa/issue/8333

Comment 7 Petr Čech 2020-05-26 04:41:59 UTC
Once the upstream community implements this feature it will be pulled into a corresponding Red Hat Enterprise Linux release following the corresponding schedules.
From now on this issue will be tracked in the community issue tracker only.
Closing this BZ.