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

inputs.http cookie_auth_headers cannot unmarshal TOML string into map[string]string #11134

Closed
antitbone opened this issue May 18, 2022 · 8 comments · Fixed by #11472
Closed
Labels
area/influxdb bug unexpected problem or unintended behavior

Comments

@antitbone
Copy link

antitbone commented May 18, 2022

Relevant telegraf.conf

# isilon

[[inputs.http]]
  urls = [
    "https://isilon:8080/platform/1/snapshot/snapshots-summary"
  ]

  cookie_auth_url = "https://isilon:8080/session/1/session"
  cookie_auth_method = "POST"
  cookie_auth_headers = '{"Content-Type": "application/json"}'
  cookie_auth_body = '{"username": "XXX", "password": "XXX, "services": ["platform"]}'
  cookie_auth_renewal = "6h"

  name_override = "snapshots"
  insecure_skip_verify = true
  data_format = "json"
  [inputs.http.tags]
    isilon_host = "isilon"


[[outputs.influxdb]]
  urls = ["http://influx:8086"]
  database = "XXX"
  username = "XXX"
  password = "XXX"
  skip_database_creation = true
  [outputs.influxdb.tagpass]
    isilon_host  = ["isilon"]

Logs from Telegraf

2022-05-18T15:11:18Z E! [telegraf] Error running agent: Error loading config file /etc/telegraf/telegraf.d/isilon-dna.conf: error parsing http, line 10: (http.HTTP.Headers) cannot unmarshal TOML string into map[string]string

System info

telegraf-1.22.4

the "cookie_auth_headers" parameter does not seem to work

The error also occurs with the default parameter:

cookie_auth_headers = '{"Content-Type": "application/json", "X-MY-HEADER":"hello"}'
curl -ik https://isilonr:8080/session/1/session -X POST -H 'Content-Type: application/json' -d '{ "username": "XXX", "password": "XXX", "services": ["platform"] }'

HTTP/1.1 201 Created
Date: Wed, 18 May 2022 15:15:16 GMT
Server: Apache
X-Frame-Options: sameorigin
Strict-Transport-Security: max-age=31536000;
Set-Cookie: isisessid=17a4416e-52ee-4dc3-b33c-c6cf1cf91e69; path=/; HttpOnly; Secure; SameSite=strict
Set-Cookie: isicsrf=bb8b666a-acd5-4294-b30f-fff134529e29; path=/; Secure
Content-Length: 92
Content-Type: application/json
@antitbone antitbone added the bug unexpected problem or unintended behavior label May 18, 2022
@powersj
Copy link
Contributor

powersj commented May 19, 2022

Hi,

I believe you are trying to use a string, when you should be using a map like this:

 cookie_auth_body = {"username" = "XXX", "password" = "XXX, "services" = ["platform"]}

Can you give that a try? we may need to update the example config.

@powersj powersj added the waiting for response waiting for response from contributor label May 19, 2022
@antitbone
Copy link
Author

The error remains the same.

2022-05-23T06:19:13Z E! [telegraf] Error running agent: Error loading config file /etc/telegraf/telegraf.conf: Error parsing data: line 11: invalid TOML syntax

I deleted any configuration other than the lines below.

[[inputs.http]]
  urls = [
    "https://isilon:8080/platform/1/snapshot/snapshots-summary"
  ]

  cookie_auth_url = "https://isilon:8080/session/1/session"
  cookie_auth_method = "POST"
  cookie_auth_headers = '{"Content-Type": "application/json"}'
  cookie_auth_body = {"username": "XXXX", "password": "XXXX", "services": ["platform"]}
  cookie_auth_renewal = "6h"

  name_override = "snapshots"
  insecure_skip_verify = true
  data_format = "json"
  [inputs.http.tags]
    isilon_host = "isilon"


[[outputs.influxdb]]
  urls = ["http://influx:8086"]
  database = "isilon"
  username = "isilon"
  password = "XXX"
  skip_database_creation = true
  [outputs.influxdb.tagpass]
    isilon_host  = ["isilon"]

@telegraf-tiger telegraf-tiger bot removed the waiting for response waiting for response from contributor label May 23, 2022
@powersj
Copy link
Contributor

powersj commented May 23, 2022

{"username": "XXXX", "password": "XXXX", "services": ["platform"]}

Ah if I had slowed down a bit more I would have noticed that these are not all strings. It is assumed that the body is a string key and value and that platform is not a string, but an array.

@powersj powersj added the waiting for response waiting for response from contributor label May 23, 2022
@telegraf-tiger
Copy link
Contributor

telegraf-tiger bot commented Jun 6, 2022

Hello! I am closing this issue due to inactivity. I hope you were able to resolve your problem, if not please try posting this question in our Community Slack or Community Page. Thank you!

@telegraf-tiger telegraf-tiger bot closed this as completed Jun 6, 2022
@antitbone
Copy link
Author

A very late response.

With the TOML syntax the parameter cookie_auth_headers is valid.

cookie_auth_headers = { Content-Type = "application/json"}
cookie_auth_body = '{"username": "XXX", "password": "XXX", "services": ["platform"]}'

The plugin.http documentation can be updated to not mislead:

# cookie_auth_headers = '{"Content-Type": "application/json", "X-MY-HEADER":"hello"}'

# cookie_auth_headers = '{"Content-Type": "application/json", "X-MY-HEADER":"hello"}'

# cookie_auth_headers = '{"Content-Type": "application/json", "X-MY-HEADER":"hello"}'

A second problem occurs with authentication.
Dell isilon array returns http code 201.

2022-07-01T12:47:20Z E! [telegraf] Error running agent: could not initialize input inputs.http: cookie auth renewal received status code: 201 (Created)
StatusOK                   = 200 // RFC 7231, 6.3.1
StatusCreated            = 201 // RFC 7231, 6.3.2

But the test only accepts code 200

if resp.StatusCode != http.StatusOK {
return fmt.Errorf("cookie auth renewal received status code: %v (%v)",
resp.StatusCode,
http.StatusText(resp.StatusCode),
)
}

@telegraf-tiger telegraf-tiger bot removed the waiting for response waiting for response from contributor label Jul 1, 2022
@powersj
Copy link
Contributor

powersj commented Jul 1, 2022

Hi,

The plugin.http documentation can be updated to not mislead:

Can you confirm you are suggesting this change:

--- cookie_auth_headers = '{"Content-Type": "application/json", "X-MY-HEADER":"hello"}' 
+++ cookie_auth_headers = { Content-Type = "application/json" }

But the test only accepts code 200

I think checking for 201 is something we could change. Let me know about the doc change.

@powersj powersj reopened this Jul 1, 2022
@powersj powersj added the waiting for response waiting for response from contributor label Jul 1, 2022
@antitbone
Copy link
Author

I suggest this change

--- cookie_auth_headers = '{"Content-Type": "application/json", "X-MY-HEADER":"hello"}' 
+++ cookie_auth_headers = { Content-Type = "application/json", X-MY-HEADER = "hello" }

@telegraf-tiger telegraf-tiger bot removed the waiting for response waiting for response from contributor label Jul 5, 2022
powersj added a commit to powersj/telegraf that referenced this issue Jul 7, 2022
This allows both a 200 and 201 response code when generating auth using
the cookie auth plugin. Additionally, this updates the docs for the
cookie headers to show a TOML map rather than a string.

fixes: influxdata#11134
@powersj
Copy link
Contributor

powersj commented Jul 7, 2022

@antitbone can you take a look at #11472?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/influxdb bug unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants