Blame SOURCES/Handle-outdated-encrypted-ccaches.patch

68bf20
From 24d776205605f3c113fdc2cb356d4c28b8033676 Mon Sep 17 00:00:00 2001
1f3433
From: Robbie Harwood <rharwood@redhat.com>
1f3433
Date: Fri, 15 Sep 2017 18:07:28 -0400
1f3433
Subject: [PATCH] Handle outdated encrypted ccaches
1f3433
1f3433
When the encrypting keytab changes, all credentials that it was used
1f3433
to encrypt must be re-created.  Otherwise, we log obtuse messages and
1f3433
fail to do what the user wants.
1f3433
1f3433
Signed-off-by: Robbie Harwood <rharwood@redhat.com>
1f3433
Reviewed-by: Simo Sorce <simo@redhat.com>
1f3433
Merges: #214
1f3433
(cherry picked from commit 657d3c8339309dd8e2bfa4ee10f005e0f0c055e8)
1f3433
---
1f3433
 proxy/src/gp_export.c                 | 11 ++++++-----
68bf20
 proxy/src/gp_rpc_accept_sec_context.c | 28 +++++++++++++++++++++++++++
1f3433
 proxy/src/gp_rpc_init_sec_context.c   |  2 +-
1f3433
 3 files changed, 35 insertions(+), 6 deletions(-)
1f3433
1f3433
diff --git a/proxy/src/gp_export.c b/proxy/src/gp_export.c
1f3433
index ab08bb7..0c39045 100644
1f3433
--- a/proxy/src/gp_export.c
1f3433
+++ b/proxy/src/gp_export.c
1f3433
@@ -268,7 +268,7 @@ static int gp_decrypt_buffer(krb5_context context, krb5_keyblock *key,
1f3433
                          &enc_handle,
1f3433
                          &data_out);
1f3433
     if (ret) {
1f3433
-        return EINVAL;
1f3433
+        return ret;
1f3433
     }
1f3433
 
1f3433
     *len = data_out.length;
1f3433
@@ -446,8 +446,8 @@ uint32_t gp_import_gssx_cred(uint32_t *min, struct gp_call_ctx *gpcall,
1f3433
 {
1f3433
     gss_buffer_desc token = GSS_C_EMPTY_BUFFER;
1f3433
     struct gp_creds_handle *handle = NULL;
1f3433
-    uint32_t ret_maj;
1f3433
-    uint32_t ret_min;
1f3433
+    uint32_t ret_maj = GSS_S_COMPLETE;
1f3433
+    uint32_t ret_min = 0;
1f3433
     int ret;
1f3433
 
1f3433
     handle = gp_service_get_creds_handle(gpcall->service);
1f3433
@@ -469,8 +469,9 @@ uint32_t gp_import_gssx_cred(uint32_t *min, struct gp_call_ctx *gpcall,
1f3433
                             &cred->cred_handle_reference,
1f3433
                             &token.length, token.value);
1f3433
     if (ret) {
1f3433
-        ret_maj = GSS_S_FAILURE;
1f3433
-        ret_min = ENOENT;
1f3433
+        /* Allow for re-issuance of the keytab. */
1f3433
+        GPDEBUG("Stored ccache failed to decrypt; treating as empty\n");
1f3433
+        *out = GSS_C_NO_CREDENTIAL;
1f3433
         goto done;
1f3433
     }
1f3433
 
1f3433
diff --git a/proxy/src/gp_rpc_accept_sec_context.c b/proxy/src/gp_rpc_accept_sec_context.c
1f3433
index ae4de55..2cdc94b 100644
1f3433
--- a/proxy/src/gp_rpc_accept_sec_context.c
1f3433
+++ b/proxy/src/gp_rpc_accept_sec_context.c
1f3433
@@ -25,6 +25,13 @@ int gp_accept_sec_context(struct gp_call_ctx *gpcall,
1f3433
     int exp_creds_type;
1f3433
     uint32_t acpt_maj;
1f3433
     uint32_t acpt_min;
1f3433
+    struct gp_cred_check_handle gcch = {
1f3433
+        .ctx = gpcall,
1f3433
+        .options.options_len = arg->accept_sec_context.options.options_len,
1f3433
+        .options.options_val = arg->accept_sec_context.options.options_val,
1f3433
+    };
1f3433
+    uint32_t gccn_before = 0;
1f3433
+    uint32_t gccn_after = 0;
1f3433
     int ret;
1f3433
 
1f3433
     asca = &arg->accept_sec_context;
1f3433
@@ -52,6 +59,8 @@ int gp_accept_sec_context(struct gp_call_ctx *gpcall,
1f3433
         if (ret_maj) {
1f3433
             goto done;
1f3433
         }
1f3433
+
1f3433
+        gccn_before = gp_check_sync_creds(&gcch, ach);
1f3433
     }
1f3433
 
1f3433
     if (ach == GSS_C_NO_CREDENTIAL) {
1f3433
@@ -146,6 +155,25 @@ int gp_accept_sec_context(struct gp_call_ctx *gpcall,
1f3433
                                               src_name, oid,
1f3433
                                               &ascr->options.options_len,
1f3433
                                               &ascr->options.options_val);
1f3433
+    if (ret_maj) {
1f3433
+        goto done;
1f3433
+    }
1f3433
+
1f3433
+    gccn_after = gp_check_sync_creds(&gcch, ach);
1f3433
+
1f3433
+    if (gccn_before != gccn_after) {
1f3433
+        /* export creds back to client for sync up */
1f3433
+        ret_maj = gp_export_sync_creds(&ret_min, gpcall, &ach,
1f3433
+                                       &ascr->options.options_val,
1f3433
+                                       &ascr->options.options_len);
1f3433
+        if (ret_maj) {
1f3433
+            /* not fatal, log and continue */
1f3433
+            GPDEBUG("Failed to export sync creds (%d: %d)",
1f3433
+                    (int)ret_maj, (int)ret_min);
1f3433
+        }
1f3433
+    }
1f3433
+
1f3433
+    ret_maj = GSS_S_COMPLETE;
1f3433
 
1f3433
 done:
1f3433
     if (ret_maj == GSS_S_COMPLETE) {
1f3433
diff --git a/proxy/src/gp_rpc_init_sec_context.c b/proxy/src/gp_rpc_init_sec_context.c
1f3433
index e4af495..f362dbc 100644
1f3433
--- a/proxy/src/gp_rpc_init_sec_context.c
1f3433
+++ b/proxy/src/gp_rpc_init_sec_context.c
1f3433
@@ -91,7 +91,7 @@ int gp_init_sec_context(struct gp_call_ctx *gpcall,
1f3433
         gp_conv_gssx_to_buffer(isca->input_token, &ibuf);
1f3433
     }
1f3433
 
1f3433
-    if (!isca->cred_handle) {
1f3433
+    if (!ich) {
1f3433
         if (gss_oid_equal(mech_type, gss_mech_krb5)) {
1f3433
             ret_maj = gp_add_krb5_creds(&ret_min, gpcall,
1f3433
                                         ACQ_NORMAL, NULL, NULL,