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 401 Unauthorized #26

Closed
miguelemosreverte opened this issue Jul 27, 2020 · 22 comments · Fixed by #323
Closed

HTTP 401 Unauthorized #26

miguelemosreverte opened this issue Jul 27, 2020 · 22 comments · Fixed by #323
Assignees

Comments

@miguelemosreverte
Copy link

the bug

grr apply mydash.libsonnet 
Folder not found and/or configured. Applying to "General" folder.
2020/07/27 12:17:01 Error retrieving dashboard my-dash.json: 401 Unauthorized
@miguelemosreverte
Copy link
Author

the explanation

Per the documentation, Grafana explicitely shows how the call protocol should include the Authentication headers, look!
Screenshot from 2020-07-27 13-03-14

Calling without headers, like Grizzly does as of now:

curl http://api_key:eyJrIjoielBIZ1BYdWJVRWVQQ2dKYkM4S0ZQcmtDd3NSa2hCZFQiLCJuIjoiYXBpX2tleSIsImlkIjoxfQ==@localhost:3000/api/org
{"message":"Basic auth failed"}

Calling with headers:

curl http://api_key:eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFeyJrIjoielBIZ1BYdWJVRWVQQ2dKYkM4S0ZQcmtDd3NSa2hCZFQiLCJuIjoiYXBpX2tleSIsImlkIjoxfQ==@localhost:3000/api/org  -H "Authorization: Bearer eyJrIjoidnBBaXhUdVQyS0VaWlJ4bGR6YWF4M3h4U3RTdllQem4iLCJuIjoiYXBpX2tleSIsImlkIjoxfQ=="
{"id":1,"name":"Main Org.","address":{"address1":"","address2":"","city":"","zipCode":"","state":"","country":""}}

@miguelemosreverte
Copy link
Author

the solution

By setting the Authorization header for all requests to Grafana, now I can hit Grafana successfully.
Screenshot from 2020-07-27 13-15-01

@trotttrotttrott
Copy link
Member

It shouldn't make a difference. In the docs right below where your screen shot cuts off, it states:

The API Token can also be passed as a Basic authorization password with the special username api_key...

Furthermore, it looks like your API key may be copied incorrectly in your examples.

curl http://api_key:eyJrIjoielBIZ1BYdWJVRWVQQ2dKYkM4S0ZQcmtDd3NSa2hCZFQiLCJuIjoiYXBpX2tleSIsImlkIjoxfQ==@localhost:3000/api/org

curl http://api_key:eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFeyJrIjoielBIZ1BYdWJVRWVQQ2dKYkM4S0ZQcmtDd3NSa2hCZFQiLCJuIjoiYXBpX2tleSIsImlkIjoxfQ==@localhost:3000/api/org  -H "Authorization: Bearer eyJrIjoidnBBaXhUdVQyS0VaWlJ4bGR6YWF4M3h4U3RTdllQem4iLCJuIjoiYXBpX2tleSIsImlkIjoxfQ=="

My guess is that your API key in the top example with just basic auth is incorrect. You're using that same key in the authorization header of the second example. And the reason the second example works is likely that you're also using basic auth with a different key that I'd assume is actually valid.

@miguelemosreverte
Copy link
Author

Yeah, you are most probably right. It's just that I experienced this issue and the fix was to add the auth header.

If no one else experiences this issue, then it must have been just me.

Most probably, (like, 99%), Grizzly works fine.

Just to make sure, I will try to reproduce this issue in a step by step scenario, and document everything. It Grizzly works our of the box, then this Issue was non existant. Else, well, we would have proven the bug!

Just a sec, BRB

@miguelemosreverte
Copy link
Author

The bug | Step by Step

1. checkout Grizzly master, build and setup

Screenshot from 2020-07-27 14-24-20

2. Create Grafana API key

Screenshot from 2020-07-27 14-22-52

3. Use

Screenshot from 2020-07-27 14-24-36

@miguelemosreverte
Copy link
Author

The solution | Step by step

1. Perform checkout of branch that uses an AuthorizationHeader

Screenshot from 2020-07-27 14-30-16

2. Same API key, the one I just created before, no changes there

3. Use

Screenshot from 2020-07-27 14-29-18

@PatMis16
Copy link
Contributor

Is there a solution to this? I couldn't find the branch AuthorizationHeader.

@miguelemosreverte
Copy link
Author

They closed my branch PR, was here. Want to reopen?
#27

@PatMis16
Copy link
Contributor

PatMis16 commented Dec 16, 2021 via email

@miguelemosreverte
Copy link
Author

Oh, I don't have permissions to reopen the PR

@miguelemosreverte
Copy link
Author

@PatMis16 I think if you can confirm reproduction of the bug they will consider reopening the PR.
@malcolmholmes

@PatMis16
Copy link
Contributor

PatMis16 commented Dec 16, 2021

Whether it is considered as a bug or not is a matter of the viewing point. However, in some setups there is no basic authentication possible, because the Grafana instance is behind a reverse proxy.

We would like to automate some things with Grizzly and it would be very helpful if we could connect through the proxy.
From this point of view, it can be seen an inhibiting limitation of Grizzly.

@malcolmholmes Please reopen the bug. If the PR is available again we can apply the changes to the latest version.

@PatMis16
Copy link
Contributor

PatMis16 commented Dec 16, 2021 via email

