`google.api.Service` config seems to require an audience to avoid JWT validation errors
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 38/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- python
- Domain
- api, authentication
Research direction
Start with endpoints/bookstore-grpc/api_config_auth.yaml and endpoints/bookstore-grpc-transcoding/api_config_auth.yaml, then review jwt_token_gen.py and bookstore_client.py for the authentication flow. Reproduce the JWT request described in the issue and verify that both service configurations accept the intended service-account authentication without the audience validation error.
Written by the indexing model from the issue text.
Description
In which file did you encounter the issue?
Did you change the file? If so, how?
Yes, in the following section of the files:
#
# Request authentication.
#
authentication:
providers:
- id: google_service_account
# Replace SERVICE-ACCOUNT-ID with your service account's email address.
issuer: SERVICE-ACCOUNT-ID
jwks_uri: https://www.googleapis.com/robot/v1/metadata/x509/SERVICE-ACCOUNT-ID
rules:
# This auth rule will apply to all methods.
- selector: "*"
requirements:
- provider_id: google_service_account
I added an audience field to the config:
#
# Request authentication.
#
authentication:
providers:
- id: google_service_account
# Replace SERVICE-ACCOUNT-ID with your service account's email address.
issuer: SERVICE-ACCOUNT-ID
jwks_uri: https://www.googleapis.com/robot/v1/metadata/x509/SERVICE-ACCOUNT-ID
audiences: DEFAULT_HOSTNAME
rules:
# This auth rule will apply to all methods.
- selector: "*"
requirements:
- provider_id: google_service_account
Describe the issue
When using current api_config_auth.yaml for service-account JWT authentication I continued to get "{"message":"Audiences in Jwt are not allowed","code":403}". This error was present regardless of whether the JWT I passed had an audience. I used jwt_token_gen.py to generate the JWTs to pass when reaching out to the api python3 bookstore_client.py --auth_token JWT_TOKEN --host= DEFAULT_HOSTNAME --port 443 --use_tls true.
To generate a JWT without an audience field I commented out the 'aud' portion of the payload in jwt_token_gen.py . I tried without an audience and with the service name as an audience and each test provided the same error message. I inspected each JWT in jwt.io to ensure that each JWT claim was how I expected.
Overall, I suspect the google.api.Service spec has a different behavior for expected audiences than the OpenAPI spec (which doesn't required audience). Adding audience to the config resolved the issue and allowed me to hit the API with service-account JWT authentication enabled. Willing to create a PR to incorporate audiences: DEFAULT_HOSTNAME if approved 👍
- Dominant language
- Jupyter Notebook
- Stars
- 8.1k
- Forks
- 6.7k
- Avg merge
- 4d 4h
- Merged PRs (30d)
- 8
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from GoogleCloudPlatform/python-docs-samples
-
samples
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
GoogleCloudPlatform/python-docs-samples#14609 ·
Maintainers usually reply within 1 day
-
samples
Difficulty 1/5 Under an hour Newbie friendliness 92/100
GoogleCloudPlatform/python-docs-samples#14610 ·
Maintainers usually reply within 1 day
-
samples
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
GoogleCloudPlatform/python-docs-samples#14611 ·
Maintainers usually reply within 1 day
-
chore(generative_ai) Update model references for generative_ai samplesMay be free again @XrossFox claimed this 153 days ago, and no pull request is open. Opensamples
GoogleCloudPlatform/python-docs-samples#14117 · 1 assignee ·
Maintainers usually reply within 1 day
-
Fix Pipeline dependency issues for geospatial-classification/serving_appMay be free again @XrossFox claimed this 164 days ago, and no pull request is open. Opensamples
GoogleCloudPlatform/python-docs-samples#14091 · 1 assignee ·
Maintainers usually reply within 1 day
All issues in GoogleCloudPlatform/python-docs-samples
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
PedestrianDynamics/pyFDS-Evac#199 ·
Maintainers usually reply within 1 day
-
agent-reported area/server bug good first issue hacktoberfest help wanted P2
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
kotope/aio_energy_management#196 · 2 comments ·
-
v1 v2
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
modelcontextprotocol/python-sdk#3589 ·
Maintainers usually reply within 1 day