Skip to content

Commit 39d70dc

Browse files
committed
security/oidc: Support oidc for kafka api
Signed-off-by: Ben Pope <[email protected]>
1 parent c9b0e3d commit 39d70dc

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

src/v/config/configuration.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1110,7 +1110,8 @@ configuration::configuration()
11101110
, sasl_mechanisms(
11111111
*this,
11121112
"sasl_mechanisms",
1113-
"A list of supported SASL mechanisms. `SCRAM` and `GSSAPI` are allowed.",
1113+
"A list of supported SASL mechanisms. `SCRAM`, `GSSAPI`, and "
1114+
"`OAUTHBEARER` are allowed.",
11141115
{.needs_restart = needs_restart::no, .visibility = visibility::user},
11151116
{"SCRAM"},
11161117
validate_sasl_mechanisms)

src/v/config/validators.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ std::optional<ss::sstring> validate_client_groups_byte_rate_quota(
109109
std::optional<ss::sstring>
110110
validate_sasl_mechanisms(const std::vector<ss::sstring>& mechanisms) {
111111
static const absl::flat_hash_set<std::string_view> supported{
112-
"GSSAPI", "SCRAM"};
112+
"GSSAPI", "SCRAM", "OAUTHBEARER"};
113113

114114
// Validate results
115115
for (const auto& m : mechanisms) {

src/v/kafka/server/server.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include "security/exceptions.h"
5353
#include "security/gssapi_authenticator.h"
5454
#include "security/mtls.h"
55+
#include "security/oidc_authenticator.h"
5556
#include "security/scram_algorithm.h"
5657
#include "security/scram_authenticator.h"
5758
#include "ssx/future-util.h"
@@ -567,6 +568,18 @@ ss::future<response_ptr> sasl_handshake_handler::handle(
567568
}
568569
}
569570

571+
if (supports(security::oidc::sasl_authenticator::name)) {
572+
supported_sasl_mechanisms.emplace_back(
573+
security::oidc::sasl_authenticator::name);
574+
575+
if (
576+
request.data.mechanism == security::oidc::sasl_authenticator::name) {
577+
ctx.sasl()->set_mechanism(
578+
std::make_unique<security::oidc::sasl_authenticator>(
579+
ctx.connection()->server().oidc_service().local()));
580+
}
581+
}
582+
570583
if (!ctx.sasl()->has_mechanism()) {
571584
error = error_code::unsupported_sasl_mechanism;
572585
}

tests/rptest/tests/redpanda_oauth_test.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
from rptest.services.redpanda import LoggingConfig, SecurityConfig, make_redpanda_service
1414
from rptest.services.keycloak import KeycloakService
1515
from rptest.services.cluster import cluster
16-
from rptest.util import expect_exception
17-
from confluent_kafka import KafkaException
1816

1917
CLIENT_ID = 'myapp'
2018
TOKEN_AUDIENCE = 'account'
@@ -55,10 +53,15 @@ def __init__(self,
5553
security.enable_sasl = True
5654
security.sasl_mechanisms = sasl_mechanisms
5755

58-
self.redpanda = make_redpanda_service(test_context,
59-
num_brokers,
60-
security=security,
61-
log_config=log_config)
56+
self.redpanda = make_redpanda_service(
57+
test_context,
58+
num_brokers,
59+
extra_rp_conf={
60+
"oidc_discovery_url": self.keycloak.get_discovery_url(kc_node),
61+
"oidc_token_audience": TOKEN_AUDIENCE,
62+
},
63+
security=security,
64+
log_config=log_config)
6265

6366
self.su_username, self.su_password, self.su_algorithm = self.redpanda.SUPERUSER_CREDENTIALS
6467

@@ -112,5 +115,4 @@ def test_init(self):
112115
# metadata requests to behave nicely.
113116
producer.poll(0.0)
114117

115-
with expect_exception(KafkaException, lambda _: True):
116-
producer.list_topics(timeout=5)
118+
producer.list_topics(timeout=5)

0 commit comments

Comments
 (0)