@miguelemosreverte
Copy link
Author

I did, @PatMis16
Changes: https://github.com/grafana/grizzly/pull/27/files
Files changed:

go.mod (require oauth2)
go.sum (require oauth2)
pkg/grizzly/config.go (add the Grafanatoken to the type Config)
pkg/grizzly/grafana.go (use the Config + GrafanaToken to hit the HTTP endpoints using an http client that is authenticated thanks to the GrafanaToken)

@PatMis16
Copy link
Contributor

PatMis16 commented Dec 20, 2021

Thank you @miguelemosreverte

However, it looks like a lot of things have changed in the current release. I am concerned to break things.

Regards,
Patrick

@PatMis16
Copy link
Contributor

PatMis16 commented Jan 3, 2022

It shouldn't make a difference. In the docs right below where your screen shot cuts off, it states:

The API Token can also be passed as a Basic authorization password with the special username api_key...

Furthermore, it looks like your API key may be copied incorrectly in your examples.

curl http://api_key:eyJrIjoielBIZ1BYdWJVRWVQQ2dKYkM4S0ZQcmtDd3NSa2hCZFQiLCJuIjoiYXBpX2tleSIsImlkIjoxfQ==@localhost:3000/api/org

curl http://api_key:eyJrIjoiT0tTcG1pUlY2RnVKZTFVaDFeyJrIjoielBIZ1BYdWJVRWVQQ2dKYkM4S0ZQcmtDd3NSa2hCZFQiLCJuIjoiYXBpX2tleSIsImlkIjoxfQ==@localhost:3000/api/org  -H "Authorization: Bearer eyJrIjoidnBBaXhUdVQyS0VaWlJ4bGR6YWF4M3h4U3RTdllQem4iLCJuIjoiYXBpX2tleSIsImlkIjoxfQ=="

My guess is that your API key in the top example with just basic auth is incorrect. You're using that same key in the authorization header of the second example. And the reason the second example works is likely that you're also using basic auth with a different key that I'd assume is actually valid.

There is another angle which has an impact to this issue. There are enviornments, where basic authentication is not pass through e.g. if the Grafana sits behind a proxy, which normaly handles the authentication via an OpenID provider or something similar. In such a scenario it is well possible, that the basic auth requests are not forwarded to the grafana instance by the proxy. However, if a request contains an authentication header with the baerer token it is passed through. Therefore I think it is neccessary to add the authentication header method to grizzly.

@tamirshaul
Copy link

I am experiencing this issue as well.
We use Amazon Managed Grafana which does not allow Basic authentication.

further details here: #196

@PatMis16
Copy link
Contributor

PatMis16 commented Jan 4, 2022

I am experiencing this issue as well. We use Amazon Managed Grafana which does not allow Basic authentication.

further details here: #196

Hi @tamirshaul
I have implemented some changes and created a pull request (#197)
Maybe the changes work for you.
Regards,
Patrick

@HabibMAALEM
Copy link

Hi,

Actuallty, Grizzly use only Bearer Authentication (Hardcoded)

Why not make this dynamic depending on user credentials :

  • If user provide Username/Password => use Basic Authentication
  • If user provide Token (Api Key) => use Bearer Authentication

@malcolmholmes
Copy link
Collaborator

@HabibMAALEM what benefit would this give?

@der-eismann
Copy link

der-eismann commented Mar 9, 2023

Actually according to the docs this should work already, but it seems that is not the case:

GRAFANA_USER: Basic auth username if applicable.
GRAFANA_TOKEN: Basic auth password or API token.

So it kind of feels like #197 broke the basic auth? With the 0.2.0-beta3 I can use the basic auth credentials as expected.

@jannisy
Copy link

jannisy commented Jun 5, 2023

Same here, basic auth works with 0.2.0-beta3 but not 0.2.0, nor 0.2.1.

julienduchesne added a commit that referenced this issue Feb 1, 2024
Issue: #26

To verify issues like above, we need to be able to test with various auth methods
This adds a `basic_auth` context (and instance) and adds the functionality to run the same test on all contexts

Also, I changed from the `RunTests` function to individual t.Run. This is helpful because vscode can now see the individual tests and we can run them individually
@julienduchesne julienduchesne self-assigned this Feb 1, 2024
julienduchesne added a commit that referenced this issue Feb 1, 2024
Issue: #26

To verify issues like above, we need to be able to test with various auth methods
This adds a `basic_auth` context (and instance) and adds the functionality to run the same test on all contexts

Also, I changed from the `RunTests` function to individual t.Run. This is helpful because vscode can now see the individual tests and we can run them individually
julienduchesne added a commit that referenced this issue Feb 1, 2024
Issue: #26

To verify issues like above, we need to be able to test with various auth methods
This adds a `basic_auth` context (and instance) and adds the functionality to run the same test on all contexts

Also, I changed from the `RunTests` function to individual t.Run. This is helpful because vscode can now see the individual tests and we can run them individually
julienduchesne added a commit that referenced this issue Feb 2, 2024
)

Issue: #26

To verify issues like above, we need to be able to test with various auth methods
This adds a `basic_auth` context (and instance) and adds the functionality to run the same test on all contexts

Also, I changed from the `RunTests` function to individual t.Run. This is helpful because vscode can now see the individual tests and we can run them individually
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
9 participants