Google云:身份验证范围不足

时间:2018-05-10 14:20:38

标签: kubernetes google-cloud-platform google-vision

我在向我的Google Cloud Kubernetes群集中部署的Spring启动应用程序发送请求时遇到了困难。我的应用会收到一张照片并将其发送到Google Vision API。我正在使用提供的客户端库(https://cloud.google.com/vision/docs/libraries#client-libraries-install-java),如https://cloud.google.com/vision/docs/auth所述:

  

如果您使用客户端库来调用Vision API,请使用Application Default Credentials(ADC)。使用ADC的服务在GOOGLE_APPLICATION_CREDENTIALS环境变量中查找凭据。除非您特别希望让ADC使用其他凭据(例如,用户凭据),否则我们建议您将此环境变量设置为指向您的服务帐户密钥文件。

在我的本地机器上,每个工作都很好,我有一个带有env的docker容器。 varialbe GOOGLE_APPLICATION_CREDENTIALS指向我的服务帐户密钥文件。

我的群集中没有此变量。这是我从Kubernetes集群中的应用程序获得的响应:

{
    "timestamp": "2018-05-10T14:07:27.652+0000",
    "status": 500,
    "error": "Internal Server Error",
    "message": "io.grpc.StatusRuntimeException: PERMISSION_DENIED: Request had insufficient authentication scopes.",
    "path": "/image"
}

我做错了什么? Thx提前!

2 个答案:

答案 0 :(得分:0)

这意味着您正在尝试访问未启用或经过身份验证的服务。您确定已启用对Google愿景的访问权限吗?

您可以在https://console.cloud.google.com/apis/dashboard处的信息中心检查/启用API,或导航至 API&服务来自菜单

答案 1 :(得分:0)

我还必须在我的GKE设置中指定GOOGLE_APPLICATION_CREDENTIALS环境变量,这些是我完成的步骤,感谢How to set GOOGLE_APPLICATION_CREDENTIALS on GKE running through Kubernetes

<强> 1。创建秘密(在我的Gitlab部署步骤中):

n

<强> 2。设置音量:

kubectl create secret generic google-application-credentials --from-file=./application-credentials.json

第3。设置卷装:

...
volumes:
- name: google-application-credentials-volume
  secret:
    secretName: google-application-credentials
    items:
    - key: application-credentials.json # default name created by the create secret from-file command
      path: application-credentials.json

<强> 4。设置环境变量:

spec:
  containers:
  - name: my-service
    volumeMounts:
    - name: google-application-credentials-volume
      mountPath: /etc/gcp
      readOnly: true
相关问题