首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >有时无法在googleapis auth库中的GKE Autopilot上检索应用程序默认凭据

有时无法在googleapis auth库中的GKE Autopilot上检索应用程序默认凭据
EN

Stack Overflow用户
提问于 2021-08-19 21:21:11
回答 1查看 127关注 0票数 1

我的GKE Autopilot集群中的一些pods无法获取应用程序默认凭据来调用其他GCP服务。

我将应用一个新的部署,3个pod中有1到2个将无法使用googleapis (google-auth-library) npm包(使用版本v73.0.0和最新版本v84.0.0尝试)进行身份验证。

我得到了:

Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information. at GoogleAuth.getApplicationDefaultAsync (/node_modules/google-auth-library/build/src/auth/googleauth.js:173:19)

我正在使用此代码,并在失败时重试:

代码语言:javascript
复制
       const {google} = require('googleapis');

       const setGoogleAuth = async () => {
            try {
                const auth = new google.auth.GoogleAuth({
                    // Scopes can be specified either as an array or as a single, space-delimited string.
                    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
                });             
                
                // Acquire an auth client, and bind it to all future calls
                const authClient = await auth.getClient();
                google.options({auth: authClient});
            } catch (e) {
                console.error(e)
                
                //retry

                //sleep for 3 seconds
                await sleep(3000)
                

                await setGoogleAuth()
            }
            
        }

通过curl http://metadata/computeMetadata/v1/instance/service-accounts/default/identity?audience=<my-gcp-endpoint>手动调用元数据服务器将返回一个来自pod的有效令牌,该令牌无法通过googleapis包进行身份验证

有时杀死pod并让它们重建工作(使用水平Pod Autoscaler)。其他时候,我对部署没有任何问题。有时,杀死pod以使其重新创建根本没有任何帮助。这种行为看起来非常不确定。

如有任何帮助,将不胜感激,谢谢!

EN

回答 1

Stack Overflow用户

发布于 2021-09-12 02:22:42

在环境中设置DETECT_GCP_RETRIES=3或K_SERVICE=true起作用。

在这里查看完整的GitHub问题讨论:https://github.com/googleapis/google-auth-library-nodejs/issues/1236

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

https://stackoverflow.com/questions/68854640

复制
相关文章

相似问题

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