Stackdriver: Datasource provisioning in 5.3.0-beta3

Hello,
I am using the Grafana Docker container 5.3.0-beta3 and want to use the new Stackdriver datasource. When I upload the config file manually it works nicely. But now I want to provision it automatically.
My datasources yaml looks like this:

apiVersion: 1
datasources:  
- editable: true
  jsonData:
    clientEmail: grafana-monitoring@mygcpproject.iam.gserviceaccount.com
    defaultProject: mygcpproject
    tokenUri: https://oauth2.googleapis.com/token
  name: stackdriver
  orgId: 1
  readOnly: false
  secureJsonData:
    privateKey: '-----BEGIN PRIVATE KEY-----asjkdasdk679123bla-----END
      PRIVATE KEY-----'
  type: stackdriver
  version: 1

Now i can see that the datasource is created but when I use it, it fails with these logs:

  t=2018-10-09T05:38:50+0000 lvl=eror msg="Failed to get access token" logger=data-proxy-log error="private key should be a PEM or plain PKSC1 or PKCS8; parse error: asn1: structure error: tags don't match (16 vs {class:0 tag:13 length:45 isCompound:true}) {optional:false explicit:false application:false private:false defaultValue:<nil> tag:<nil> stringType:0 timeType:0 set:false omitEmpty:false} pkcs1PrivateKey @2"

I also tried adding the whole gcp generated json but that didn’t work either. How is the config supposed to look like? The docu just says
privateKey: “”

Thanks for your help

Hi,

You need to make sure to escape the linebreaks that are present in the google jwt json file, and then paste it as a multiline yaml string in the provisioning config file.

E.g

apiVersion: 1
datasources:  
- editable: true
  jsonData:
    clientEmail: grafana-monitoring@mygcpproject.iam.gserviceaccount.com
    defaultProject: mygcpproject
    tokenUri: https://oauth2.googleapis.com/token
  name: stackdriver
  orgId: 1
  readOnly: false
  secureJsonData:
    privateKey: |
      -----BEGIN PRIVATE KEY-----
      POSEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCb1u1Srw8ICYHS
      ...
      yA+23427282348234=
      -----END PRIVATE KEY-----
  type: stackdriver
  version: 1

Sorry, this should have been in the docs. I’ll fix that asap.
/Erik

1 Like

Works like a charm! Thank you very much

Hi together,

I just wanted to configure a Stackdriver datasource.
Unfortunately I get the following error message.

lvl=eror msg=“Failed to get access token” logger=data-proxy-log error=“private key should be a PEM or plain PKCS1 or PKCS8; parse error: asn1: structure error: tags don’t match (16 vs {class:0 tag:13 length:45 isCompound:true}) {optional:false explicit:false application:false private:false defaultValue: tag: stringType:0 timeType:0 set:false omitEmpty:false} pkcs1PrivateKey @2

Attached you will find the .yaml configuration. Somebody an idea what’s wrong with that?

Thanks in advance!