google-api-ruby-client icon indicating copy to clipboard operation
google-api-ruby-client copied to clipboard

[Bug] Allow UserRefreshCredentials in IAMCredentialsService sign_service_account_jwt

Open ianjhuang opened this issue 8 years ago • 1 comments

Is your feature request related to a problem? Please describe.

The gcloud cli allows signing a JWT token on behalf of a service account using user credentials. The Ruby library does not. The following code results in the error below:

service = Google::Apis::IamcredentialsV1::IAMCredentialsService.new
service.authorization = Google::Auth.get_application_default(['https://www.googleapis.com/auth/cloud-platform']) # Default credentials (UserRefreshCredentials) from https://github.com/googleapis/google-auth-library-ruby

req = Google::Apis::IamcredentialsV1::SignJwtRequest.new
req.payload = {
  :aud => '<my audience>',
  :sub => '<my_subject>',
  :exp => (Time.new + 600).to_i
}.to_json

resp = service.sign_service_account_jwt('projects/-/<my service account>', req)

Results in: /.../.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/google-api-client-0.25.0/lib/google/apis/core/http_command.rb:228:in 'check_status': accessNotConfigured: Your application has authenticated using end user credentials from the Google Cloud SDK or Google Cloud Shell which are not supported by the iamcredentials.googleapis.com. We recommend that most server applications use service accounts instead. For more information about service accounts and how to use them in your application, see https://cloud.google.com/docs/authentication/. (Google::Apis::ClientError)

Describe the solution you'd like The library should be able to sign a JWT token successfully. The expected behavior should match the gcloud cli (ran locally):

$ gcloud beta iam service-accounts sign-jwt login_request.json signed_jwt.json --iam-account=<my service account>
signed jwt [login_request.json] as [signed_jwt.json] for [<my service account>] using key [<scrubbed key>]

Describe alternatives you've considered The alternative is to download a json key of a GCP service account with access token signing permissions. However, then the code needs be aware of that json key, and it is a hassle to pass it around to other devs, and makes setup more difficult.

System Info

  • Ruby 2.5.1
  • googleauth (0.6.6)
  • google-api-client (0.25.0)

ianjhuang avatar Nov 08 '18 17:11 ianjhuang

Thank you for reporting this issue. We have reviewed it as part of our ongoing backlog triage. Because we are currently prioritizing higher-impact features and critical bug fixes, we are closing this item for now to keep our focus streamlined.

jjmew avatar Sep 03 '26 22:09 jjmew