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

chore: improve kafka startup logging #696

Merged
merged 1 commit into from
Oct 11, 2023

Conversation

lzap
Copy link
Member

@lzap lzap commented Oct 4, 2023

It looks like we use TLS on stage but not on prod and ephemeral.

This is small logging improvement that should confirm it as we do not dump configuration on prod.

@@ -98,7 +106,6 @@ func NewKafkaBroker(ctx context.Context) (Broker, error) {

//nolint:gosec
tlsConfig = &tls.Config{
MinVersion: tls.VersionTLS12,
Copy link
Member Author

Choose a reason for hiding this comment

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

Unrelated, TLS 1.2 is the default value when this field is nil so useless.

@@ -81,7 +81,15 @@ func NewKafkaBroker(ctx context.Context) (Broker, error) {
var saslMechanism sasl.Mechanism

logger := zerolog.Ctx(ctx)
logger.Debug().Msgf("Setting up Kafka transport: %v", config.Kafka.Brokers)
logger.Info().Msgf("Setting up Kafka transport: %v TLS:%b Skip:%b CA:%b Auth:%s SASLMech:%s SASLProto:%s",
Copy link
Member

Choose a reason for hiding this comment

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

I guess %b should have been %t?

Suggested change
logger.Info().Msgf("Setting up Kafka transport: %v TLS:%b Skip:%b CA:%b Auth:%s SASLMech:%s SASLProto:%s",
logger.Info().Msgf("Setting up Kafka transport: %v TLS:%t Skip:%t CA:%t Auth:%s SASLMech:%s SASLProto:%s",

@lzap lzap force-pushed the kafka-better-logging branch from 4190439 to ebd8275 Compare October 4, 2023 13:48
@lzap
Copy link
Member Author

lzap commented Oct 4, 2023

Rebased.

Comment on lines 85 to 91
config.Kafka.Brokers,
config.Kafka.TlsEnabled,
config.Kafka.TlsSkipVerify,
config.Kafka.CACert != "",
config.Kafka.AuthType,
config.Kafka.SASL.SaslMechanism,
config.Kafka.SASL.SecurityProtocol,
Copy link
Member

Choose a reason for hiding this comment

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

aren't we more interested in what's in the clowder config directly?

Copy link
Member

@ezr-ondrej ezr-ondrej left a comment

Choose a reason for hiding this comment

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

sure, let's get it in :)

@ezr-ondrej
Copy link
Member

/retest

@lzap
Copy link
Member Author

lzap commented Oct 4, 2023

Do not merge, I have some new info about clowder.

@lzap lzap force-pushed the kafka-better-logging branch 3 times, most recently from ae9df73 to bd2617c Compare October 4, 2023 15:48
@lzap
Copy link
Member Author

lzap commented Oct 4, 2023

After chat with Derek Horton, he suggest to provide an empty TLS config value as the library is supposed to automatically detect if TLS is present on a cluster or not and use the safest transport. He mentioned that he uses this on their project and it works even after Kafka migration from this weekend.

Therefore this patch drops the newly introduced setting completely, I don’t have a TLS Kafka setup in my home lab so we need to test this. Ephemeral is plaintext and stage is TLS so if both works prod should be fine. Then I will remove these flags.

@lzap lzap force-pushed the kafka-better-logging branch from bd2617c to 883efe0 Compare October 4, 2023 16:08
@lzap
Copy link
Member Author

lzap commented Oct 4, 2023

DO NOT MERGE.

Looks like Derek was not right, might not work as he described.

@lzap lzap force-pushed the kafka-better-logging branch 2 times, most recently from 7dbb463 to e2aca9c Compare October 5, 2023 07:33
@lzap
Copy link
Member Author

lzap commented Oct 5, 2023

I am reverting the commit back to the initial one - only improves logging and drops a line that has no effect. Looks like our solution is the best for now. I asked via email if we can use one of clowder's fields to detect TLS, let’s wait until I get some reply.

@lzap
Copy link
Member Author

lzap commented Oct 5, 2023

_Regarding how apps should know whether SSL is on or off moving forward... I think a good example we have is the one Dan Kuc just pushed for malware-detection[1]. You are correct that the only values Clowder sets on this field is either "SSL"[2] or "SASL_SSL"[3,4]. In short, I think you can use this logic to determine if your Kafka client should use SSL or not:

  • if kafka.brokers[0].securityProtocol is defined and its value is "SSL" or "SASL_SSL", then SSL should be ON

Your client should be able to use SSL with or without the 'cacert' field present. If the field is present, then use that as your client's trust store. If not, then ideally your client falls back to using the "system default trust store" -- which should already trust well-known root CA's like Digicert, Verisign, LetsEncrypt, and so on._

So I will go ahead and drop our own field and rely on this field instead.

@lzap lzap force-pushed the kafka-better-logging branch 2 times, most recently from 8a61f31 to 4d7316b Compare October 5, 2023 07:50
@lzap
Copy link
Member Author

lzap commented Oct 5, 2023

So the latest version drops the KAFKA_TLS_ENABLED flag and uses SecurityProtocol flag to check if it contains "SSL" string. If it does, it configures TLS.

The same way it also checks for SASL in the AuthType which should contain this string if SASL should be used.

I am keeping the verification skip flag tho, can be useful for local TLS testing. Once this is confirmed to work on both stage and ephemeral we can remove flags from app-interface. I believe this is the final version.

@lzap lzap force-pushed the kafka-better-logging branch from 4d7316b to 095e981 Compare October 5, 2023 07:58
Copy link
Member

@ezr-ondrej ezr-ondrej left a comment

Choose a reason for hiding this comment

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

Just two nits and only one of them addressable xD
Apart of it great effort here to find out how to do it properly! 👍

Password string `env:"PASSWORD" env-default:"" env-description:"kafka SASL password"`
SaslMechanism string `env:"MECHANISM" env-default:"" env-description:"kafka SASL mechanism (scram-sha-512, scram-sha-256 or plain)"`
SecurityProtocol string `env:"PROTOCOL" env-default:"" env-description:"kafka SASL security protocol"`
Enabled bool `env:"ENABLED" env-default:"false" env-description:"kafka service enabled"`
Copy link
Member

Choose a reason for hiding this comment

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

should we delete it right away, given we are now quite sure it's probably not gonna be used? :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Delete what, enabled flag? How are you going to test Kafka in dev environment (without clowder)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Still not sure what you mean here, rebasing anyeway.

@@ -93,18 +100,17 @@ func NewKafkaBroker(ctx context.Context) (Broker, error) {
}
}

if config.Kafka.TlsEnabled && !config.InEphemeralClowder() {
if strings.Contains(strings.ToUpper(config.Kafka.SecurityProtocol), "SSL") {
Copy link
Member

Choose a reason for hiding this comment

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

I'd love to have the values in constants, but I guess we can contribute that to https://github.com/RedHatInsights/app-common-go and then use it.
So good for now 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Ehm "middleware" ehm.

Copy link
Member

Choose a reason for hiding this comment

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

right xD :)

@lzap
Copy link
Member Author

lzap commented Oct 6, 2023

So we got the following info for the field: PLAINTEXT, SSL, SASL_PLAINTEXT, or SASL_SSL I can incorporate this in the help text if necessary.

@lzap lzap force-pushed the kafka-better-logging branch from 095e981 to 4cccdb5 Compare October 10, 2023 11:03
@lzap
Copy link
Member Author

lzap commented Oct 10, 2023

Rebased the docs-only change.

@ezr-ondrej
Copy link
Member

/retest

@lzap
Copy link
Member Author

lzap commented Oct 10, 2023

Fails on unexpected backend data that is the error we talked about on scrum. Something is deleting source prior this request. @akhil-jha any ideas?

@akhil-jha
Copy link
Member

The error here is - image builder couldn't find the image. Becuase it expired. Will have to update the images for the stub. This is not related to the error sources we were talking about :)

@lzap
Copy link
Member Author

lzap commented Oct 11, 2023

/retest

@ezr-ondrej
Copy link
Member

Thanks! 🧡

@ezr-ondrej ezr-ondrej merged commit ac740ed into RHEnVision:main Oct 11, 2023
6 checks passed
@lzap lzap deleted the kafka-better-logging branch October 11, 2023 14:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants