Skip to content

Commit f403048

Browse files
Add SASL Kerberos domain override for service principal
1 parent 616fb6e commit f403048

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

CONFIGURATION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ ssl.certificate.verify_cb | * | |
9191
sasl.mechanisms | * | | GSSAPI | high | SASL mechanism to use for authentication. Supported: GSSAPI, PLAIN, SCRAM-SHA-256, SCRAM-SHA-512, OAUTHBEARER. **NOTE**: Despite the name only one mechanism must be configured. <br>*Type: string*
9292
sasl.mechanism | * | | GSSAPI | high | Alias for `sasl.mechanisms`: SASL mechanism to use for authentication. Supported: GSSAPI, PLAIN, SCRAM-SHA-256, SCRAM-SHA-512, OAUTHBEARER. **NOTE**: Despite the name only one mechanism must be configured. <br>*Type: string*
9393
sasl.kerberos.service.name | * | | kafka | low | Kerberos principal name that Kafka runs as, not including /hostname@REALM <br>*Type: string*
94+
sasl.kerberos.domain.name | * | | | low | Override for the broker hostname part in the service principal (the portion after `service/`). Use this if the Kerberos ticket should target a fixed FQDN instead of the broker's advertised hostname. <br>*Type: string*
9495
sasl.kerberos.principal | * | | kafkaclient | low | This client's Kerberos principal name. (Not supported on Windows, will use the logon user's principal). <br>*Type: string*
9596
sasl.kerberos.kinit.cmd | * | | kinit -R -t "%{sasl.kerberos.keytab}" -k %{sasl.kerberos.principal} \|\| kinit -t "%{sasl.kerberos.keytab}" -k %{sasl.kerberos.principal} | low | Shell command to refresh or acquire the client's Kerberos ticket. This command is executed on client creation and every sasl.kerberos.min.time.before.relogin (0=disable). %{config.prop.name} is replaced by corresponding config object value. <br>*Type: string*
9697
sasl.kerberos.keytab | * | | | low | Path to Kerberos keytab file. This configuration property is only used as a variable in `sasl.kerberos.kinit.cmd` as ` ... -t "%{sasl.kerberos.keytab}"`. <br>*Type: string*

src/rdkafka_conf.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,12 @@ static const struct rd_kafka_property rd_kafka_properties[] = {
996996
"Kerberos principal name that Kafka runs as, "
997997
"not including /hostname@REALM",
998998
.sdef = "kafka"},
999+
{_RK_GLOBAL, "sasl.kerberos.domain.name", _RK_C_STR,
1000+
_RK(sasl.domain_name),
1001+
"Override for the broker hostname portion of the service principal "
1002+
"(the string after \"service/\"). Set this if the Kerberos ticket "
1003+
"should always target a fixed FQDN regardless of the broker's "
1004+
"advertised hostname."},
9991005
{_RK_GLOBAL, "sasl.kerberos.principal", _RK_C_STR, _RK(sasl.principal),
10001006
"This client's Kerberos principal name. "
10011007
"(Not supported on Windows, will use the logon user's principal).",

src/rdkafka_sasl_cyrus.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ static int rd_kafka_sasl_cyrus_client_new(rd_kafka_transport_t *rktrans,
522522
rktrans},
523523
{SASL_CB_CANON_USER, (void *)rd_kafka_sasl_cyrus_cb_canon, rktrans},
524524
{SASL_CB_LIST_END}};
525+
const char *principal_host;
525526

526527
state = rd_calloc(1, sizeof(*state));
527528
rktrans->rktrans_sasl.state = state;
@@ -544,8 +545,13 @@ static int rd_kafka_sasl_cyrus_client_new(rd_kafka_transport_t *rktrans,
544545

545546
memcpy(state->callbacks, callbacks, sizeof(callbacks));
546547

548+
principal_host = (rk->rk_conf.sasl.domain_name &&
549+
*rk->rk_conf.sasl.domain_name)
550+
? rk->rk_conf.sasl.domain_name
551+
: hostname;
552+
547553
mtx_lock(&rktrans->rktrans_rkb->rkb_rk->rk_conf.sasl.lock);
548-
r = sasl_client_new(rk->rk_conf.sasl.service_name, hostname, NULL,
554+
r = sasl_client_new(rk->rk_conf.sasl.service_name, principal_host, NULL,
549555
NULL, /* no local & remote IP checks */
550556
state->callbacks, 0, &state->conn);
551557
mtx_unlock(&rktrans->rktrans_rkb->rkb_rk->rk_conf.sasl.lock);

src/rdkafka_sasl_win32.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,18 @@ static int rd_kafka_sasl_win32_client_new(rd_kafka_transport_t *rktrans,
512512
state = rd_calloc(1, sizeof(*state));
513513
rktrans->rktrans_sasl.state = state;
514514

515-
_snwprintf(state->principal, RD_ARRAYSIZE(state->principal), L"%hs/%hs",
516-
rktrans->rktrans_rkb->rkb_rk->rk_conf.sasl.service_name,
517-
hostname);
515+
{
516+
const char *principal_host;
517+
if (rk->rk_conf.sasl.domain_name &&
518+
*rk->rk_conf.sasl.domain_name)
519+
principal_host = rk->rk_conf.sasl.domain_name;
520+
else
521+
principal_host = hostname;
522+
523+
_snwprintf(state->principal, RD_ARRAYSIZE(state->principal),
524+
L"%hs/%hs", rk->rk_conf.sasl.service_name,
525+
principal_host);
526+
}
518527

519528
state->cred = rd_kafka_sasl_sspi_cred_new(rktrans, errstr, errstr_size);
520529
if (!state->cred)

0 commit comments

Comments
 (0)