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 certificate options for all commands #86

Merged
merged 2 commits into from
Oct 27, 2018
Merged

add certificate options for all commands #86

merged 2 commits into from
Oct 27, 2018

Conversation

rwaweber
Copy link
Contributor

Despite the branch name these changes would add certificate support to all available commands.

Happy to restructure them if this could be improved/simplified!

@fgeller
Copy link
Owner

fgeller commented Oct 11, 2018 via email

Copy link
Owner

@fgeller fgeller left a comment

Choose a reason for hiding this comment

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

@rwaweber finally back home, thanks for waiting and thanks a lot for your work and time!

the changes to look good to me, i have one suggestion for changing the setup per command and suggested some naming changes in common.go. have you tested the changes? would you mind writing a test for them?
let me know if you want to continue on this or if you want me to pull in your changes and continue working on it. in any case, thanks for pushing this forward! 🙏

common.go Outdated
}

caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)
Copy link
Owner

Choose a reason for hiding this comment

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

// It appends any certificates found to s and reports whether any certificates
// were successfully parsed.

I'd suggest we check that AppendCertsFromPEM returns true, or?

common.go Outdated
return nil, err
}

caCertPool := x509.NewCertPool()
Copy link
Owner

Choose a reason for hiding this comment

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

certs might be a more concise name in this case?

Copy link
Owner

Choose a reason for hiding this comment

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

you might choose to drop a couple of certs from other names - the context of the function should be enough for a reader, what do you think? ie, for the func args cert, ca, key string

@@ -275,6 +287,16 @@ func (cmd *consumeCmd) setupClient() {
if cmd.verbose {
fmt.Fprintf(os.Stderr, "sarama client configuration %#v\n", cfg)
}
// AFAIK kafka authentication only works when the ca, cert and certkey are
// presented.
Copy link
Owner

Choose a reason for hiding this comment

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

let's pull most of this into common.go - then we don't need this differently for every command and could add a bit more ui-friendliness. e.g.:

func setupTLSConfig(cert, ca, key string) (tls.Config, error) {

then when we setup the commands we'd use it like this:

tls, err := setupTLSConfig(cmd.tlsCert, cmd.tlsCA, cmd.tlsKey)
if err != nil {
  failf("failed to setup TLS config err=%v", err)
}
if tls != nil {
  cfg.Net.TLS.Enable = true
  cfg.Net.TLS.Config = tls
}

so setupTLSConfig could return errors like TLS cert was supplied, but CA or key is missingand we'd keep the duplication in the command minimal. what do you think?
untested code btw 😇

@rwaweber
Copy link
Contributor Author

Great suggestions all around! I'm not sure if I totally understood the third section but I tossed around two approaches:

  1. Clean up the invocation of the setupCerts function in each of the command's, set the variables for the sarama config closer together(what I went with).
  2. Passing in a sarama config object to the setupCerts function, or a function with 80% of the same body, that would also set the sarama config variables and return the, now modified, sarama config. I wasn't too much of a fan of this approach as I feel like it overcomplicated this function a bit and felt that most of the interaction with the sarama config should be handled with the rest of the functions that deal with it.

Totally down to revise my approach here as well!

In terms of testing, I've been using this branch at work without issue! Unfortunately, a tls-enabled kafka cluster isn't trivial to setup for CI/integration test purposes, at least the last time I took a look at it.

@fgeller
Copy link
Owner

fgeller commented Oct 27, 2018

@rwaweber awesome, thanks for that! i'll pull this in as is, and will apply a change so that we provide feedback if only one or two of ca, cert and key are provided. i'd ping you on the PR if you're interested.

re testing: depending on time, i'll try my hands at changing the system test - but if you're using this as is I don't see any reason not to pull this into master (ie, these changes should not interfere if someone isn't supplying the TLS specific args)

@fgeller fgeller merged commit fe39f5f into fgeller:master Oct 27, 2018
@fgeller fgeller mentioned this pull request Oct 27, 2018
@rwaweber rwaweber deleted the add_tls_consumer_support branch October 27, 2018 20: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.

2 participants