首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法从顶点AI自定义作业中使用“`gcloud auth print-identity-token`”

无法从顶点AI自定义作业中使用“`gcloud auth print-identity-token`”
EN

Stack Overflow用户
提问于 2022-07-04 08:02:27
回答 2查看 492关注 0票数 0

背景

  • 我想使用一个带有顶点AI自定义作业的服务帐户,并创建一个标识符。
  • 我试图通知一个云运行API,一旦一个顶点-AI定制工作已经完成。
  • 我创建了一个具有roles/run.invoker角色的服务帐户,并确认服务帐户可以访问云运行API。
    • 我使用了来自服务帐户的凭据,并创建了一个标识令牌,用户设置为云运行API URL

问题

  • 当使用gcloud ai custom-jobs create或通过高朗客户端库创建顶点AI自定义作业时,无法为自定义服务帐户获取标识令牌。
    • gcloud auth print-identity-token导致一个错误:
      • (gcloud.auth.print-identity-token) No identity token can be obtained from the current credentials.

代码语言:javascript
运行
复制
- Using the [metadata server URL](https://cloud.google.com/run/docs/authenticating/service-to-service#use_the_metadata_server) directly gives a `Not Found` response. 
    - Command: curl \   -s \   --get \   --data-urlencode "audience=$CLOUD\_RUN\_API\_URL" \   --data-urlencode "format=full" \   -H "Metadata-Flavor: Google" \   http://metadata/computeMetadata/v1/instance/service-accounts/default/identity
代码语言:javascript
运行
复制
    - Response: `Not Found`
  • 在调用自定义作业的设置/方式允许我访问服务帐户的标识令牌方面,我需要一些指导。

详细信息

  • 为了测试创建标识令牌,使用下面的docker文件指定自定义容器:
代码语言:javascript
运行
复制
FROM alpine:3.6

RUN apk add --update python curl which bash
RUN curl -sSL https://sdk.cloud.google.com | bash -s -- --disable-prompts
ENV PATH $PATH:/root/google-cloud-sdk/bin

CMD ["gcloud", "auth", "print-identity-token", "--verbosity", "debug"]
  • 以下内容产生一个工作身份令牌:
代码语言:javascript
运行
复制
- ✅ Running this image locally
- ✅ Running this image using the "Create" button on the vertex AI GUI and setting the service account to my custom one, created for this use case.
- ✅ Running this image using `gcloud` with NO service account set (using vertex-ai default service account for the project)
  • 以下情况导致一个错误(促使我提出这个问题的问题):
代码语言:javascript
运行
复制
- ❌ Running this image using `gcloud` with the following settings, I get an **error**:
代码语言:javascript
运行
复制
    - Command (image name/service account redacted): gcloud ai custom-jobs create \   --region=asia-northeast1 \   --display-name=cli\_identity\_test \   --worker-pool-spec=machine-type=n2-standard-4,replica-count=1,container-image-uri=<IMAGE NAME> \   --service-account=<SERVICE ACCOUNT EMAIL>
代码语言:javascript
运行
复制
    - Error: DEBUG: (gcloud.auth.print-identity-token) No identity token can be obtained from the current credentials.                                                                 Traceback (most recent call last):                                                                                                                                          File "/root/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py", line 987, in Execute                                                                                      resources = calliope\_command.Run(cli=self, args=args)                                                                                                                   File "/root/google-cloud-sdk/lib/googlecloudsdk/calliope/backend.py", line 809, in Run                                                                                      resources = command\_instance.Run(args)                                                                                                                                  File "/root/google-cloud-sdk/lib/googlecloudsdk/calliope/exceptions.py", line 129, in TryFunc                                                                               return func(\*args, \*\*kwargs)                                                                                                                                            File "/root/google-cloud-sdk/lib/surface/auth/print\_identity\_token.py", line 130, in Run                                                                                    credential = \_Run(args)                                                                                                                                                 File "/root/google-cloud-sdk/lib/surface/auth/print\_identity\_token.py", line 78, in \_Run                                                                                    'No identity token can be obtained from the current credentials.')                                                                                                    InvalidIdentityTokenError: No identity token can be obtained from the current credentials.                                                                                ERROR: (gcloud.auth.print-identity-token) No identity token can be obtained from the current credentials.
代码语言:javascript
运行
复制
- ❌ Running the image with a custom service account, and using the vertex ai golang API client library to start the job

关于角色的说明

  • 我也尝试过扩展与我的服务帐户相关的角色,但是这些都没有修复错误:
    • 匹配默认的顶点-ai服务帐户(roles/aiplatform.customCodeServiceAgent)
    • 服务帐户令牌创建器(roles/iam.serviceAccountTokenCreator)
    • 服务帐户用户(roles/iam.serviceAccountUser)
EN

回答 2

Stack Overflow用户

发布于 2022-07-04 16:41:30

我写了

我相信您可以通过使用访问令牌来生成和标识令牌来重用该API。我对云构建一次也有类似的问题(我认为现在已经解决了)。

票数 1
EN

Stack Overflow用户

发布于 2022-10-08 21:35:33

您可以使用

代码语言:javascript
运行
复制
import google.auth.transport.requests
import google.oauth2.id_token
auth_req = google.auth.transport.requests.Request()
token = google.oauth2.id_token.fetch_id_token(auth_req, <AUDIENCE>)

示例:云功能的受众将类似于https://<REGION>-<PROJECT_ID>.cloudfunctions.net/<FUNCTION_NAME>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72853485

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档