-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[kafka/internal, kafkaexporter, kafkareceiver] Add SASL mechanism "AWS_MSK_IAM_OAUTHBEARER" to kafkaexporter #32500
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
Changes from 1 commit
c14de4e
e9ecbc1
7955f9d
b4c0c73
f6148a6
bad9c2e
c25c058
e0f68d7
e934bc0
596c814
897d705
ddda641
1c502fd
a35c776
fd12dd2
b5ffb5a
fa288ba
2c803f1
154dfe8
daf479b
f3c9057
15bd9f9
f3f2c39
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: enhancement | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: kafkaexporter, internal/kafka | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Add a new mechanism "AWS_MSK_IAM_OAUTHBEARER" for kafka exporter and kafka receiver. This mechanism use the AWS MSK IAM SASL Signer for Go https://github.com/aws/aws-msk-iam-sasl-signer-go. | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/19747] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: | ||
|
||
# If your change doesn't affect end users or the exported elements of any package, | ||
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
# Optional: The change log or logs in which this entry should be included. | ||
# e.g. '[user]' or '[user, api]' | ||
# Include 'user' if the change is relevant to end users. | ||
# Include 'api' if there is a change to a library API. | ||
# Default: '[user]' | ||
change_logs: [user] |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,11 @@ import ( | |
"context" | ||
"crypto/sha256" | ||
"crypto/sha512" | ||
"crypto/tls" | ||
"fmt" | ||
|
||
"github.com/IBM/sarama" | ||
"github.com/aws/aws-msk-iam-sasl-signer-go/signer" | ||
"go.opentelemetry.io/collector/config/configtls" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/kafka/awsmsk" | ||
|
@@ -35,7 +37,7 @@ type SASLConfig struct { | |
Username string `mapstructure:"username"` | ||
// Password to be used on authentication | ||
Password string `mapstructure:"password"` | ||
// SASL Mechanism to be used, possible values are: (PLAIN, AWS_MSK_IAM, SCRAM-SHA-256 or SCRAM-SHA-512). | ||
// SASL Mechanism to be used, possible values are: (PLAIN, AWS_MSK_IAM, AWS_MSK_IAM_OAUTHBEARER, SCRAM-SHA-256 or SCRAM-SHA-512). | ||
Mechanism string `mapstructure:"mechanism"` | ||
// SASL Protocol Version to be used, possible values are: (0, 1). Defaults to 0. | ||
Version int `mapstructure:"version"` | ||
|
@@ -44,14 +46,21 @@ type SASLConfig struct { | |
} | ||
|
||
// AWSMSKConfig defines the additional SASL authentication | ||
// measures needed to use AWS_MSK_IAM mechanism | ||
// measures needed to use AWS_MSK_IAM and AWS_MSK_IAM_OAUTHBEARER mechanism | ||
type AWSMSKConfig struct { | ||
// Region is the AWS region the MSK cluster is based in | ||
Region string `mapstructure:"region"` | ||
// BrokerAddr is the client is connecting to in order to perform the auth required | ||
BrokerAddr string `mapstructure:"broker_addr"` | ||
} | ||
|
||
// Token return the AWS session token for the AWS_MSK_IAM_OAUTHBEARER mechanism | ||
func (c *AWSMSKConfig) Token() (*sarama.AccessToken, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please pass in the context to avoid using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have changed the code to pass the context from parent's function. PTAL. Thank you. |
||
token, _, err := signer.GenerateAuthToken(context.TODO(), c.Region) | ||
|
||
return &sarama.AccessToken{Token: token}, err | ||
} | ||
|
||
// KerberosConfig defines kereros configuration. | ||
type KerberosConfig struct { | ||
ServiceName string `mapstructure:"service_name"` | ||
|
@@ -93,11 +102,11 @@ func configurePlaintext(config PlainTextConfig, saramaConfig *sarama.Config) { | |
|
||
func configureSASL(config SASLConfig, saramaConfig *sarama.Config) error { | ||
|
||
if config.Username == "" { | ||
if config.Username == "" && config.Mechanism != "AWS_MSK_IAM_OAUTHBEARER" { | ||
return fmt.Errorf("username have to be provided") | ||
} | ||
|
||
if config.Password == "" { | ||
if config.Password == "" && config.Mechanism != "AWS_MSK_IAM_OAUTHBEARER" { | ||
return fmt.Errorf("password have to be provided") | ||
} | ||
|
||
|
@@ -119,8 +128,14 @@ func configureSASL(config SASLConfig, saramaConfig *sarama.Config) error { | |
return awsmsk.NewIAMSASLClient(config.AWSMSK.BrokerAddr, config.AWSMSK.Region, saramaConfig.ClientID) | ||
} | ||
saramaConfig.Net.SASL.Mechanism = awsmsk.Mechanism | ||
case "AWS_MSK_IAM_OAUTHBEARER": | ||
saramaConfig.Net.SASL.Mechanism = sarama.SASLTypeOAuth | ||
saramaConfig.Net.SASL.TokenProvider = &config.AWSMSK | ||
tlsConfig := tls.Config{} | ||
saramaConfig.Net.TLS.Enable = true | ||
saramaConfig.Net.TLS.Config = &tlsConfig | ||
default: | ||
return fmt.Errorf(`invalid SASL Mechanism %q: can be either "PLAIN", "AWS_MSK_IAM", "SCRAM-SHA-256" or "SCRAM-SHA-512"`, config.Mechanism) | ||
return fmt.Errorf(`invalid SASL Mechanism %q: can be either "PLAIN", "AWS_MSK_IAM", "AWS_MSK_IAM_OAUTHBEARER", "SCRAM-SHA-256" or "SCRAM-SHA-512"`, config.Mechanism) | ||
} | ||
|
||
switch config.Version { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't receiver missing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we can remove the internal/kafka?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I updated the changelog.