`google.api.Service` config seems to require an audience to avoid JWT validation errors
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 38/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- python
- 领域
- api, authentication
调研方向
先从 endpoints/bookstore-grpc/api_config_auth.yaml 和 endpoints/bookstore-grpc-transcoding/api_config_auth.yaml 开始,然后查看 jwt_token_gen.py 和 bookstore_client.py,了解身份验证流程。复现 issue 中描述的 JWT 请求,并验证两项服务配置都能接受预期的服务账号身份验证,且不会出现 audience 验证错误。
由索引模型根据 Issue 内容生成。
描述
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 👍
- 主要语言
- Jupyter Notebook
- 星标
- 8.1k
- 派生
- 6.7k
- 平均合并
- 4 天 4 小时
- 30 天内合并 PR
- 8
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
GoogleCloudPlatform/python-docs-samples 的其他 Issue
-
samples
难度 2/5 1-3 小时 新手友好度 88/100
-
samples
难度 1/5 1 小时以内 新手友好度 92/100
-
samples
难度 2/5 1-3 小时 新手友好度 88/100
-
samples
GoogleCloudPlatform/python-docs-samples#14117 · 已指派 1 人 ·
-
samples
GoogleCloudPlatform/python-docs-samples#14091 · 已指派 1 人 ·
查看 GoogleCloudPlatform/python-docs-samples 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
-
难度 2/5 1-3 小时 新手友好度 78/100
doctrine/collections#554 · 1 个 reaction ·
-
难度 2/5 1-3 小时 新手友好度 84/100
receptron/mulmoterminal#2264 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
openfoodfacts/robotoff#1957 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
django-tastypie/django-tastypie#1702 ·