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

Wildcard support for x509_cert files #6952

Merged
merged 12 commits into from Mar 23, 2021

Conversation

jaroug
Copy link
Contributor

@jaroug jaroug commented Jan 29, 2020

Required for all PRs:

  • Signed CLA.
  • Associated README.md updated.
  • Has appropriate unit tests. (as much as there is no existing ones)

Closes #6951

@jaroug
Copy link
Contributor Author

jaroug commented Jan 29, 2020

Fixes #6951

plugins/inputs/x509_cert/x509_cert.go Outdated Show resolved Hide resolved
plugins/inputs/x509_cert/x509_cert.go Outdated Show resolved Hide resolved
@danielnelson danielnelson added the feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin label Feb 6, 2020
@danielnelson danielnelson changed the title Inputs/x509 cert Wildcard support for x509_cert files Apr 21, 2020
@jaroug jaroug requested a review from danielnelson May 13, 2020 10:12
@ikkemaniac
Copy link

Would this also allow to add a complete dir?

["/etc/certs/*"]

@jaroug
Copy link
Contributor Author

jaroug commented Jul 25, 2020

Would this also allow to add a complete dir?

["/etc/certs/*"]

Yes :)

@ikkemaniac
Copy link

Would this also allow to add a complete dir?

["/etc/certs/*"]

Yes :)

AWEsome, let's hope this get's merged quickly.

I should be able to build it from 9309072 right?

@jaroug
Copy link
Contributor Author

jaroug commented Jul 25, 2020

Would this also allow to add a complete dir?

["/etc/certs/*"]

Yes :)

AWEsome, let's hope this get's merged quickly.

I should be able to build it from 9309072 right?

I just rebased master, resolved the merge conflict, it works :)

@ikkemaniac
Copy link

Took a little bit to x-compile but i got r running. No strange things yet so thumbs up from me!

Thx bud!

@MatthewGow
Copy link

Wow, this is exactly what we were looking to do - great work @jaroug !

@danielnelson - is there anything holding up the review of this other than time?

@VorobevPavel-dev
Copy link

VorobevPavel-dev commented Feb 11, 2021

It’s sad that it’s been all year since PR was created. Maybe there is something new or you just forgot about it. Very useful functions and features cannot be added for a whole year. Please, take a look, @danielnelson, @jaroug

@ssoroka ssoroka requested review from ssoroka and removed request for danielnelson February 11, 2021 20:21
var allFiles []string

