-
Notifications
You must be signed in to change notification settings - Fork 747
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
feat: kafka sasl auth #1186
feat: kafka sasl auth #1186
Conversation
Signed-off-by: Joshua Jorel Lee <[email protected]>
Signed-off-by: Joshua Jorel Lee <[email protected]>
Signed-off-by: Joshua Jorel Lee <[email protected]>
Signed-off-by: Joshua Jorel Lee <[email protected]>
Signed-off-by: Joshua Jorel Lee <[email protected]>
Signed-off-by: Joshua Jorel Lee <[email protected]>
pkg/apis/common/common.go
Outdated
// SASLMechanism is the name of the enabled SASL mechanism. | ||
// Possible values: OAUTHBEARER, PLAIN (defaults to PLAIN). | ||
Mechanism string `json:"mechanism,omitempty" protobuf:"bytes,1,opt,name=mechanism"` | ||
// Version is the SASL Protocol Version to use |
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.
Comments do not match the fields...
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.
Removed comments.
pkg/apis/common/common.go
Outdated
User *corev1.SecretKeySelector `json:"user,omitempty" protobuf:"bytes,2,opt,name=user"` | ||
// Password for SASL/PLAIN authentication | ||
Password *corev1.SecretKeySelector `json:"password,omitempty" protobuf:"bytes,3,opt,name=password"` | ||
// authz id used for SASL/SCRAM authentication |
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.
Where is authz id?
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.
Remove authz id. It wasn't supposed to be in there. Comments were lifted from the sarama library.
pkg/apis/common/validate.go
Outdated
|
||
var mechanismSet, userSet, passwordSet bool | ||
|
||
if saslConfig.Mechanism != "" { |
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.
Does not need !=""
check
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.
Removed !=""
check
pkg/apis/common/validate.go
Outdated
} | ||
|
||
if !mechanismSet { | ||
return errors.New("invalid sasl config, please configure Mechanism. Possible values are `OAUTHBEARER`, `PLAIN`, `SCRAM-SHA-256`, `SCRAM-SHA-512` and `GSSAPI`") |
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.
It says defaults to PLAIN
above.
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.
Renamed error message to account for the only possible values.
pkg/apis/common/validate.go
Outdated
passwordSet = true | ||
} | ||
|
||
if !userSet && !passwordSet { |
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.
Can either of them be missing?
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.
This should have been an OR statement. Will fix.
sensors/triggers/kafka/kafka.go
Outdated
@@ -63,6 +63,24 @@ func NewKafkaTrigger(sensor *v1alpha1.Sensor, trigger *v1alpha1.Trigger, kafkaPr | |||
config.Version = version | |||
} | |||
|
|||
if kafkatrigger.SASL != nil { | |||
config.Net.SASL.Enable = true | |||
config.Net.SASL.Mechanism = sarama.SASLMechanism(kafkatrigger.SASL.Mechanism) |
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.
Validating?
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.
Checks whether the configuration is set. Enables SASL authentication if parameters are set in the YAML configs.
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.
Added additional validation for empty strings.
@@ -461,28 +461,31 @@ type KafkaEventSource struct { | |||
Topic string `json:"topic" protobuf:"bytes,3,opt,name=topic"` | |||
// Backoff holds parameters applied to connection. | |||
ConnectionBackoff *apicommon.Backoff `json:"connectionBackoff,omitempty" protobuf:"bytes,4,opt,name=connectionBackoff"` | |||
// SASL configuration for the kafka client |
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.
BTW - we should keep the order of existing fields, otherwise it's a breaking change for proto files, we should reduce that kind of changes.
https://developers.google.com/protocol-buffers/docs/pythontutorial#extending-a-protocol-buffer
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.
Reverted the byte ordering and added the SASL configs to the end.
Signed-off-by: Joshua Jorel Lee <[email protected]>
Signed-off-by: Joshua Jorel Lee <[email protected]>
Signed-off-by: Joshua Jorel Lee <[email protected]>
…passwordset logic. Signed-off-by: Joshua Jorel Lee <[email protected]>
Signed-off-by: Joshua Jorel Lee <[email protected]>
Signed-off-by: Joshua Jorel Lee <[email protected]>
Signed-off-by: Joshua Jorel Lee <[email protected]>
pkg/apis/common/validate.go
Outdated
return nil | ||
} | ||
|
||
var mechanismSet, userSet, passwordSet bool |
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.
Kind of verbose.
switch saslConfig.GetMechanism() {
case "PLAIN", xxxxxx:
default:
return errors.New("invalid sasl config. Possible xxxxxx")
}
if saslConfig.User == nil {
return errors.New("xxx")
}
if saslConfig.Password == nil {
return errors.New("xxx")
}
return nil
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.
Removed xxxSet flags. merged validating user and password into a single if statemetn.
pkg/apis/sensor/v1alpha1/types.go
Outdated
@@ -499,20 +499,24 @@ type KafkaTrigger struct { | |||
// Defaults to 500 milliseconds. | |||
// +optional | |||
FlushFrequency int32 `json:"flushFrequency,omitempty" protobuf:"varint,7,opt,name=flushFrequency"` | |||
// SASL configuration for the kafka client |
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.
Same here, do not change the order.
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.
Reverted order.
eventsources/sources/kafka/start.go
Outdated
if kafkaEventSource.SASL != nil { | ||
config.Net.SASL.Enable = true | ||
|
||
if kafkaEventSource.SASL.Mechanism == "" { |
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.
A function func (s SASLConfig) GetMechanism()
would be helpful to save if..else
everywhere.
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.
Will refactor.
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.
Refactored both sensor and event source kafka configs. Function GetMechanism() will by default, will set mechanism to "PLAINTEXT" unless otherwise specified.
Signed-off-by: Joshua Jorel Lee <[email protected]>
Signed-off-by: Joshua Jorel Lee <[email protected]>
Signed-off-by: Joshua Jorel Lee <[email protected]>
Signed-off-by: Joshua Jorel Lee <[email protected]>
Signed-off-by: Joshua Jorel Lee <[email protected]>
Signed-off-by: Joshua Jorel Lee <[email protected]>
pkg/apis/common/common.go
Outdated
@@ -153,3 +167,13 @@ type Metadata struct { | |||
Annotations map[string]string `json:"annotations,omitempty" protobuf:"bytes,1,rep,name=annotations"` | |||
Labels map[string]string `json:"labels,omitempty" protobuf:"bytes,2,rep,name=labels"` | |||
} | |||
|
|||
func (s SASLConfig) GetMechanism() sarama.SASLMechanism { |
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.
Overall everything looks good to me except this part.
- Returning
sarama.SASLMechanism
makesgithub.com/Shopify/sarama
get introduced to the models, which is not good. Ideally the dependencies in models are either from native GoLang or k8s related. I prefer to return a string here. - Another reason is, since this struct is put in
common
, it is intended to be used by not only Kafka. Assume it's going to be used by something else,sarma.SASLMechanism
might not be recognized by it. Also, I made a little research on SASL auth, it looks like the mechanism is not unified, different product has different support (PLAIN might be the one everyone supports). Correct me if I'm wrong.
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.
- Apologies for the oversight. Removed the type reference and refactored again to reflect on the actual sensor and eventsource.
- I'm basing the authentication mechanism on the available library which is Sarama. The other authentication mechanisms might be something to look into in the future, but "PLAIN" auth is a good place to start.
Signed-off-by: Joshua Jorel Lee <[email protected]>
Signed-off-by: Joshua Jorel Lee <[email protected]>
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.
LGTM, thanks!
* feat: SASL Auth for Kafka Signed-off-by: Joshua Jorel Lee <[email protected]>
Checklist:
Test Cases:
Notes: