Skip to content

Commit 66e7c5c

Browse files
Steinar H. Gundersonsimo5
Steinar H. Gunderson
authored andcommitted
Respect krb5_principal when impersonating
When doing impersonation, we need to get initial credentials using some service principal from the given keytab. However, since keytabs have no default principals, libgss just chooses the first one in the file, which generally does not work well when in Active Directory. In particular, in AD, the only valid principal for authenticating is [email protected], whereas e.g. host/[email protected] is just an SPN connected to SERVER$ and not valid for authenticating in its own right. gssd will try SERVER$ first for its own purposes (at least according to the man page), but when impersonating, it will naturally ask for a ticket for a user (e.g. [email protected]) and not the service principal itself. This patch doesn't really make us choose the right principal for AD purposes, but it makes us respect the krb5_principal configuration option when getting a service principal for this purpose, so that an administrator can at least manually select which one to use without having to somehow reorder entries in the keytab (which appears to be hard). Thus, the admin can set "krb5_principal = [email protected]" in the service definition in gssproxy.conf, and it will work. Signed-off-by: Steinar H. Gunderson <[email protected]>
1 parent 01a9648 commit 66e7c5c

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/gp_creds.c

+19-2
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,24 @@ uint32_t gp_add_krb5_creds(uint32_t *min,
667667
}
668668
} else { /* impersonation */
669669
switch (acquire_type) {
670-
case ACQ_NORMAL:
671-
ret_maj = gss_acquire_cred_from(&ret_min, GSS_C_NO_NAME,
670+
case ACQ_NORMAL: {
671+
struct gp_service *svc = gpcall->service;
672+
gss_name_t host_principal = GSS_C_NO_NAME;
673+
674+
if (svc->krb5.principal) {
675+
/* configuration dictates to use a specific name */
676+
gss_buffer_desc const_buf;
677+
const_buf.value = svc->krb5.principal;
678+
const_buf.length = strlen(svc->krb5.principal) + 1;
679+
680+
ret_maj = gss_import_name(&ret_min, &const_buf,
681+
discard_const(GSS_KRB5_NT_PRINCIPAL_NAME),
682+
&host_principal);
683+
if (ret_maj) {
684+
goto done;
685+
}
686+
}
687+
ret_maj = gss_acquire_cred_from(&ret_min, host_principal,
672688
GSS_C_INDEFINITE,
673689
&desired_mechs, GSS_C_BOTH,
674690
&cred_store, &impersonator_cred,
@@ -714,6 +730,7 @@ uint32_t gp_add_krb5_creds(uint32_t *min,
714730

715731
input_cred = impersonator_cred;
716732
break;
733+
}
717734
case ACQ_IMPNAME:
718735
input_cred = in_cred;
719736
break;

0 commit comments

Comments
 (0)