]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Refresh manually acquired creds from client keytab 1044/head
authorRobbie Harwood <rharwood@redhat.com>
Wed, 26 Feb 2020 23:27:17 +0000 (18:27 -0500)
committerGreg Hudson <ghudson@mit.edu>
Tue, 3 Mar 2020 03:27:20 +0000 (22:27 -0500)
If a client keytab is present but credentials are acquired manually,
the credentials would not be refreshed because no refresh_time config
var is set in the cache.  Change kg_cred_time_to_refresh() to attempt
a refresh from the client keytab on any credentials which will expire
in the next 30 seconds.

[ghudson@mit.edu: adjused code and added test case]

ticket: 7976

src/lib/gssapi/krb5/acquire_cred.c
src/tests/gssapi/t_client_keytab.py

index acc1868f85d2314ed85fc23943184cb57798f10d..4062f4741bfb756b20ca46bf5ba2160e15377e6b 100644 (file)
@@ -557,15 +557,23 @@ set_refresh_time(krb5_context context, krb5_ccache ccache,
 krb5_boolean
 kg_cred_time_to_refresh(krb5_context context, krb5_gss_cred_id_rec *cred)
 {
-    krb5_timestamp now;
+    krb5_timestamp now, soon;
 
     if (krb5_timeofday(context, &now))
         return FALSE;
+    soon = ts_incr(now, 30);
     if (cred->refresh_time != 0 && !ts_after(cred->refresh_time, now)) {
-        set_refresh_time(context, cred->ccache,
-                         ts_incr(cred->refresh_time, 30));
+        set_refresh_time(context, cred->ccache, soon);
         return TRUE;
     }
+
+    /* If the creds will expire soon, try to refresh even if they weren't
+     * acquired with a client keytab. */
+    if (ts_after(soon, cred->expire)) {
+        set_refresh_time(context, cred->ccache, soon);
+        return TRUE;
+    }
+
     return FALSE;
 }
 
index e474a27c7bcd0a65b80bc65b4a8e4b181ffa8e2c..7847b3ecd8acfefb6a49446959d934d080f43f7b 100755 (executable)
@@ -124,4 +124,22 @@ realm.kinit(realm.user_princ, password('user'))
 realm.run(['./t_ccselect', phost], env=bad_cktname,
           expected_msg=realm.user_princ)
 
+mark('refresh of manually acquired creds')
+
+# Test 17: no name/ccache specified, manually acquired creds which
+# will expire soon.  Verify that creds are refreshed using the current
+# client name, with refresh_time set in the refreshed ccache.
+realm.kinit('bob', password('bob'), ['-l', '15s'])
+realm.run(['./t_ccselect', phost], expected_msg='bob')
+realm.run([klist, '-C'], expected_msg='refresh_time = ')
+
+# Test 18: no name/ccache specified, manually acquired creds with a
+# client principal not present in the client keytab.  A refresh is
+# attempted but fails, and an expired ticket error results.
+realm.kinit(realm.admin_princ, password('admin'), ['-l', '-1s'])
+msgs = ('Getting initial credentials for user/admin@KRBTEST.COM',
+        '/Matching credential not found')
+realm.run(['./t_ccselect', phost], expected_code=1,
+          expected_msg='Ticket expired', expected_trace=msgs)
+
 success('Client keytab tests')