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

[Bug] Crash when adding or updating OAuth2 datasources in latest grafana #668

Closed
paige-muon opened this issue Sep 6, 2023 · 27 comments
Closed
Labels
type/bug Something isn't working

Comments

@paige-muon
Copy link

paige-muon commented Sep 6, 2023

Describe the bug

"An unexpected error happened" when adding OAuth2 client secret to a datasource, or when editing a datasource with OAuth2 enabled.
For example, I set up an azure AD app by following instructions on #404 and while I am able to get data from this datasource, I am unable to edit the datasource or add new OAuth2 datasources. I am able to add other types of datasource.

TypeError: Cannot assign to read only property 'oauth2_type' of object '#<Object>'

    at fO (https://muonspacegroundprod.grafana.net/public/plugins/yesoreyeram-infinity-datasource/module.js?_cache=2.0.0:3:1780081)

Steps to reproduce

Add new datasource
Use OAuth2 authentication
Fill out the fields
When I type in the field for "client secret" I get redirected to "An unexpected error happened"
When editing an existing datasource using OAuth2, most interactions with the datasource authentication lead to the same issue.

Sample Data

No data other than the error message and the screen recording below

Screenshots

Screen.Recording.2023-09-06.at.10.56.35.AM.mov

Version Details:

  • Grafana version : 10.2.0-60139
  • Plugin version : 2.0.0

Additional context

I'm not sure if this is an issue with grafana or with the datasource itself or some combination of both

@paige-muon paige-muon added the type/bug Something isn't working label Sep 6, 2023
@aps-net
Copy link

aps-net commented Sep 7, 2023

We are experiencing the same issue on v 2.0.0 and v 1.4.1

@madima92
Copy link

madima92 commented Sep 7, 2023

Hi Team, we are also experiencing the same issue, can we get someone to look into this issue?

@paige-muon
Copy link
Author

@aps-net and @madima92 can you specify the grafana version you're each using? I am opening a ticket with grafana support in case there is a change on that side impacting oauth2 in plugins, and it would help narrow down the problem.

@aps-net
Copy link

aps-net commented Sep 12, 2023

@paige-muon v2.0.0 and v1.4.1

@paige-muon
Copy link
Author

paige-muon commented Sep 12, 2023

@paige-muon v2.0.0 and v1.4.1

@aps-net these are plugin versions for the datasource, the grafana version should be >=8.4.7
You can find it by clicking the (?) button from any page in your grafana instance:
Screenshot 2023-09-12 at 11 14 10 AM

@aps-net
Copy link

aps-net commented Sep 13, 2023

Ohh yea it is v10.2.0-60477

@paige-muon
Copy link
Author

@yesoreyeram The oauth2 authentication is totally broken with grafana 10.2. I have tried updating via the UI and the API with no luck. With the API update of the datasource, it appears to not be able to write the token at all since the datasource reports unauthorized.

@alexandredavi
Copy link

+1

1 similar comment
@raphael5178
Copy link

+1

@hbig48
Copy link

hbig48 commented Oct 16, 2023

I am also facing this issue: +1

@VKlueber
Copy link

+1

2 similar comments
@anophis
Copy link

anophis commented Oct 18, 2023

+1

@hugoglezmx
Copy link

+1

@yesoreyeram
Copy link
Collaborator

Just back to work after a break. I will take a look later this week.

Meantime, workaround is to use older version of grafana or use grafana http api to configure the datasource or use grafana datasource provisioning or things such as terraform to configure the datasource. ( I can confirm that this is just a UI bug but the underlying functionality not affected )

@Av8tor101
Copy link

Av8tor101 commented Nov 1, 2023

Any update on this? I'm not sure what the work around is. Grafana v10.3.0-62882 (dd773e74f1)

@em1064
Copy link

em1064 commented Nov 2, 2023

I have tried to implement the workaround via the HTTP API, with no luck so far. Could use some guidance as I am not too familiar with the Grafana API, particularly with using the Cloud instance.

Using a Grafana cloud instance here. I have attempted to use the HTTP API to configure a new Data source but cannot get it to work.

  • Created a Cloud Access Policy and an API Token
  • Used Bearer Token type Authentication

First used the GET Data sources to see my other data sources.
GET https://grafana.com/api/instances/`GrafanaCloudInstanceName`/datasources

This works and I see the standard Grafana Cloud Data sources (Alertmanager, Loki, Prometheus, etc.) but no Infinity data sources.

Next tried to create a Data source.
POST https://grafana.com/api/instances/`GrafanaCloudInstanceName`/datasources
Body:

{
  "access": "proxy",
  "basicAuth": false,
  "basicAuthUser": "",
  "isDefault": false,
  "jsonData": {
      "allowedHosts": [
         "https://portal.xyz.com/"
      ],
      "auth_method": "oauth2",
      "customHealthCheckEnabled": true,
      "customHealthCheckUrl": "https://portal.xyz.com/api/v23.7.0/me",
      "global_queries": [],
      "oauth2":{
        "client_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
        "oauth2_type": "client_credentials",
        "token_url": "https://portal.xyz.com/api/v23.7.0/auth/token"
        },
      "oauthPassThru": false

  },
  "name": "Test",
  "secureJsonData": {
    "oauth2ClientSecret": "<string>"
  },
  "type": "yesoreyeram-infinity-datasource",
  "url": ""
}

This Worked, on the API level, but I do not see this Data source in Grafana.
Took what I could from the Provisioning Script output, but not everything there was compatible, like uid, and access.

Does someone have an example of the HTTP api for creating a working Infinity Data source on a Cloud instance? Or perhaps someone can point out an obvious issue I am missing.

@Av8tor101
Copy link

Wow, Workarounds

  1. use older version of grafana or
  2. use grafana http api to configure the datasource or
  3. use grafana datasource provisioning or
  4. things such as terraform to configure the datasource.

I use this plugin to remove all of the above complexities, I'm a novice at this and built a dashboard for demonstrations. I have a cloud instance of Grafana, so the simple workaround (1) is may not be available to me? is there a way to tell the cloud to use an older instance?

@em1064
Copy link

em1064 commented Nov 2, 2023

So it did work, just needed to wait about 20-30 minutes until the Cloud Instance refreshed, or manually trigger the instance to reset.

Made some additional tweaks to the body for it to work with my requirements. In my case I use Oauth2 Client Credentials.

POST https://grafana.com/api/instances/{{CloudInstance}}/datasources
Body

{
    "name": "{{DataSourceName}}",
    "type": "yesoreyeram-infinity-datasource",
    "isDefault": false,
    "jsonData": {
        "allowedHosts": [
            "{{allowedHost}}"
        ],
        "auth_method": "oauth2",
        "customHealthCheckEnabled": true,
        "customHealthCheckUrl": "{{customHealthCheckUrl}}",
        "global_queries": [],
        "oauth2": {
            "client_id": "{{client_id}}",
            "oauth2_type": "client_credentials",
            "token_url": "{{token_url}}"
        },
        "oauthPassThru": false,
        "refData": [{
            "data": "{{allowedHost}}",
            "name": "URL"
        }]
    },
    "secureJsonData": {
        "oauth2ClientSecret": "{{oauth2ClientSecret}}"
    },
    "access": "proxy",
    "basicAuth": false,
    "basicAuthUser": "",
    "url": ""
}

Can trigger a reset of the instance with
POST https://grafana.com/api/instances/{{CloudInstance}}/restart

I will share a Postman collection that should help anyone that has a Cloud Instance.

Please note, it is not possible to delete this via Grafana, can only delete via API
DELETE https://grafana.com/api/instances/{{CloudInstance}}/datasources/:id

@em1064
Copy link

em1064 commented Nov 3, 2023

@Av8tor101 My colleague confirmed that downgrading to 10.0.x works. He had Grafana Support downgrade his Cloud instance.

Alternative, you can try via API.
Here is a public postman collection for my example.
https://www.postman.com/eduardo-melendez/workspace/grafana-infinity-datasource/collection/23517476-0fe17351-56f9-44a1-a2cd-b94866d806f3?action=share&creator=23517476

Just fork it, change the variables, and make modifications to the POST Create a data source body endpoint for your needs.
Just need to convert the Provisioning config into JSON.

@yesoreyeram
Copy link
Collaborator

Actually, I published v2.1.0 which included some fix along with other features. But unfortunately the fix didn't help. Also noticing this happening only on grafana cloud.

I am planning to work on the follow-up fix later this weekend. Sorry for the trouble. Meantime, feel free to use the workarounds suggested.

@schmallaria
Copy link

@yesoreyeram the latest version 2.2.0 (which fixes this bug) is not available via https://grafana.com/grafana/plugins/yesoreyeram-infinity-datasource. Is there a reason why?

@yesoreyeram
Copy link
Collaborator

It is already in grafana plugin review process queue. Usually it will take a day or two.

@schmallaria
Copy link

@yesoreyeram...didn't know that. Then it should be available in the next few days. Thanks for the quick reply

@yesoreyeram
Copy link
Collaborator

New version 2.2.1 is now available in grafana cloud for download with this fix. Let me know if anyone still having issue

@paige-muon
Copy link
Author

Thank you @yesoreyeram!!

@JesperBaertel
Copy link

JesperBaertel commented Oct 1, 2024

@yesoreyeram still facing the issue in grafana Cloud with version 2.1 installed which are the newest version avalible for download in grafana cloud.

@yesoreyeram
Copy link
Collaborator

@yesoreyeram still facing the issue in grafana Cloud with version 2.1 installed which are the newest version avalible for download in grafana cloud.

Can you provide more details? what error you are seeing and how to reproduce? @JesperBaertel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug Something isn't working
Projects
None yet
Development

No branches or pull requests