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

Can't pass token in credentials config file (newline issue) #16547

Closed
lafrech opened this issue Jan 15, 2020 · 6 comments · Fixed by #16562
Closed

Can't pass token in credentials config file (newline issue) #16547

lafrech opened this issue Jan 15, 2020 · 6 comments · Fixed by #16562

Comments

@lafrech
Copy link

lafrech commented Jan 15, 2020

Steps to reproduce:

Following instructions in https://v2.docs.influxdata.com/v2.0/reference/cli/influx/#usage, I set the token in my config file.

I get an error when trying to use it.

echo "8UJX0DXOqJV28U2nBSnrmYeZWD611G60_5AZkTS0tzIuNIZcF2OtCYAjiJgPMp8btaDSjlKBY1Jg==" > .influxdbv2/credentials

influx auth find
Error: Get http://localhost:9999/api/v2/authorizations: net/http: invalid header field value "Token KCB0Dshl2-8UJX0DXOqJV28U2nBSnrmYeZWD611G60_5AZkTS0tzIuNIZcF2OtCYAjiJgPMp8btaDSjlKBY1Jg==\n" for key Authorization.

However, it works by passing the token in the command line or in an environment variable.

influx auth find -t KCB0Dshl2-8UJX0DXOqJV28U2nBSnrmYeZWD611G60_5AZkTS0tzIuNIZcF2OtCYAjiJgPMp8btaDSjlKBY1Jg==
ID			Token												Status	User	UserID			Permissions
05151712a2029000	KCB0Dshl2-8UJX0DXOqJV28U2nBSnrmYeZWD611G60_5AZkTS0tzIuNIZcF2OtCYAjiJgPMp8btaDSjlKBY1Jg==	active	<nil>	051517128e029000	[read:authorizations write:authorizations read:buckets write:buckets read:dashboards write:dashboards read:orgs write:orgs read:sources write:sources read:tasks write:tasks read:telegrafs write:telegrafs read:users write:users read:variables write:variables read:scrapers write:scrapers read:secrets write:secrets read:labels write:labels read:views write:views read:documents write:documents read:notificationRules write:notificationRules read:notificationEndpoints write:notificationEndpoints read:checks write:checks]

export INFLUX_TOKEN=KCB0Dshl2-8UJX0DXOqJV28U2nBSnrmYeZWD611G60_5AZkTS0tzIuNIZcF2OtCYAjiJgPMp8btaDSjlKBY1Jg==
influx auth find
ID			Token												Status	User	UserID			Permissions
05151712a2029000	KCB0Dshl2-8UJX0DXOqJV28U2nBSnrmYeZWD611G60_5AZkTS0tzIuNIZcF2OtCYAjiJgPMp8btaDSjlKBY1Jg==	active	<nil>	051517128e029000	[read:authorizations write:authorizations read:buckets write:buckets read:dashboards write:dashboards read:orgs write:orgs read:sources write:sources read:tasks write:tasks read:telegrafs write:telegrafs read:users write:users read:variables write:variables read:scrapers write:scrapers read:secrets write:secrets read:labels write:labels read:views write:views read:documents write:documents read:notificationRules write:notificationRules read:notificationEndpoints write:notificationEndpoints read:checks write:checks]

From the error, it seems a \n is added at the end of the token. I don't see how to remove it. Maybe this is a user issue, but even so, influx should be able to remove it.

(The lines were not edited. This is a test instance in a VM not meant to be exposed so I don't mind the token appearing here.)

Environment info:

  • Linux 4.19.0-6-amd64 x86_64
  • InfluxDB 2.0.0-beta.1 (git: 128b9ee) build_date: 2020-01-15T14:50:20Z
@russorat
Copy link
Contributor

@lafrech you should be able to use echo -n "token" > .influxdbv2/credentials

but we should also not throw that error. we will look into fixing that.

@jsteenb2
Copy link
Contributor

shouldn't be logging that token either I imagine 🤔

@jsteenb2 jsteenb2 self-assigned this Jan 15, 2020
@jsteenb2
Copy link
Contributor

jsteenb2 commented Jan 15, 2020

@lafrech I'm looking into this. I'm unable to reproduce on my local (darwin). It looks like you have the newline in the auth header. Try running the echo -n "token" > .influxdbv2/credentials which will trim the /n using the -n. In your error, you have the /n there which is coming from your credentials file.

Let me know if that doesn't fix things up. Otherwise, go on and close the issue and happy hacking 😃

@lafrech
Copy link
Author

lafrech commented Jan 16, 2020

Thank you for your quick answers.

With the -n argument, it works fine.

echo -n "token" > .influxdbv2/credentials

However, without it, or if I just open the file with vim and paste the token, I get above error.

hexdump confirms there's that spurious 000a at the end of the file when it fails.

This could be qualified as a user issue (I should have known about -n) but I think Influx should be able to rip the \n off. I've never encountered this with other software reading config files. Therefore, I'm leaving this open. Feel free to close as wontfix.

@jsteenb2
Copy link
Contributor

@lafrech that's a great point. I'll throw something together to remedy that, great suggestion 👍

@lafrech lafrech changed the title Can't pass token in credentials config file (newline issue ?) Can't pass token in credentials config file (newline issue) Jan 16, 2020
@jsteenb2
Copy link
Contributor

merged and sealed @lafrech 👍, thanks again for your patience and pro-activity 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants