Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose GSSAPI Service name configuration of Kafka Scaler #5483

Merged
merged 2 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ New deprecation(s):
- **General**: Introduce ENABLE_OPENTELEMETRY in deploying/testing process ([#5375](https://github.com/kedacore/keda/issues/5375))
- **General**: Migrate away from unmaintained golang/mock and use uber/gomock ([#5440](https://github.com/kedacore/keda/issues/5440))
- **General**: Minor refactor to reduce copy/paste code in ScaledObject webhook ([#5397](https://github.com/kedacore/keda/issues/5397))
- **Kafka**: Expose GSSAPI service name ([#5474](https://github.com/kedacore/keda/issues/5474))
ArunYogesh marked this conversation as resolved.
Show resolved Hide resolved

## v2.13.1

Expand Down
17 changes: 13 additions & 4 deletions pkg/scalers/kafka_scaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ type kafkaMetadata struct {
password string

// GSSAPI
keytabPath string
realm string
kerberosConfigPath string
keytabPath string
realm string
kerberosConfigPath string
kerberosServiceName string

// OAUTHBEARER
scopes []string
Expand Down Expand Up @@ -291,6 +292,10 @@ func parseKerberosParams(config *scalersconfig.ScalerConfig, meta *kafkaMetadata
}
meta.kerberosConfigPath = path

if config.AuthParams["kerberosServiceName"] != "" {
meta.kerberosServiceName = strings.TrimSpace(config.AuthParams["kerberosServiceName"])
}

meta.saslType = mode
return nil
}
Expand Down Expand Up @@ -541,7 +546,11 @@ func getKafkaClients(metadata kafkaMetadata) (sarama.Client, sarama.ClusterAdmin
if metadata.saslType == KafkaSASLTypeGSSAPI {
config.Net.SASL.Enable = true
config.Net.SASL.Mechanism = sarama.SASLTypeGSSAPI
config.Net.SASL.GSSAPI.ServiceName = "kafka"
if metadata.kerberosServiceName != "" {
config.Net.SASL.GSSAPI.ServiceName = metadata.kerberosServiceName
} else {
config.Net.SASL.GSSAPI.ServiceName = "kafka"
}
config.Net.SASL.GSSAPI.Username = metadata.username
config.Net.SASL.GSSAPI.Realm = metadata.realm
config.Net.SASL.GSSAPI.KerberosConfigPath = metadata.kerberosConfigPath
Expand Down
5 changes: 5 additions & 0 deletions pkg/scalers/kafka_scaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ var parseKafkaAuthParamsTestDataset = []parseKafkaAuthParamsTestData{
{map[string]string{"sasl": "gssapi", "username": "admin", "password": "admin", "kerberosConfig": "<config>", "realm": "tst.com", "tls": "enable", "ca": "caaa", "cert": "ceert", "key": "keey"}, false, true},
// success, SASL GSSAPI/keytab + TLS
{map[string]string{"sasl": "gssapi", "username": "admin", "keytab": "/path/to/keytab", "kerberosConfig": "<config>", "realm": "tst.com", "tls": "enable", "ca": "caaa", "cert": "ceert", "key": "keey"}, false, true},
// success, SASL GSSAPI, KerberosServiceName supported
{map[string]string{"sasl": "gssapi", "username": "admin", "keytab": "/path/to/keytab", "kerberosConfig": "<config>", "realm": "tst.com", "kerberosServiceName": "srckafka"}, false, false},
// failure, SASL OAUTHBEARER + TLS bad sasl type
{map[string]string{"sasl": "foo", "username": "admin", "password": "admin", "scopes": "scope", "oauthTokenEndpointUri": "https://website.com", "tls": "disable"}, true, false},
// success, SASL OAUTHBEARER + TLS missing scope
Expand Down Expand Up @@ -412,6 +414,9 @@ func TestKafkaAuthParamsInTriggerAuthentication(t *testing.T) {
t.Errorf(err.Error())
}
}
if meta.kerberosServiceName != testData.authParams["kerberosServiceName"] {
t.Errorf("Expected kerberos ServiceName to be set to %v but got %v\n", testData.authParams["kerberosServiceName"], meta.kerberosServiceName)
}
}
}
}
Expand Down