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

Add Kafka TLS support to the producer. #178

Merged
merged 1 commit into from
Jun 3, 2021

Conversation

srikartati
Copy link
Contributor

Also, enhance the input consumption when initializing the
Kafka producer.

@codecov
Copy link

codecov bot commented Apr 29, 2021

Codecov Report

Merging #178 (d1bdcff) into main (4fafcfb) will decrease coverage by 0.02%.
The diff coverage is 62.79%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #178      +/-   ##
==========================================
- Coverage   79.36%   79.33%   -0.03%     
==========================================
  Files          17       17              
  Lines        2118     2149      +31     
==========================================
+ Hits         1681     1705      +24     
+ Misses        300      298       -2     
- Partials      137      146       +9     
Flag Coverage Δ
integration-tests 55.55% <9.30%> (-1.71%) ⬇️
unit-tests 77.94% <53.48%> (-1.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/producer/kafka.go 63.33% <62.79%> (+15.05%) ⬆️

@srikartati srikartati force-pushed the add_kafka_tls branch 2 times, most recently from 356c876 to 5a8c108 Compare April 29, 2021 19:02
pkg/producer/kafka.go Outdated Show resolved Hide resolved
if tlsConfig := setupTLSConfig(input.KafkaCAFile, input.KafkaTLSCertFile, input.KafkaTLSKeyFile); tlsConfig != nil {
kafkaConfig.Net.TLS.Config = tlsConfig
kafkaConfig.Net.TLS.Enable = true
if input.KafkaTLSSkipVerify {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that input.KafkaTLSSkipVerify is not used other places other than here. Do we need to handle the case when input.KafkaTLSSkipVerify is set?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be used in testing, where we can create a tlsConfig with TLSSkipVerify set as true.
I wanted to use this insetupTLSConfig function, but gosec, which is part of golint is not letting me add this as parameter because they do not want to set this as false.

Copy link
Contributor

@zyiou zyiou Apr 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. We can add code to ignore secure checking with proper reasoning description like:

// #nosec G402: only applicable for testing purpose
t.InsecureSkipVerify = input.KafkaTLSSkipVerify

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why didn't we pass input.KafkaTLSSkipVerify to setupTLSConfig(), which returns a tls.Config object?
I thought that value can be directly assigned to the returning tls.Config, such as
tls.Config{InsecureSkipVerify: input.KafkaTLSSkipVerify} ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

golang lint test fails if we directly the value like above. However, I moved the assignment to setupTLSConfig.

Sorry for late response. I had put this PR on hold. Please take a look again.

pkg/producer/kafka.go Outdated Show resolved Hide resolved
@srikartati srikartati force-pushed the add_kafka_tls branch 2 times, most recently from 28142d7 to 7ca4dec Compare April 30, 2021 05:45
zyiou
zyiou previously approved these changes Apr 30, 2021
Copy link
Contributor

@zyiou zyiou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we planning to add tests for this PR? Otherwise LGTM overall.

@srikartati
Copy link
Contributor Author

Are we planning to add tests for this PR? Otherwise LGTM overall.

I do not have tests for InitKafkaProducer function. I think TLS certificates warrant some unit tests. Will add those.

@srikartati srikartati changed the base branch from release-0.5.0 to main June 2, 2021 00:05
@srikartati srikartati marked this pull request as draft June 2, 2021 00:48
@srikartati srikartati force-pushed the add_kafka_tls branch 4 times, most recently from 2fe4000 to c61b1ed Compare June 2, 2021 17:14
@srikartati srikartati marked this pull request as ready for review June 2, 2021 17:15
pkg/producer/kafka_test.go Show resolved Hide resolved
pkg/test/certs.go Show resolved Hide resolved
pkg/collector/process_test.go Show resolved Hide resolved
Also, enhance the input consumption when initializing the
Kafka producer.

Unit tests added for TLS cert based kafka connection.
Copy link
Contributor

@zyiou zyiou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the changes. LGTM

@srikartati srikartati merged commit 67fed69 into vmware:main Jun 3, 2021
@srikartati srikartati deleted the add_kafka_tls branch June 3, 2021 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants