Skip to content

Commit 33904f9

Browse files
authored
[kafka] Ensure TLS is enabled when using MSK IAM auth (#40720)
#### Description Fixes a defect introduced in #39115 that prevents MSK IAM auth from working Signed-off-by: Anthony J Mirabella <[email protected]>
1 parent ab48eb9 commit 33904f9

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

.chloggen/fix_kafka_iam_tls.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: kafka
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: "Fixes a defect introduced in #39115 that prevents MSK IAM auth from working"
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [40720]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: "IAM auth requires TLS, but the config translation was enabling SASL when it intended to enable TLS"
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: [user]

internal/kafka/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func newSaramaClientConfig(ctx context.Context, config configkafka.ClientConfig)
147147
}
148148
} else if config.Authentication.SASL != nil && config.Authentication.SASL.Mechanism == "AWS_MSK_IAM_OAUTHBEARER" {
149149
saramaConfig.Net.TLS.Config = &tls.Config{}
150-
saramaConfig.Net.SASL.Enable = true
150+
saramaConfig.Net.TLS.Enable = true
151151
}
152152
configureSaramaAuthentication(ctx, config.Authentication, saramaConfig)
153153
return saramaConfig, nil

internal/kafka/client_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,3 +543,30 @@ func TestSetSaramaProducerConfig_Compression(t *testing.T) {
543543
})
544544
}
545545
}
546+
547+
func TestNewSaramaClientConfigWithAWSMSKIAM(t *testing.T) {
548+
// Test case for AWS_MSK_IAM_OAUTHBEARER mechanism
549+
clientConfig := configkafka.ClientConfig{
550+
Brokers: []string{"localhost:9092"},
551+
Authentication: configkafka.AuthenticationConfig{
552+
SASL: &configkafka.SASLConfig{
553+
Mechanism: "AWS_MSK_IAM_OAUTHBEARER",
554+
AWSMSK: configkafka.AWSMSKConfig{
555+
Region: "us-west-2",
556+
},
557+
},
558+
},
559+
}
560+
561+
saramaConfig, err := newSaramaClientConfig(context.Background(), clientConfig)
562+
assert.NoError(t, err)
563+
564+
// Verify that TLS is enabled, not just SASL
565+
assert.True(t, saramaConfig.Net.TLS.Enable, "TLS should be enabled for AWS_MSK_IAM_OAUTHBEARER")
566+
assert.NotNil(t, saramaConfig.Net.TLS.Config, "TLS config should not be nil for AWS_MSK_IAM_OAUTHBEARER")
567+
568+
// Also verify that SASL is enabled and properly configured
569+
assert.True(t, saramaConfig.Net.SASL.Enable, "SASL should be enabled for AWS_MSK_IAM_OAUTHBEARER")
570+
assert.Equal(t, sarama.SASLMechanism(sarama.SASLTypeOAuth), saramaConfig.Net.SASL.Mechanism)
571+
assert.NotNil(t, saramaConfig.Net.SASL.TokenProvider, "TokenProvider should not be nil for AWS_MSK_IAM_OAUTHBEARER")
572+
}

0 commit comments

Comments
 (0)