背景
roles/run.invoker
角色的服务帐户,并确认服务帐户可以访问云运行API。问题
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.
- 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
- Response: `Not Found`
详细信息
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"]
- ✅ 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)
- ❌ 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
关于角色的说明
roles/aiplatform.customCodeServiceAgent
)roles/iam.serviceAccountTokenCreator
)roles/iam.serviceAccountUser
)发布于 2022-07-04 16:41:30
我写了那
我相信您可以通过使用访问令牌来生成和标识令牌来重用该API。我对云构建一次也有类似的问题(我认为现在已经解决了)。
发布于 2022-10-08 21:35:33
您可以使用
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>
https://stackoverflow.com/questions/72853485
复制相似问题