Blame SOURCES/Refresh-manually-acquired-creds-from-client-keytab.patch

9c4c6b
From fdd97fe6c9f0a3a6ff8d2580ca9f3c46826449b7 Mon Sep 17 00:00:00 2001
9c4c6b
From: Robbie Harwood <rharwood@redhat.com>
9c4c6b
Date: Wed, 26 Feb 2020 18:27:17 -0500
9c4c6b
Subject: [PATCH] Refresh manually acquired creds from client keytab
9c4c6b
9c4c6b
If a client keytab is present but credentials are acquired manually,
9c4c6b
the credentials would not be refreshed because no refresh_time config
9c4c6b
var is set in the cache.  Change kg_cred_time_to_refresh() to attempt
9c4c6b
a refresh from the client keytab on any credentials which will expire
9c4c6b
in the next 30 seconds.
9c4c6b
9c4c6b
[ghudson@mit.edu: adjused code and added test case]
9c4c6b
9c4c6b
ticket: 7976
9c4c6b
(cherry picked from commit 729896467e3c77904666019d6cbbda583ae49b95)
9c4c6b
(cherry picked from commit 685aada9eae420cb5156ca7b71c2c7614c0b6e2c)
9c4c6b
---
9c4c6b
 src/lib/gssapi/krb5/acquire_cred.c  | 14 +++++++++++---
9c4c6b
 src/tests/gssapi/t_client_keytab.py | 18 ++++++++++++++++++
9c4c6b
 2 files changed, 29 insertions(+), 3 deletions(-)
9c4c6b
9c4c6b
diff --git a/src/lib/gssapi/krb5/acquire_cred.c b/src/lib/gssapi/krb5/acquire_cred.c
9c4c6b
index acc1868f8..4062f4741 100644
9c4c6b
--- a/src/lib/gssapi/krb5/acquire_cred.c
9c4c6b
+++ b/src/lib/gssapi/krb5/acquire_cred.c
9c4c6b
@@ -557,15 +557,23 @@ set_refresh_time(krb5_context context, krb5_ccache ccache,
9c4c6b
 krb5_boolean
9c4c6b
 kg_cred_time_to_refresh(krb5_context context, krb5_gss_cred_id_rec *cred)
9c4c6b
 {
9c4c6b
-    krb5_timestamp now;
9c4c6b
+    krb5_timestamp now, soon;
9c4c6b
 
9c4c6b
     if (krb5_timeofday(context, &now))
9c4c6b
         return FALSE;
9c4c6b
+    soon = ts_incr(now, 30);
9c4c6b
     if (cred->refresh_time != 0 && !ts_after(cred->refresh_time, now)) {
9c4c6b
-        set_refresh_time(context, cred->ccache,
9c4c6b
-                         ts_incr(cred->refresh_time, 30));
9c4c6b
+        set_refresh_time(context, cred->ccache, soon);
9c4c6b
         return TRUE;
9c4c6b
     }
9c4c6b
+
9c4c6b
+    /* If the creds will expire soon, try to refresh even if they weren't
9c4c6b
+     * acquired with a client keytab. */
9c4c6b
+    if (ts_after(soon, cred->expire)) {
9c4c6b
+        set_refresh_time(context, cred->ccache, soon);
9c4c6b
+        return TRUE;
9c4c6b
+    }
9c4c6b
+
9c4c6b
     return FALSE;
9c4c6b
 }
9c4c6b
 
9c4c6b
diff --git a/src/tests/gssapi/t_client_keytab.py b/src/tests/gssapi/t_client_keytab.py
9c4c6b
index e474a27c7..7847b3ecd 100755
9c4c6b
--- a/src/tests/gssapi/t_client_keytab.py
9c4c6b
+++ b/src/tests/gssapi/t_client_keytab.py
9c4c6b
@@ -124,4 +124,22 @@ realm.kinit(realm.user_princ, password('user'))
9c4c6b
 realm.run(['./t_ccselect', phost], env=bad_cktname,
9c4c6b
           expected_msg=realm.user_princ)
9c4c6b
 
9c4c6b
+mark('refresh of manually acquired creds')
9c4c6b
+
9c4c6b
+# Test 17: no name/ccache specified, manually acquired creds which
9c4c6b
+# will expire soon.  Verify that creds are refreshed using the current
9c4c6b
+# client name, with refresh_time set in the refreshed ccache.
9c4c6b
+realm.kinit('bob', password('bob'), ['-l', '15s'])
9c4c6b
+realm.run(['./t_ccselect', phost], expected_msg='bob')
9c4c6b
+realm.run([klist, '-C'], expected_msg='refresh_time = ')
9c4c6b
+
9c4c6b
+# Test 18: no name/ccache specified, manually acquired creds with a
9c4c6b
+# client principal not present in the client keytab.  A refresh is
9c4c6b
+# attempted but fails, and an expired ticket error results.
9c4c6b
+realm.kinit(realm.admin_princ, password('admin'), ['-l', '-1s'])
9c4c6b
+msgs = ('Getting initial credentials for user/admin@KRBTEST.COM',
9c4c6b
+        '/Matching credential not found')
9c4c6b
+realm.run(['./t_ccselect', phost], expected_code=1,
9c4c6b
+          expected_msg='Ticket expired', expected_trace=msgs)
9c4c6b
+
9c4c6b
 success('Client keytab tests')