Skip to content

Commit 5ba3c4c

Browse files
mw-asimo5
authored andcommitted
Handle impersonation of oneself
When trying to impersonate the user which has been selected as impersonation credential, MIT krb5 returns error: GSSX_RES_ACQUIRE_CRED( status: { 851968 { 1 2 840 113554 1 2 2 } 2529638928 "Unspecified GSS failure. Minor code may provide more information" "KDC has no support for padata type" [ ] } output_cred_handle: <Null> ) An attempt to impersonate oneself is not allowed. Also, it is likely not even necessary: If we can get impersonation credentials from credstores, we can at least try to short circuit and get actual user credentials the same way. With this patch it becomes possible to delegate the acquisition of e.g. cifs mount credentials from cifs.upcall into gssproxy and use the host identity (e.g. HOSTNAME$@realm of AD) while it is also being selected as impersonation credential due to the order of keys in the keytab. Signed-off-by: Michael Weiser <[email protected]>
1 parent 68c4a7f commit 5ba3c4c

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/gp_creds.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ uint32_t gp_add_krb5_creds(uint32_t *min,
600600
gss_ctx_id_t initiator_context = GSS_C_NO_CONTEXT;
601601
gss_ctx_id_t acceptor_context = GSS_C_NO_CONTEXT;
602602
gss_name_t target_name = GSS_C_NO_NAME;
603+
gss_name_t compare_name = GSS_C_NO_NAME;
603604
gss_buffer_desc init_token = GSS_C_EMPTY_BUFFER;
604605
gss_buffer_desc accept_token = GSS_C_EMPTY_BUFFER;
605606
gss_cred_id_t input_cred;
@@ -667,6 +668,42 @@ uint32_t gp_add_krb5_creds(uint32_t *min,
667668
if (ret_maj) {
668669
goto done;
669670
}
671+
672+
if (req_name != GSS_C_NO_NAME) {
673+
int equal = 0;
674+
675+
ret_maj = gss_inquire_cred(&ret_min, impersonator_cred,
676+
&compare_name, NULL, NULL, NULL);
677+
if (ret_maj) {
678+
goto done;
679+
}
680+
681+
ret_maj = gss_compare_name(&ret_min, compare_name,
682+
req_name, &equal);
683+
if (ret_maj) {
684+
goto done;
685+
}
686+
687+
/* if impersonator credential retrieval yielded the requested
688+
* client name, we do not need to impersonate. Also, with MIT
689+
* krb5 an attempt to impersonate oneself gives an error "KDC
690+
* has no support for padata type" */
691+
if (equal) {
692+
ret_maj = gss_acquire_cred_from(&ret_min, req_name,
693+
GSS_C_INDEFINITE,
694+
&desired_mechs, cred_usage,
695+
&cred_store, &user_cred,
696+
actual_mechs, NULL);
697+
if (ret_maj == GSS_S_COMPLETE) {
698+
*output_cred_handle = user_cred;
699+
user_cred = GSS_C_NO_CREDENTIAL;
700+
goto done;
701+
}
702+
703+
/* fall on through, if failed */
704+
}
705+
}
706+
670707
input_cred = impersonator_cred;
671708
break;
672709
case ACQ_IMPNAME:
@@ -750,6 +787,7 @@ uint32_t gp_add_krb5_creds(uint32_t *min,
750787
}
751788
}
752789
free_cred_store_elements(&cred_store);
790+
gss_release_name(&discard, &compare_name);
753791
gss_release_cred(&discard, &impersonator_cred);
754792
gss_release_cred(&discard, &user_cred);
755793
gss_release_name(&discard, &target_name);

0 commit comments

Comments
 (0)