for _, source := range c.Sources {
if strings.HasPrefix(source, "/") {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should swap the order of processing and first call sourcesToURLs() and afterwards this function. This way you can be sure that file always have file:// prepended. Otherwise you might miss files where the user added file:// already for you.

Suggested change
if strings.HasPrefix(source, "/") {
if strings.HasPrefix(source, "file://") {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the globing tools don't work with url styled path, so I'll have to strip the leading file://

if len(files) <= 0 {
return fmt.Errorf("could not find file: %v", source)
}
allFiles = append(allFiles, files...)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please remember to prepend file:// again here after swapping functions.

Comment on lines 273 to 310
err := c.refreshFilePaths()
if err != nil {
return err
}

err = c.sourcesToURLs()
if err != nil {
return err
}

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's better to swap these functions so refreshFilePaths() (which might be called expandFilePaths()) can work on normalized inputs as otherwise you miss entries where the user specified files in the form file:///etc/certs/*.

Copy link
Contributor

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

I suggest swapping the two functions in Init() and work on normalized URLs instead of relying on the user not specifying file:// prefixed with wildcards. See my comments in the code.

@srebhan srebhan self-assigned this Feb 12, 2021
Copy link
Contributor

@ssoroka ssoroka left a comment

Choose a reason for hiding this comment

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

looks like it needs some merge conflicts resolved. Any additional test coverage would be great, but not a blocker.

@sjwang90
Copy link
Contributor

@jaroug If you can address the comments from @srebhan and @ssoroka we can do another review and look to get this into our next feature release. Thanks!

@jaroug
Copy link
Contributor Author

jaroug commented Feb 17, 2021

@sjwang90 gonna have a look asap

Copy link
Contributor

@srebhan srebhan left a comment

Choose a reason for hiding this comment

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

Looks good so far. Only one more question: You now moved the globbing to Init() which means you won't catch new certs and maybe will poke old (already deleted) certs. Is this by intention? Maybe it would make sense to take the extra cycles and update the cert-list in every gather-cycle?!?

@jaroug
Copy link
Contributor Author

jaroug commented Feb 22, 2021

@srebhan it was requested by the previous person holding the PR: #6952 (comment)

@srebhan
Copy link
Contributor

srebhan commented Feb 23, 2021

@jaroug almost, if you read the comment you cited carefully the idea was to prepare the glob-statement in Init() but call the Match() method in each gather cycle. Do you think this is doable to prepare the glob statement in Init() then call the Match() for the glob entries in Gather() and join the result with the static entries? This would mean to split the refreshFilePaths() function into two parts...

@jaroug
Copy link
Contributor Author

jaroug commented Feb 23, 2021

@srebhan oh yeah ok, I totally misunderstood, my bad, I'll have a look asap

@sjwang90
Copy link
Contributor

sjwang90 commented Mar 2, 2021

Hi @jaroug, just checking on the status. We're hoping for a Telegraf 1.18 release candidate this week and would love to get this in.

@jaroug
Copy link
Contributor Author

jaroug commented Mar 3, 2021

👋 I made those changes a bit in a hurry so it might be far from perfect but it seems to work. I haven't considered searching for globpath on "file://" inputs since I'm not sure it's supposed to be supported by the URL package, should I?

@srebhan srebhan added the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label Mar 4, 2021
@ikkemaniac
Copy link

*sees 'ready to merge' tag

is this really happening ? 🤞

@jaroug
Copy link
Contributor Author

jaroug commented Mar 8, 2021

*sees 'ready to merge' tag

is this really happening ?

Well hopefully, poke @sjwang90

@srebhan
Copy link
Contributor

srebhan commented Mar 9, 2021

@jaroug and @ikkemaniac please stay calm and let the Influx guys do their job. It might take some more time due to the amount of PRs they have to handle and the way PRs are merged during the release cycle. So poking at this every second day takes away review resources (e.g. mine ;-))...

@ssoroka
Copy link
Contributor

ssoroka commented Mar 10, 2021

Looks good, but i'd like to see some tests. also looks like the existing tests are failing in windows.

}
for _, file := range files {
file = "file://" + file
u, err := url.Parse(file)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this causes windows tests to fail, as it assumes the path is a linux-style path. On windows the path will start with C: or something and it will recognize the colon as a port. A workaround for windows is adding an extra slash to the file:// part but it looks like there might be other issues (see: golang/go#13276). I'm thinking maybe we'd just need to manually handle the windows case here, not 100% sure but we will need it to work on windows.

@reimda
Copy link
Contributor

reimda commented Mar 18, 2021

Hi @jaroug, are you able/willing to fix this windows path problem? If not, let us know and we'll try to find someone who can. This PR is useful and I'd hate to see it stagnate again after getting so close to being merged! Thanks!

@srebhan srebhan removed the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label Mar 19, 2021
Anthony LE BERRE added 11 commits March 21, 2021 14:16
* rename refreshFilePaths to expandFilePaths
* expandFilePaths handles '/path/to/*.pem' and 'files:///path/to/*.pem'
* update sample config
 * add var globFilePathsToUrls to stack files path
 * add var globpaths to stack compiled globpath
 * rework sourcesToURLs to compile files path and stack them
 * rename expandFilePaths to expandFilePathsToUrls
 * rework expandFilePathsToUrls to only match compiled globpath
 * rework the `Gather` ticker to match globpath at each call
 * add specifics regarding relative paths in sample config
 * add logger and use it in expandFilePathsToUrls()
 * precompile glob for `files://`, `/` and `://`
 * rename expandFilePathsToUrls() to collectCertURLs()
 * collectCertURLs() now returns []*url.URL to avoid extra field
globFilePathsToUrls in structure
 * update the Gather() ticker accordingly
Copy link
Contributor

@telegraf-tiger telegraf-tiger bot left a comment

Choose a reason for hiding this comment

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

Copy link
Contributor

@telegraf-tiger telegraf-tiger bot left a comment

Choose a reason for hiding this comment

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

@jessingrass jessingrass merged commit b2b3613 into influxdata:master Mar 23, 2021
jblesener pushed a commit to jblesener/telegraf that referenced this pull request Apr 18, 2021
* Accept standard unix glob matching rules

* comply with indentation

* update readme

* move globing expand and url parsing into Init()

* chore: rebase branch on upstream master

* rename refreshFilePaths to expandFilePaths
* expandFilePaths handles '/path/to/*.pem' and 'files:///path/to/*.pem'
* update sample config

* fix: recompile files globing pattern at every gather tic

 * add var globFilePathsToUrls to stack files path
 * add var globpaths to stack compiled globpath
 * rework sourcesToURLs to compile files path and stack them
 * rename expandFilePaths to expandFilePathsToUrls
 * rework expandFilePathsToUrls to only match compiled globpath
 * rework the `Gather` ticker to match globpath at each call

* fix: comply with requested changes

 * add specifics regarding relative paths in sample config
 * add logger and use it in expandFilePathsToUrls()
 * precompile glob for `files://`, `/` and `://`

* fix: update README to match last changes

* fix: comply with last requested changes

 * rename expandFilePathsToUrls() to collectCertURLs()
 * collectCertURLs() now returns []*url.URL to avoid extra field
globFilePathsToUrls in structure
 * update the Gather() ticker accordingly

* fix(windows): do not try to compile glopath for windows path as it's not supposed to be supported by the OS

* fix(ci): apply go fmt

* fix(ci): empty-lines/import-shadowing

Co-authored-by: Anthony LE BERRE <aleberre@vente-privee.com>
@aslgithub
Copy link

This Pull seems to be the only change I can obviously find between v1.18.1 and v1.19.0 for x509_cert and I'm concerned it may have broken URL testing on Windows ?
#9384

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

wildcard (glob) support for files sources in plugins/inputs/x509_cert (PR included)