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

Http plugin add cookie auth #9395

Merged
merged 11 commits into from
Jul 13, 2021

Conversation

jh125486
Copy link
Contributor

Required for all PRs:

  • Updated associated README.md.
  • Wrote appropriate unit tests.

resolves #5932

  1. Added a few configuration options for inputs.http cookie auth:
    auth url
    body
    method
    refresh interval
  2. HTTP Client is updated to use a CookieJar
  3. During plugin Init(), a initial auth is attempted and is successful, a Go routine is fired off for cookie auth renewal

@telegraf-tiger telegraf-tiger bot added the feat Improvement on an existing feature such as adding a new setting/mode to an existing plugin label Jun 18, 2021
Copy link
Member

@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.

Hey @jh125486, thanks for tackling this issue!

The code, with one exeception, looks good with only minor issues (see my comments in the code). However, I have a big concern reusing the http client for the cookie authentication as you are also reusing e.g. username and password with a URL potentially different to the settings in urls. This might leak sensible data.

Furthermore, I ask myself if this new feature wouldn't be a good candidate to add to plugins/common/http so it can be reused by other plugins as well. Do you think this makes sense?

@srebhan srebhan self-assigned this Jun 18, 2021
@srebhan srebhan added the plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins label Jun 18, 2021
@jh125486
Copy link
Contributor Author

jh125486 commented Jun 18, 2021

Hey @jh125486, thanks for tackling this issue!

The code, with one exeception, looks good with only minor issues (see my comments in the code). However, I have a big concern reusing the http client for the cookie authentication as you are also reusing e.g. username and password with a URL potentially different to the settings in urls. This might leak sensible data.

Furthermore, I ask myself if this new feature wouldn't be a good candidate to add to plugins/common/http so it can be reused by other plugins as well. Do you think this makes sense?

I can move it to plugins/common/http ... I wasn't even aware that was there really :)
Does it make more sense in the telegraf codebase to have it in plugins/common/cookie and embed it into the plugins/common/http HTTPClientConfig (mirroring the HTTPProxy and TLS config)?

Regarding the http.Client re-use, there should be no direct leaking of creds with using the same client, since that is per-request. Currently the HTTP Basic Auth and OAuth mechanisms are for all URLs in the URLs slice, so that leak is already happening.
As for using the same auth methods/headers for the Cookie Auth, I can definitely break that out into a separate request fn.

jh125486 added 3 commits June 21, 2021 17:54
updated both plugins/inputs/http and plugins/outputs/http sample config/READMEs
Copy link
Member

@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.

Wow that's really nice. I have some more comments and questions, but I think we are very close. Thanks for working on this!

Copy link
Member

@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.

Almost. I had one idea about passing the auth() errors to the caller using a non-blocking channel. Maybe you can check if this is doable.
Furthermore, I see the timing issues in your tests. While I do not have a good idea on how to do it correctly in your case, I fear flakey tests in later (unrelated) PRs (we have been there...).

Copy link
Member

@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.

One more suggestion for allowing to omit the logging. There might be some plugins that do not have a logger.
Otherwise this looks good.

Copy link
Member

@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 to me. Thanks @jh125486 for working hard to get this PR to the current state!

@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 Jun 28, 2021
Copy link
Member

@helenosheaa helenosheaa left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, looks good. I think it would be useful if you could provide more information in the readme as to the use-case of this. So new users can understand why they might want to use verses when they don't need to use this setting.

@jh125486
Copy link
Contributor Author

jh125486 commented Jul 4, 2021

provide more information in the readme as to the use-case of this. So new users can understand why they might want to use verses when they don't need to use this setting.

The READMEs currently do not reference any of the options within the toml, so what section name should I create for this?

@srebhan
Copy link
Member

srebhan commented Jul 6, 2021

@jh125486 I guess @helenosheaa wants a small section of text in plugins/inputs/http/README.md (and plugins/outputs/http/README.md accordingly) describing under which circumstances a user should fill this. Is there e.g. a certain popular service that uses this type of authentication that you could use as an example?
So something like

Cookie authentication allows to derive an authentication cookie from a server providing your credentials as body. A popular example is XYZ which work with the following configuration...

@jh125486
Copy link
Contributor Author

jh125486 commented Jul 6, 2021

@jh125486 I guess @helenosheaa wants a small section of text in plugins/inputs/http/README.md (and plugins/outputs/http/README.md accordingly) describing under which circumstances a user should fill this. Is there e.g. a certain popular service that uses this type of authentication that you could use as an example?
So something like

Cookie authentication allows to derive an authentication cookie from a server providing your credentials as body. A popular example is XYZ which work with the following configuration...

Correct, so what should the name of that section be?

@helenosheaa
Copy link
Member

@jh125486 perhaps - Optional Cookie Authentication Settings: with the explanation and an example config.

@MyaLongmire
Copy link
Contributor

MyaLongmire commented Jul 6, 2021

This is looking great so far! Can you please add a sample config? Also, is there any way to make your optional cookie authentication section a little shorter? It seems a touch wordy.

@jh125486
Copy link
Contributor Author

jh125486 commented Jul 6, 2021

This is looking great so far! Can you please add a sample config? Also, is there any way to make your optional cookie authentication section a little shorter? It seems a touch wordy.

  1. An example config in addition to the example config in the README? What should that file be called?
  2. That section is three sentences long. What is the max number of sentences I should have?

@srebhan
Copy link
Member

srebhan commented Jul 7, 2021

@MyaLongmire there is the usual sample-config part in the http input/output sections (options starting with cookie_auth_). Do you have a suggestion on how to shorten the text?

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 plugin/input 1. Request for new input plugins 2. Issues/PRs that are related to input plugins ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

input http_response cookies and sessions
4 participants