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

发布于 2025-02-12 13:28:22 字数 5148 浏览 1 评论 0 原文

背景

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

请将受众设置为云运行api url问题设置为云运行API url问题。


详细信息

  • 为了测试创建身份令牌的
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"]
  • ,使用下面的Docker文件指定自定义容器:

    以下产生工作身份令牌:

    • ✅在本地运行此图像
    • ✅使用顶点AI GUI上的“创建”按钮运行此图像,并将服务帐户设置为我的自定义帐户,为此用例创建。
    • ✅使用 gcloud 在没有服务帐户集的情况下运行此图像(使用该项目的Vertex-ai默认服务帐户)
  • 以下结果错误(促使我问这个问题的问题) :

    • ❌使用 gcloud 在以下设置中运行此图像,我得到错误

      • 命令(删除图像名称/服务帐户):
          gcloud ai custom-jobs创建\
          -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 =<服务帐户电子邮件>
         
      • 错误:
          debug :( gcloud.auth.print-isentity-token)无法从当前凭据获得身份令牌。                                                                
        Trackback(最近的最新电话):                                                                                                                                       
          文件“/root/google-cloud-sdk/lib/googlecloudsdk/calliope/cli.py”,第987行,在execute中                                                                                 
            资源= calliope_command.run(cli = self,args = args)                                                                                                                
          文件“/root/google-cloud-sdk/lib/googlecloudsdk/calliope/backend.py”,第809行                                                                                 
            资源= command_instance.run(args)                                                                                                                               
          文件“/root/google-cloud-sdk/lib/googlecloudsdk/calliope/exceptions.py”,第129行,在tryfunc                                                                          
            返回func(*args,** kwargs)                                                                                                                                         
          文件“/root/google-cloud-sdk/lib/surface/auth/print_identity_token.py”,第130行                                                                               
            凭据= _run(args)                                                                                                                                              
          文件“/root/google-cloud-sdk/lib/surface/auth/print_identity_token.py”,第78行,in _run                                                                               
            “无法从当前的凭据获得身份令牌。”)                                                                                                   
        InvalidIdentityTokenerror:从当前的凭据无法获得身份令牌。                                                                               
        错误:( gcloud.auth.print-nidentity-token)无法从当前凭据获得身份令牌。
         
    • ❌使用自定义服务帐户运行图像,并使用顶点AI Golang API客户端库来启动作业


角色的注释,

  • 我也尝试扩展与我的服务帐户相关的角色,但是这些没有解决错误:
    • 要匹配默认的顶点ai服务帐户(角色/aiplatform.customcodeserviceagent
    • 服务帐户令牌创建者(角色/iam.serviceaccounttokencreator
    • 服务帐户用户(角色/IAM.Serviceaccountuser

Background

  • I want to use a service account, with a vertex AI custom job, and create an identity token.
  • I am attempting to notify a cloud run API once a vertex-AI custom job has finished.
  • I have created a service account with a roles/run.invoker role, and have confirmed that the service account can access the cloud run API.
    • I used credentials from the service account and created an identity token with audience set to the cloud run API URL

Problem

  • When a vertex AI custom job is created using gcloud ai custom-jobs create or through the golang client library, an identity token cannot be obtained for a custom service account.
    • gcloud auth print-identity-token results in an error:
      • (gcloud.auth.print-identity-token) No identity token can be obtained from the current credentials.
    • Using the metadata server URL 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
        
      • Response: Not Found
  • I need some guidance on what settings / way of invoking the custom job will allow me to access the service account's identity token.

Details

  • For the purposes of testing creating an identity token, the custom container is specified using the docker file below:
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"]
  • The following produce a working identity token:

    • ✅ 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)
  • The following results in an error (the problem which prompted me to ask this question):

    • ❌ Running this image using gcloud with the following settings, I get an error:

      • 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>
        
      • 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.
        
    • ❌ Running the image with a custom service account, and using the vertex ai golang API client library to start the job


A note on roles

  • I have also tried extending the roles associated with my service account, but these do not fix the error:
    • to match the default vertex-ai service account (roles/aiplatform.customCodeServiceAgent)
    • Service Account Token Creator (roles/iam.serviceAccountTokenCreator)
    • Service Account User (roles/iam.serviceAccountUser)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情深如许 2025-02-19 13:28:22

我写了 >

我确定您可以使用访问令牌重复使用该API来生成和身份令牌。一次我一次构建云的问题(我认为现在已经修复了)。

I wrote that

I'm sure you can reuse that API with an Access Token to generate and identity token. I had a similar issue with Cloud Build at a time (I think it's fixed now).

始终不够 2025-02-19 13:28:22

您可以使用

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://&lt; region&gt; - &lt; project_id&gt; .cloudfunctions.net/&lt; function_name&gt;

You can use

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>)

Example: Audience for cloud function will look like
https://<REGION>-<PROJECT_ID>.cloudfunctions.net/<FUNCTION_NAME>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文