Stackdriver logging API authentication error

620 views
Skip to first unread message

Tobias Hoke

unread,
Jul 5, 2018, 9:47:51 AM7/5/18
to Google Stackdriver Discussion Forum
Hi, 

does anyone has an idea why my API request to list log entries always tells me that i'm using a wrong API key? 

Here is a code snipped with my request: 

    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true
    req = Net::HTTP::Post.new(uri.path, 'Content-Type' => 'application/json')
    req.body = {
  "pageSize": 5,
  "filter": "resource.type=\"k8s_cluster\" AND resource.labels.location=\"europe-west1-b\" AND resource.labels.cluster_name=\"container-cluster\"",
  "resourceNames": [
  "projects/myproject"
  ]
}.to_json

    res = http.request(req)



I always get this response: 

response {
  "error": {
    "code": 403,
    "message": "The request is missing a valid API key.",
    "status": "PERMISSION_DENIED"
  }
}


I created an API Key with sufficient permissions to Stackdriver I also tried using OAuth Token but got the same result (oauth_token={myToken}


Am I missing anything? 

Igor Peshansky

unread,
Jul 5, 2018, 10:10:08 AM7/5/18
to Tobias Hoke, Google Stackdriver Discussion Forum
Not sure about your API key, but an OAuth2 token needs to be passed in via the "Authorization" header (see https://tools.ietf.org/html/rfc6750#section-2.1). Don't know if our APIs support the "access_token" URL parameter (https://tools.ietf.org/html/rfc6750#section-2.3) as well.
        Igor
-- sent from a mobile device, please excuse tyops and omissns

--
© 2016 Google Inc. 1600 Amphitheatre Parkway, Mountain View, CA 94043
 
Email preferences: You received this email because you signed up for the Google Stackdriver Discussion Google Group (google-stackdr...@googlegroups.com) to participate in discussions with other members of the GoogleStackdriver community.
---
You received this message because you are subscribed to the Google Groups "Google Stackdriver Discussion Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-stackdriver-d...@googlegroups.com.
To post to this group, send email to google-stackdr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-stackdriver-discussion/12715af6-dbfb-4b0e-b61a-10d24ff434d2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tobias Hoke

unread,
Jul 6, 2018, 3:26:48 AM7/6/18
to Google Stackdriver Discussion Forum
Hi Igor, 

thank you very much! This solved my issue - i had to pass the authorizsation via header. 

Marc Unangst

unread,
Jul 6, 2018, 10:33:40 AM7/6/18
to Tobias Hoke, Google Stackdriver Discussion Forum
Hi Tobias,

Adding to what Igor said, the logging API requires authentication for all API methods, so just passing an API key is insufficient. Instead of hand-rolling your authentication and API access you might consider using the GCP client library. One of the features of the GCP client libraries is application default credentials, which automatically picks up credentials from the default service account on GCE, GKE, GAE, and GCF and supplies them when making API calls. This eliminates the need for you to worry about authentication from your application, as well as improving security, since you don't have to manually manage private key files for service accounts.


--
© 2016 Google Inc. 1600 Amphitheatre Parkway, Mountain View, CA 94043
 
Email preferences: You received this email because you signed up for the Google Stackdriver Discussion Google Group (google-stackdr...@googlegroups.com) to participate in discussions with other members of the GoogleStackdriver community.
---
You received this message because you are subscribed to the Google Groups "Google Stackdriver Discussion Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-stackdriver-d...@googlegroups.com.
To post to this group, send email to google-stackdr...@googlegroups.com.

Marc Unangst

unread,
Jul 7, 2018, 8:41:25 PM7/7/18
to Tobias Hoke, Google Stackdriver Discussion Forum
Hi Tobias,

One of my coworkers pointed out to me offline that it looks like you're using Perl, and that there's no Google Cloud client library for Perl. Assuming this is the case, I apologize since this isn't an option for you...however, my advice still holds for people using one of the supported languages (Go, Java, Node.js, Python, Ruby, PHP, C#). Thanks!

Igor Peshansky

unread,
Jul 7, 2018, 9:39:50 PM7/7/18
to Marc Unangst, Tobias Hoke, Google Stackdriver Discussion Forum
Looks like Ruby to me, actually... Marc is right. Tobias, any reason to not use the client libraries? A prime example is the logging agent itself: https://github.com/GoogleCloudPlatform/fluent-plugin-google-cloud/blob/master/lib/fluent/plugin/out_google_cloud.rb#L847 .

        Igor
-- sent from a mobile device, please excuse tyops and omissns

Tobias Hoke

unread,
Jul 10, 2018, 3:59:07 AM7/10/18
to Google Stackdriver Discussion Forum

Hi @all, 

it is actually ruby not perl - I'm aware of the client library but I had some issues using the list logs api v2 methods, I will now spend more time investigating that issue and will come back to you with some more info. 
I needed a quick solution last week therefore I used the workaround with the direct API call, but thanks for your input. 


Reply all
Reply to author
Forward
0 new messages