如何增加gcloud重新身份验证超时,目前每1小时过期一次



我运行以下命令

  • 使用我的公司电子邮件id(ldap(向谷歌云进行身份验证
  • 在我的on premis机器上更新我的kubeconfig文件
  • 使用kube-api代理从premis机器访问k8s控制平面。(我使用此代理到达控制平面,因为GKE控制平面VPC和我的公司网络之间没有VPC对等(
gcloud auth login --no-launch-browser  ## I use corporate email id to authenticate
gcloud container clusters get-credentials <>gke_cluster_name> --region <region> --project <gcp_project>
export https_proxy=<kube_api_proxy>:8118  ## Proxy to connect to k8s controlplane
kubectl get no

每1小时,我必须重复以上步骤来重新验证,因为我失败了,否则当我尝试连接到k8S 时会出现以下错误

Unable to connect to the server: error executing access token command "/usr/lib64/google-cloud-sdk/bin/gcloud 
config config-helper --format=json": err=exit status 1 output= stderr=ERROR: gcloud crashed (TransportError):
HTTPSConnectionPool(host='oauth2.googleapis.com', port=443): Max retries exceeded with url: /token 
(Caused by ProxyError('Cannot connect to proxy.', 
OSError('Tunnel connection failed: 403 Request blocked by Privoxy')))

有没有办法增加这个超时时间,比如说4个小时左右,因为我有一个作业运行了1个多小时,但由于超时,它在中间失败了。

CLIgcloud创建有效期为3600秒的OAuth访问令牌。这是非组织项目支持的最长生存期。这也是您正在使用的用户身份的最长生存期。

要增加组织的令牌生存期,必须从服务帐户创建凭据,并设置组织策略约束约束/iam.allowServiceAccountCredentialLifetimeExtension,该约束支持生存期为12小时的令牌。链路

但是,我不知道有什么方法可以在CLI中使用该约束而不修改CLI的源代码,该源代码是用Python编写的。我从未做过这样的更改,因为编写自己的代码要容易得多。

相反,编写您自己的令牌生成器。互联网上有许多源代码示例。我写了一篇包含源代码链接的文章。将代码中的这一行更改为所需时间:

# Set how long this token will be valid in seconds
expires_in = 3600   # Expires in 1 hour

总结:

  1. 您必须是谷歌云组织的一员
  2. 您必须从服务帐户创建凭据
  3. 您必须设置组织策略约束
  4. 约束必须包括允许的服务帐户的电子邮件地址

最新更新