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

Added flag to skip TLS verification when connection to ES #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ekrucio
Copy link

@ekrucio ekrucio commented Oct 17, 2022

This PR is a continuation of my last PR in this repository -> Original declined PR and I tried to implement the proposed changes.

Since Elastic 8.0 onwards Security is enabled by default Security settings in Elasticsearch .

Currently this tool has no means to handle some pretty common cases related to HTTPS communication, such as certificate verification. Currently it skips the whole certificate verification. Could be extented if the need arises.
Also, another drawback I encountered was the usage of the default http client in Go.
The way it is implemented it never timeouts, which could be a problem. I added a default limit of 600 seconds (10 minutes) to the command.
For our usecase we needed a way to identify the git author and thus added it to the mapping.
It's enabled by default for everyone, since I decided that this may be pretty common scenario, if needed I can flag it.

func addVCS(pkgpath string, doc map[string]interface{}) {
pkg, err := build.Import(pkgpath, "", build.FindOnly)
func addVCS(pkgpath string, doc map[string]interface{}) error {
pkg, err := build.Import(pkgpath, "", build.IgnoreVendor)
Copy link
Member

Choose a reason for hiding this comment

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

Should this be build.FindOnly | build.IgnoreVendor?

}
resp, err := http.DefaultClient.Do(req)

req.WithContext(ctx)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
req.WithContext(ctx)
req = req.WithContext(ctx)

@@ -279,7 +330,10 @@ func createMapping(cfg elasticsearchConfig) error {
req.SetBasicAuth(cfg.user, cfg.pass)
}
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)

req.WithContext(ctx)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
req.WithContext(ctx)
req = req.WithContext(ctx)

WithContext does not mutate the original context.

Comment on lines +195 to +197
flag.BoolVar(&cfg.shouldSkipTlsVerify, "tls-verify", true,
"Should skip TLS verification.",
)
Copy link
Member

Choose a reason for hiding this comment

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

The flag says "should skip ...", but the name presented to the user is "tls-verify" -- the name implies the reverse of what it's doing.

Copy link
Member

Choose a reason for hiding this comment

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

BTW in #3 (comment), I said that the default should be true. I misread the flag as "should verify" because of the name. So what I actually want is to verify by default, and users can opt out if they like.

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