Skip to content

Conversation

andreaskapfer
Copy link
Contributor

This PR adds the ability to authenticate to Elasticsearch via client certificate.

It also fixes some bugs related to the options ca_file and ca_data.

@elasticmachine
Copy link

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

Copy link
Member

@tobio tobio left a comment

Choose a reason for hiding this comment

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

Sorry for the delay here, took a little longer to spin up a cluster with PKI auth to test this.

Couple of nits on the code.

Comment on lines 130 to 131
ensureTLSClientConfig(&config)
config.Transport.(*http.Transport).TLSClientConfig.Certificates = []tls.Certificate{cert}
Copy link
Member

Choose a reason for hiding this comment

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

IMO these blocks would likely read more nicely if ensureTLSClientConfig returned a *http.Transport so the subsequent code could avoid the casts. WDYT?

To be clear: "You're wrong because..." is totally fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! I would even go one step further. What about returning *tls.Config?
I guess everyone calling ensureTLSClientConfig wants to customize TLSClientConfig afterwards.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds great, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}

if certFile, ok := esConfig["cert_file"]; ok && certFile.(string) != "" {
if keyFile, ok := esConfig["key_file"]; ok && keyFile.(string) != "" {
Copy link
Member

Choose a reason for hiding this comment

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

I know this is enforced in the schema, but IMO we should return an error if cert_file is ok but key_file is not ok.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}
}
if certData, ok := esConfig["cert_data"]; ok && certData.(string) != "" {
if keyData, ok := esConfig["key_data"]; ok && keyData.(string) != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Similarly, I think this code should error out if cert_data is specified without key_data

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}

if certFile, ok := conn["cert_file"]; ok && certFile.(string) != "" {
if keyFile, ok := conn["key_file"]; ok && keyFile.(string) != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Similarly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}
}
if certData, ok := conn["cert_data"]; ok && certData.(string) != "" {
if keyData, ok := conn["key_data"]; ok && keyData.(string) != "" {
Copy link
Member

Choose a reason for hiding this comment

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

Similarly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@andreaskapfer andreaskapfer requested a review from tobio November 22, 2022 12:04
@tobio tobio merged commit 5adb0f6 into elastic:main Nov 23, 2022
@tobio
Copy link
Member

tobio commented Nov 23, 2022

Thanks for this @andreaskapfer we'll have a new version of the provider out with this change in the next few weeks.

@andreaskapfer
Copy link
Contributor Author

Great! Many thanks for the review @tobio

@tobio
Copy link
Member

tobio commented Dec 7, 2022

This has been released with 0.5.0

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