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

google.auth.exceptions.RefreshError: ('invalid_scope: Invalid OAuth scope or ID token audience provided.', {'error': 'invalid_scope', 'error_description': 'Invalid OAuth scope or ID token audience provided.'}) #42

Open
birb57 opened this issue Apr 14, 2024 · 9 comments
Assignees

Comments

@birb57
Copy link

birb57 commented Apr 14, 2024

Hi

Can not use adc authentication via service account for gce-rescue

Can you please advise ?

[gce-rescue]#
[root@gce-rescue]# export GOOGLE_APPLICATION_CREDENTIALS="/root/gce-rescue/auth-simu.json"
[root@gce-rescue]# /usr/bin/gce-rescue -p dbg-cs-sz-32064e0b -z europe-west3-a -n gcsb84rhel098
Traceback (most recent call last):
File "/usr/bin/gce-rescue", line 33, in
sys.exit(load_entry_point('gce-rescue==0.4b0', 'console_scripts', 'gce-rescue')())
File "/usr/lib/python3.9/site-packages/gce_rescue-0.4b0-py3.9.egg/gce_rescue/bin/rescue.py", line 44, in main
vm = Instance(test_mode=False, **parse_kwargs)
File "", line 12, in init
File "/usr/lib/python3.9/site-packages/gce_rescue-0.4b0-py3.9.egg/gce_rescue/gce.py", line 112, in post_init
check = Validations(
File "", line 7, in init
File "/usr/lib/python3.9/site-packages/gce_rescue-0.4b0-py3.9.egg/gce_rescue/tasks/pre_validations.py", line 48, in post_init
authorize_check(project = self.project)
File "/usr/lib/python3.9/site-packages/gce_rescue-0.4b0-py3.9.egg/gce_rescue/tasks/validations/authorization.py", line 43, in authorize_check
result = service.projects().testIamPermissions(
File "/usr/lib/python3.9/site-packages/google_api_python_client-2.125.0-py3.9.egg/googleapiclient/_helpers.py", line 130, in positional_wrapper
return wrapped(*args, **kwargs)
File "/usr/lib/python3.9/site-packages/google_api_python_client-2.125.0-py3.9.egg/googleapiclient/http.py", line 923, in execute
resp, content = _retry_request(
File "/usr/lib/python3.9/site-packages/google_api_python_client-2.125.0-py3.9.egg/googleapiclient/http.py", line 191, in _retry_request
resp, content = http.request(uri, method, *args, **kwargs)
File "/usr/lib/python3.9/site-packages/google_auth_httplib2-0.2.0-py3.9.egg/google_auth_httplib2.py", line 209, in request
self.credentials.before_request(self._request, method, uri, request_headers)
File "/usr/local/lib/python3.9/site-packages/google/auth/credentials.py", line 228, in before_request
self._blocking_refresh(request)
File "/usr/local/lib/python3.9/site-packages/google/auth/credentials.py", line 191, in _blocking_refresh
self.refresh(request)
File "/usr/local/lib/python3.9/site-packages/google/oauth2/service_account.py", line 441, in refresh
access_token, expiry, _ = _client.jwt_grant(
File "/usr/local/lib/python3.9/site-packages/google/oauth2/_client.py", line 308, in jwt_grant
response_data = _token_endpoint_request(
File "/usr/local/lib/python3.9/site-packages/google/oauth2/_client.py", line 279, in _token_endpoint_request
_handle_error_response(response_data, retryable_error)
File "/usr/local/lib/python3.9/site-packages/google/oauth2/_client.py", line 72, in _handle_error_response
raise exceptions.RefreshError(
google.auth.exceptions.RefreshError: ('invalid_scope: Invalid OAuth scope or ID token audience provided.', {'error': 'invalid_scope', 'error_description': 'Invalid OAuth scope or ID token audience provided.'})
[root@ gce-rescue]#

Thanks for your support

@halleysouza
Copy link
Collaborator

halleysouza commented Apr 17, 2024

Hey there... I understand you are trying to set up local credentials for a service account.
I'd recommend you to use ADC with your SA credentials.

gcloud auth application-default login --impersonate-service-account <SA-login>

Have a look for more: https://cloud.google.com/docs/authentication/provide-credentials-adc#sa-impersonation

Also, make sure your SA have all the permissions necessary to rescue a VM.

Let me know if that works for you

@halleysouza halleysouza self-assigned this Apr 17, 2024
@bskou57
Copy link

bskou57 commented Apr 17, 2024

Hi

I can not as I am login via cyberark platform

I can only use service account file

Best regards

@halleysouza
Copy link
Collaborator

@runxinw I remember you worked on:

def api_service

Maybe we can parse the $GOOGLE_APPLICATION_CREDENTIALS (credentials json file) there ?

@runxinw
Copy link
Collaborator

runxinw commented May 7, 2024

gce-rescue uses the google-auth library to perform authentication and authorization, the issue is not specific to its code.

I assume you are using the service account key for this case, otherwise, please review this doc to create a proper SA key file.

Based on the traceback -- 'invalid_scope: Invalid OAuth scope or ID token audience provided.', the issue indicates the SA does not have right scope. Have you tried following this doc to set the right scope for your GCE instance for the SA ?

If it is still not working, please give us a bit more details how you generate the credential json and how you set the scope.

@Rishi247
Copy link

Rishi247 commented Jun 3, 2024

Was this resolved since I am getting the same error. I tried running gcloud auth login command before running the gce-rescue command. Although it logged in successfully, but I am still getting the same error as above when running gce-rescue.

@halleysouza
Copy link
Collaborator

@Rishi247 are you also using exported SA key ? Are you able to able to run other gcloud commands with this SA key (ie: stop/start VM, etc) ? If possible, please provide here the logs

Also check the last comment setting up the correct scope for your SA.

@Rishi247
Copy link

Rishi247 commented Jun 4, 2024 via email

@halleysouza
Copy link
Collaborator

In this case, I assume you configured your account:
$ gcloud init

and later updated the applications login:
$ gcloud auth application-default login

Can you please run the GCE Rescue with the --debug options and share the logs ? ** please make sure to redact any personal information from the logs before submitting **

@Rishi247
Copy link

Rishi247 commented Jun 5, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants