Google Cloud Platform 驗證 - 無法列出項目或設定項目

Google Cloud Platform 驗證 - 無法列出項目或設定項目

我之前已經透過 Google Cloud Platform 進行了身份驗證,一切正常,但突然之間,今天我開始收到google-gaxNode 應用程式中提到的錯誤:

2023-09-07T18:13:41: Error: 13 INTERNAL: Received RST_STREAM with code 0
2023-09-07T18:13:41:     at callErrorFromStatus (/path/to/app/node_modules/.pnpm/@[email protected]/node_modules/@grpc/grpc-js/build/src/call.js:31:19)
2023-09-07T18:13:41:     at Object.onReceiveStatus (/path/to/app/node_modules/.pnpm/@[email protected]/node_modules/@grpc/grpc-js/build/src/client.js:192:76)
2023-09-07T18:13:41:     at Object.onReceiveStatus (/path/to/app/node_modules/.pnpm/@[email protected]/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:360:141)
2023-09-07T18:13:41:     at Object.onReceiveStatus (/path/to/app/node_modules/.pnpm/@[email protected]/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:323:181)
2023-09-07T18:13:41:     at /path/to/app/node_modules/.pnpm/@[email protected]/node_modules/@grpc/grpc-js/build/src/resolving-call.js:94:78
2023-09-07T18:13:41:     at process.processTicksAndRejections (node:internal/process/task_queues:77:11)
2023-09-07T18:13:41: for call at
2023-09-07T18:13:41:     at ServiceClientImpl.makeUnaryRequest (/path/to/app/node_modules/.pnpm/@[email protected]/node_modules/@grpc/grpc-js/build/src/client.js:160:32)
2023-09-07T18:13:41:     at ServiceClientImpl.<anonymous> (/path/to/app/node_modules/.pnpm/@[email protected]/node_modules/@grpc/grpc-js/build/src/make-client.js:105:19)
2023-09-07T18:13:41:     at /path/to/app/node_modules/.pnpm/@[email protected]/node_modules/@google-cloud/kms/build/src/v1/key_management_service_client.js:241:29
2023-09-07T18:13:41:     at /path/to/app/node_modules/.pnpm/[email protected]/node_modules/google-gax/build/src/normalCalls/timeout.js:44:16
2023-09-07T18:13:41:     at repeat (/path/to/app/node_modules/.pnpm/[email protected]/node_modules/google-gax/build/src/normalCalls/retries.js:80:25)
2023-09-07T18:13:41:     at /path/to/app/node_modules/.pnpm/[email protected]/node_modules/google-gax/build/src/normalCalls/retries.js:118:13
2023-09-07T18:13:41:     at OngoingCallPromise.call (/path/to/app/node_modules/.pnpm/[email protected]/node_modules/google-gax/build/src/call.js:67:27)
2023-09-07T18:13:41:     at NormalApiCaller.call (/path/to/app/node_modules/.pnpm/[email protected]/node_modules/google-gax/build/src/normalCalls/normalApiCaller.js:34:19)
2023-09-07T18:13:41:     at /path/to/app/node_modules/.pnpm/[email protected]/node_modules/google-gax/build/src/createApiCall.js:84:30 {
2023-09-07T18:13:41:   code: 13,
2023-09-07T18:13:41:   details: 'Received RST_STREAM with code 0',
2023-09-07T18:13:41:   metadata: Metadata { internalRepr: Map(0) {}, options: {} },
2023-09-07T18:13:41:   note: 'Exception occurred in retry method that was not classified as transient'
2023-09-07T18:13:41: }

執行gcloud auth list返回No credentialed accounts.,所以我假設身份驗證以某種方式刪除/過期。

我刪除了~/.config/gcloud並嘗試重新驗證:

$ gcloud auth login
Go to the following link in your browser:

    https://accounts.google.com/o/oauth2/auth?response_type=code...

Enter authorization code: [...]

You are now logged in as [[email protected]].
Your current project is [None].  You can change this setting by running:
  $ gcloud config set project PROJECT_ID

到目前為止,一切都很好。看來我已成功通過身份驗證:

$ gcloud auth list
    Credentialed Accounts
ACTIVE  ACCOUNT
*       [email protected]

To set the active account, run:
    $ gcloud config set account `ACCOUNT`

但是,我無法列出這些項目:

$ gcloud projects list
ERROR: (gcloud.projects.list) HTTPError 403: <!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 403 (Forbidden)!!1</title>
  <style>
    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
  </style>
  <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
  <p><b>403.</b> <ins>That’s an error.</ins>
  <p>Your client does not have permission to get URL <code>/v1/projects</code> from this server.  <ins>That’s all we know.</ins>

如果我手動設定項目 ID,它會顯示:

$ gcloud config set project my_project_id
WARNING: You do not appear to have access to project [my_project_id] or it does not exist.
Are you sure you wish to set property [core/project] to my_project_id?

Do you want to continue (Y/n)?  y

Updated property [core/project].

如果我選擇y,我的 Nodejs 應用程式中會出現以下錯誤:

錯誤:無法載入預設憑證。瀏覽至https://cloud.google.com/docs/authentication/getting-started了解更多。

在不同的電腦上,使用相同的使用者登入並執行gcloud projects list可以正常工作:

$ gcloud projects list
PROJECT_ID                 NAME       PROJECT_NUMBER
aaa                        aaa        123456789012
bbb                        bbb        123456789012
ccc                        ccc        123456789012
ddd                        ddd        123456789012
eee                        eee        123456789012
fff                        fff        123456789012
ggg                        ggg        123456789012
hhh                        hhh        123456789012

編輯:

我還嘗試過以下方法:

  • 將 gcloud 更新到最新版本
  • 建立新用戶
  • 停用防火牆
  • 停用apparmor

答案1

如果您嘗試存取受限 VIP 不支援的 API 端點,那麼您將獲得一個403 禁止錯誤

被封鎖的 VIP 的回應內容是不同的HTML 格式錯誤那麼問題就是受限 VIP 整合問題。

IP 位址範圍restricted.googleapis.com and private.googleapis.com分別為 199.36.153.4/30 和 199.36.153.8/30。受限制的 Google API 只能用於受限制的 VIP 支援的服務

如果restricted.googleapis.com正在使用,您可以使用DNS配置作為解決方案,根據您的需要,將 DNS CNAME 記錄更新為www.googleapis.com199.36.153.8/30並確保為子網路啟用私人 Google API 訪問,或者如果虛擬機器具有外部private.googleapis.comIPprivate.googleapis.com預設域也可以使用。

答案2

看起來問題是我的伺服器的 IP 不知何故被 Google Cloud 封鎖了。我嘗試下載https://packages.cloud.google.com/apt/doc/apt-key.gpg它會產生 403 狀態並輸出以下內容:

<!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 403 (Forbidden)!!1</title>
  <style>
    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
  </style>
  <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
  <p><b>403.</b> <ins>That’s an error.</ins>
  <p>Your client does not have permission to get URL <code>/apt/doc/apt-key.gpg</code> from this server.  <ins>That’s all we know.</ins>

相關內容