Skip to content

Commit 37f548a

Browse files
KRB5: skip switch_creds() in PKINIT case
Since 'krb5_child' has lost set-id bit and is run under uid/gid of the backend, it was a no-op.
1 parent 1cd9a9c commit 37f548a

File tree

1 file changed

+12
-43
lines changed

1 file changed

+12
-43
lines changed

src/providers/krb5/krb5_child.c

+12-43
Original file line numberDiff line numberDiff line change
@@ -3297,8 +3297,6 @@ static krb5_error_code get_tgt_times(krb5_context ctx, const char *ccname,
32973297
}
32983298

32993299
static krb5_error_code get_fast_ccache_with_anonymous_pkinit(krb5_context ctx,
3300-
uid_t fast_uid,
3301-
gid_t fast_gid,
33023300
bool posix_domain,
33033301
struct cli_opts *cli_opts,
33043302
krb5_keytab keytab,
@@ -3308,7 +3306,6 @@ static krb5_error_code get_fast_ccache_with_anonymous_pkinit(krb5_context ctx,
33083306
{
33093307
krb5_error_code kerr;
33103308
krb5_get_init_creds_opt *options;
3311-
struct sss_creds *saved_creds = NULL;
33123309
krb5_preauthtype pkinit = KRB5_PADATA_PK_AS_REQ;
33133310
krb5_creds creds = { 0 };
33143311

@@ -3343,38 +3340,19 @@ static krb5_error_code get_fast_ccache_with_anonymous_pkinit(krb5_context ctx,
33433340
goto done;
33443341
}
33453342

3346-
kerr = switch_creds(NULL, fast_uid, fast_gid, 0, NULL, &saved_creds);
3347-
if (kerr != 0) {
3348-
DEBUG(SSSDBG_OP_FAILURE,
3349-
"Failed to switch credentials to store FAST ccache with "
3350-
"expected permissions.\n");
3351-
goto done;
3352-
}
3353-
33543343
kerr = create_ccache(ccname, &creds);
33553344
if (kerr != 0) {
33563345
DEBUG(SSSDBG_OP_FAILURE, "Failed to store FAST ccache.\n");
33573346
goto done;
33583347
}
33593348

3360-
kerr = restore_creds(saved_creds);
3361-
if (kerr != 0) {
3362-
DEBUG(SSSDBG_OP_FAILURE,
3363-
"Failed to restore credentials, krb5_child might run with wrong "
3364-
"permissions, aborting.\n");
3365-
goto done;
3366-
}
3367-
33683349
done:
33693350
sss_krb5_get_init_creds_opt_free(ctx, options);
3370-
talloc_free(saved_creds);
33713351

33723352
return kerr;
33733353
}
33743354

33753355
static krb5_error_code get_fast_ccache_with_keytab(krb5_context ctx,
3376-
uid_t fast_uid,
3377-
gid_t fast_gid,
33783356
bool posix_domain,
33793357
struct cli_opts *cli_opts,
33803358
krb5_keytab keytab,
@@ -3399,11 +3377,7 @@ static krb5_error_code get_fast_ccache_with_keytab(krb5_context ctx,
33993377
/* Try to carry on */
34003378
}
34013379

3402-
kerr = k5c_become_user(fast_uid, fast_gid, posix_domain);
3403-
if (kerr != 0) {
3404-
DEBUG(SSSDBG_CRIT_FAILURE, "become_user failed: %d\n", kerr);
3405-
exit(1);
3406-
}
3380+
sss_drop_all_caps();
34073381
DEBUG(SSSDBG_TRACE_INTERNAL,
34083382
"Running as [%"SPRIuid"][%"SPRIgid"].\n", geteuid(), getegid());
34093383

@@ -3557,8 +3531,7 @@ static krb5_error_code check_fast_ccache(TALLOC_CTX *mem_ctx,
35573531

35583532
/* Need to recreate the FAST ccache */
35593533
if (cli_opts->fast_use_anonymous_pkinit) {
3560-
kerr = get_fast_ccache_with_anonymous_pkinit(ctx, fast_uid, fast_gid,
3561-
posix_domain, cli_opts,
3534+
kerr = get_fast_ccache_with_anonymous_pkinit(ctx, posix_domain, cli_opts,
35623535
keytab, client_princ,
35633536
ccname, realm);
35643537
if (kerr != 0) {
@@ -3567,8 +3540,8 @@ static krb5_error_code check_fast_ccache(TALLOC_CTX *mem_ctx,
35673540
"likely fail!\n");
35683541
}
35693542
} else {
3570-
kerr = get_fast_ccache_with_keytab(ctx, fast_uid, fast_gid, posix_domain,
3571-
cli_opts, keytab, client_princ, ccname);
3543+
kerr = get_fast_ccache_with_keytab(ctx, posix_domain, cli_opts,
3544+
keytab, client_princ, ccname);
35723545
if (kerr != 0) {
35733546
DEBUG(SSSDBG_MINOR_FAILURE, "Creating FAST ccache with keytab failed, "
35743547
"krb5_child will likely fail!\n");
@@ -4289,24 +4262,20 @@ int main(int argc, const char *argv[])
42894262
/* For PKINIT we might need access to the pcscd socket which by default
42904263
* is only allowed for authenticated users. Since PKINIT is part of
42914264
* the authentication and the user is not authenticated yet, we have
4292-
* to use different privileges and can only drop it only after the TGT is
4293-
* received. The fast_uid and fast_gid are the IDs the backend is running
4294-
* with. This can be either root or the 'sssd' user. Root is allowed by
4295-
* default and the 'sssd' user is allowed with the help of the
4296-
* sssd-pcsc.rules policy-kit rule. So those IDs are a suitable choice. We
4297-
* can only call switch_creds() because after the TGT is returned we have
4298-
* to switch to the IDs of the user to store the TGT.
4265+
* to use different privileges and can only drop it after the TGT is
4266+
* received. IDs the backend (and thus 'krb5_child) is running with are
4267+
* either root or the 'sssd' user. Root is allowed by default and
4268+
* the 'sssd' user is allowed with the help of the sssd-pcsc.rules
4269+
* policy-kit rule. So those IDs are a suitable choice and needs to
4270+
* be kept until TGT is obtained.
42994271
* If we are offline we have to switch to the user's credentials directly
43004272
* to make sure the empty ccache is created with the expected
43014273
* ownership. */
4302-
if (IS_SC_AUTHTOK(kr->pd->authtok) && !offline) {
4303-
kerr = switch_creds(kr, kr->fast_uid, kr->fast_gid, 0, NULL,
4304-
&kr->pcsc_saved_creds);
4305-
} else {
4274+
if (!IS_SC_AUTHTOK(kr->pd->authtok) || offline) {
43064275
kerr = k5c_become_user(kr->uid, kr->gid, kr->posix_domain);
43074276
}
43084277
if (kerr != 0) {
4309-
DEBUG(SSSDBG_CRIT_FAILURE, "become_user failed.\n");
4278+
DEBUG(SSSDBG_CRIT_FAILURE, "k5c_become_user() failed.\n");
43104279
ret = EFAULT;
43114280
goto done;
43124281
}

0 commit comments

Comments
 (0)