本指南說明如何從使用 Identity-Aware Proxy (IAP) OAuth 管理 API 建立的 OAuth 2.0 用戶端,遷移至 IAP 自動部署的 Google 管理 OAuth 2.0 用戶端。
異動內容
我們即將淘汰 IAP OAuth 管理 API,包括下列用於手動管理 OAuth 用戶端和品牌的 API:
現在 IAP 會在需要時自動建立及管理 OAuth 用戶端,您不必再手動管理 OAuth 2.0 用戶端。這項變更可簡化用戶端管理、減少人為錯誤,並簡化部署程序。
維持不變的部分
如果您使用 Compute Engine API、App Engine API 或 Google Cloud 控制台手動設定 OAuth 用戶端,則不受這項淘汰作業影響。
您可以使用 Google Cloud 控制台繼續建立新的 OAuth 品牌和用戶端設定,並加以管理。現有設定仍會完全受到支援。
如果您未使用 IAP OAuth Admin API,這項異動不會對您造成影響。
詳細說明
自 2025 年 1 月 22 日起,用於建立 IAP OAuth 2.0 用戶端的 IAP OAuth 2.0 Admin API 將淘汰。您不再需要設定 OAuth 用戶端,因此不再需要 IAP OAuth 2.0 Admin API。現在,IAP 預設會使用 Google 管理的 OAuth 用戶端,或在未明確設定 OAuth 2.0 用戶端時,使用該用戶端進行瀏覽器存取。透過瀏覽器存取啟用 IAP 的應用程式時,Google 代管的 OAuth 2.0 用戶端會限制只有相同機構內的使用者可以存取。
隨著 Identity-Aware Proxy (IAP) OAuth 2.0 Admin API 淘汰,您將無法再建立或管理新的 OAuth 用戶端。在此淘汰程序前建立的 OAuth 用戶端不會失效。您可以繼續使用先前建立的 OAuth 用戶端,並透過 Google Cloud 控制台管理這些用戶端。
如果您已使用 IAP 2.0 Admin API 或其他方式建立 OAuth 用戶端,並設定應用程式,這些應用程式仍可繼續運作。應用程式不需要進行任何變更。不過,如果您已設定自動化程序,在部署應用程式時建立新用戶端,或為現有用戶端擷取用戶端密碼,則必須更新自動化指令碼,移除對 IAP OAuth 2.0 Admin API 的依附元件。
如要使用 Google 代管的 OAuth 2.0 用戶端,請參閱「程式輔助存取」指南,為這些應用程式設定程式輔助存取權。
如果 Google 管理的 OAuth 2.0 用戶端無法滿足您的需求,您可以與多個 IAP 應用程式共用單一 OAuth 用戶端,不必為每個新應用程式手動建立用戶端。
必要操作
更新自動化指令碼
如果您使用 Terraform 或其他工具自動設定 IAP,並使用 IAP OAuth 2.0 Admin API,則必須更新自動化指令碼,才能使用預先建立的用戶端,或使用 IAP 的 Google 管理 OAuth 用戶端。
使用 Google 管理的 OAuth 2.0 用戶端,為應用程式設定程式輔助存取權
如果您已有受 IAP 保護的應用程式,並打算將這些應用程式遷移至使用 Google 管理的 OAuth 2.0 用戶端,可以將 OAuth 2.0 用戶端加入允許清單,為這些應用程式設定程式輔助存取權。
遷移啟用 IAP 的資源
如要遷移資源,改用 Google 管理的 OAuth 2.0 用戶端,請按照資源類型 (例如要遷移的 Compute Engine 資源) 的步驟操作。
遷移啟用 IAP 的 App Engine 資源
完成本節中的步驟,即可遷移已啟用 IAP 並設定 OAuth 2.0 用戶端的 App Engine 資源。
gcloud
繼續執行後續步驟前,請確認您使用的是最新版 gcloud CLI。如要瞭解如何安裝 gcloud CLI,請參閱「安裝 gcloud CLI」。
使用 Google Cloud CLI 進行驗證。
gcloud auth login
點選畫面顯示的網址並登入。
登入之後,複製顯示的驗證碼並貼到指令列中。
執行下列指令,指定要繼續使用 IAP 保護的應用程式所屬專案。
gcloud config set project PROJECT_ID
執行下列指令,擷取已設定的 OAuth 2.0 用戶端 ID。
gcloud app describe --format="value(iap.oauth2ClientId)"
如要允許以程式輔助存取,請儲存上一個指令中的用戶端 ID。
如要將 OAuth 2.0 用戶端加入允許清單,以進行程式輔助存取,請對 IAP 設定 API 執行讀取-更新-寫入作業。
gcloud iap settings get --resource-type=app-engine --project=$PROJECT > settings.yaml
更新 settings.yaml 檔案,並在
programmaticClients
下方新增先前擷取的 OAuth 2.0 用戶端 ID,如範例所示。accessSettings: oauthSettings: programmaticClients: - CLIENT_ID
在 App Engine 應用程式上套用新設定
gcloud iap settings set settings.yaml --resource-type=app-engine --project=PROJECT_ID
如要遷移應用程式,請執行下列指令。
gcloud iap web enable --resource-type=app-engine
API
執行下列指令,擷取已設定的 OAuth 2.0 用戶端 ID。
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ "https://appengine.googleapis.com/v1/apps/PROJECT_ID?fields=iap"
執行下列指令,將現有的 IAP 設定擷取到
settings.json
檔案。curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ "https://iap.googleapis.com/v1/projects/PROJECT_ID/iap_web/appengine-PROJECT_ID:iapSettings" > settings.json
更新
settings.json
檔案,將先前儲存的 CLIENT_ID 新增為程式輔助用戶端。{ "accessSettings": { "oauthSettings": { "programmaticClients": [ "CLIENT_ID" ] }, }, }
執行下列指令來更新 IAP 設定。
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -d "@settings.json" \ "https://iap.googleapis.com/v1/projects/PROJECT_ID/iap_web/appengine-PROJECT_ID:iapSettings"
執行下列指令來準備
settings.json
檔案。cat << EOF > settings.json { "iap": { "enabled":true } } EOF
執行下列指令來遷移應用程式。
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -d @settings.json \ "https://appengine.googleapis.com/v1/apps/PROJECT_ID?updateMask=iap"
遷移啟用 IAP 的 Compute Engine 資源
完成本節中的步驟,即可遷移已啟用 IAP 並設定 OAuth 2.0 用戶端的 Compute Engine 資源。
gcloud
繼續執行後續步驟前,請確認您使用的是最新版 gcloud CLI。如要瞭解如何安裝 gcloud CLI,請參閱「安裝 gcloud CLI」。
使用 Google Cloud CLI 進行驗證。
gcloud auth login
點選畫面顯示的網址並登入。
登入之後,複製顯示的驗證碼並貼到指令列中。
執行下列指令,指定要繼續使用 IAP 保護的應用程式所屬專案。
gcloud config set project PROJECT_ID
執行下列指令,擷取已設定的 OAuth 2.0 用戶端 ID。
全球範圍
gcloud compute backend-services describe BACKEND_SERVICE_NAME \ --global \ --format="value(iap.oauth2ClientId)"
區域範圍
如要允許以程式輔助存取,請儲存上一個指令中的用戶端 ID。gcloud compute backend-services describe BACKEND_SERVICE_NAME \ --region REGION_NAME \ --format="value(iap.oauth2ClientId)"
如要將 OAuth 2.0 用戶端加入允許清單,以進行程式輔助存取,請對 IAP 設定 API 執行讀取-更新-寫入作業。
全球範圍
gcloud iap settings get \ --resource-type=compute \ --project=PROJECT_ID \ --service=BACKEND_SERVICE_NAME > settings.yaml
區域範圍
gcloud iap settings get \ --resource-type=compute \ --project=PROJECT_ID \ --service=BACKEND_SERVICE_NAME \ --region=REGION_NAME > settings.yaml
更新 settings.yaml 檔案,並在
programmaticClients
下方新增先前擷取的 OAuth 2.0 用戶端 ID,如範例所示。accessSettings: oauthSettings: programmaticClients: - CLIENT_ID
在 Compute Engine 應用程式上套用新設定
全球範圍
gcloud iap settings set settings.yaml \ --resource-type=compute \ --project=PROJECT_ID \ --service=BACKEND_SERVICE_NAME
區域範圍
gcloud iap settings set settings.yaml \ --resource-type=compute \ --project=PROJECT_ID \ --service=BACKEND_SERVICE_NAME \ --region=REGION_NAME
如要遷移應用程式,請執行全域或區域範圍的指令。
全球範圍
gcloud compute backend-services update BACKEND_SERVICE_NAME \ --global \ --iap=enabled,oauth2-client-id=" ",oauth2-client-secret=" "
區域範圍
gcloud compute backend-services update BACKEND_SERVICE_NAME \ --region REGION_NAME \ --iap=enabled,oauth2-client-id=" ",oauth2-client-secret=" "
如要確認 OAuth 用戶端 ID 未設定,請執行下列全域或區域範圍指令。 執行指令後,請檢查輸出內容,確認 OAuth 用戶端 ID 欄位是否為空白。
全球範圍
gcloud compute backend-services describe BACKEND_SERVICE_NAME \ --global
區域範圍
gcloud compute backend-services describe BACKEND_SERVICE_NAME \ --region REGION_NAME
API
執行下列指令,擷取已設定的 OAuth 2.0 用戶端 ID。
全球範圍
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ "https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices/BACKEND_SERVICE_NAME?fields=iap.oauth2ClientId"
區域範圍
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ "https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION_NAME/backendServices/BACKEND_SERVICE_NAME?fields=iap.oauth2ClientId"
執行下列指令,將現有的 IAP 設定擷取到
settings.json
檔案。全球範圍
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://iap.googleapis.com/v1/projects/PROJECT_ID/iap_web/compute/services/BACKEND_SERVICE_NAME:iapSettings" > settings.json
區域範圍
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://iap.googleapis.com/v1/projects/PROJECT_ID/iap_web/compute-REGION_NAME/services/BACKEND_SERVICE_NAME:iapSettings" > settings.json
更新
settings.json
檔案,將先前儲存的 CLIENT_ID 新增為程式輔助用戶端。{ "accessSettings": { "oauthSettings": { "programmaticClients": [ "CLIENT_ID" ] }, }, }
執行下列指令來更新 IAP 設定。
全球範圍
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -d "@settings.json" \ "https://iap.googleapis.com/v1/projects/PROJECT_ID/iap_web/compute/services/BACKEND_SERVICE_NAME:iapSettings"
區域範圍
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -d "@settings.json" \ "https://iap.googleapis.com/v1/projects/PROJECT_ID/iap_web/compute-REGION_NAME/services/BACKEND_SERVICE_NAME:iapSettings"
執行下列指令來準備
settings.json
檔案。cat << EOF > settings.json { "iap": { "enabled":true, "oauth2ClientId": " ", "oauth2ClientSecret": " " } } EOF
執行下列指令,遷移 IAP 資源。
全球範圍
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -d @settings.json \ "https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices/BACKEND_SERVICE_NAME"
區域範圍
curl -X PATCH
-H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -d @settings.json \ "https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION_NAME/backendServices/BACKEND_SERVICE_NAME"如要確認 OAuth 用戶端 ID 未設定,請執行下列全域或區域範圍指令。 執行指令後,請檢查輸出內容,確認 OAuth 用戶端 ID 欄位是否為空白。
全球範圍
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices/BACKEND_SERVICE_NAME"
區域範圍
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION_NAME/backendServices/BACKEND_SERVICE_NAME"
Terraform
如果您要遷移已啟用 IAP 的現有資源,改用 Google 管理的 OAuth 用戶端,請務必將 oauth2_client_id
和 oauth2_client_secret
欄位更新為單一空白字元,明確取消設定這些欄位。
範例:
resource "google_compute_backend_service" "default" {
name = "tf-test-backend-service-external"
protocol = "HTTP"
load_balancing_scheme = "EXTERNAL"
iap {
oauth2_client_id = " "
oauth2_client_secret = " "
}
}
oauth2_client_id
和 oauth2_client_secret
欄位為選用欄位,如果您使用已啟用 IAP 的新資源,可以忽略這些欄位。
詳情請參閱 Terraform 說明文件。
遷移已啟用 IAP 的 Cloud Run 資源
完成本節中的步驟,即可遷移已啟用 IAP 並設定 OAuth 2.0 用戶端的 Cloud Run 資源。
gcloud
繼續執行後續步驟前,請確認您使用的是最新版 gcloud CLI。如需安裝 gcloud CLI 的操作說明,請參閱「安裝 gcloud CLI」。
如要進行驗證,請使用 Google Cloud CLI 執行下列指令。
gcloud auth login
點選畫面顯示的網址並登入。
登入之後,複製顯示的驗證碼並貼到指令列中。
執行下列指令,指定要繼續使用 IAP 保護的應用程式所屬專案。
gcloud config set project PROJECT_ID
執行下列指令,擷取已設定的 OAuth 2.0 用戶端 ID。
全球範圍
gcloud compute backend-services describe BACKEND_SERVICE_NAME \ --global \ --format="value(iap.oauth2ClientId)"
區域範圍
如要允許以程式輔助存取,請儲存上一個指令中的用戶端 ID。gcloud compute backend-services describe BACKEND_SERVICE_NAME \ --region REGION_NAME \ --format="value(iap.oauth2ClientId)"
如要將 OAuth 2.0 用戶端加入允許清單,以進行程式輔助存取,請對 IAP 設定 API 執行讀取-更新-寫入作業。
全球範圍
gcloud iap settings get \ --resource-type=compute \ --project=PROJECT_ID \ --service=BACKEND_SERVICE_NAME > settings.yaml
區域範圍
gcloud iap settings get \ --resource-type=compute \ --project=PROJECT_ID \ --service=BACKEND_SERVICE_NAME \ --region=REGION_NAME > settings.yaml
更新 settings.yaml 檔案,並在
programmaticClients
下方新增先前擷取的 OAuth 2.0 用戶端 ID,如範例所示。accessSettings: oauthSettings: programmaticClients: - CLIENT_ID
在 Compute Engine 應用程式上套用新設定
全球範圍
gcloud iap settings set settings.yaml \ --resource-type=compute \ --project=PROJECT_ID \ --service=BACKEND_SERVICE_NAME
區域範圍
gcloud iap settings set settings.yaml \ --resource-type=compute \ --project=PROJECT_ID \ --service=BACKEND_SERVICE_NAME \ --region=REGION_NAME
如要遷移資源,請執行全域或區域範圍的指令。
全球範圍
gcloud compute backend-services update BACKEND_SERVICE_NAME \ --global \ --iap=enabled,oauth2-client-id=" ",oauth2-client-secret=" "
區域範圍
gcloud compute backend-services update BACKEND_SERVICE_NAME \ --region REGION_NAME \ --iap=enabled,oauth2-client-id=" ",oauth2-client-secret=" "
如要確認 OAuth 用戶端 ID 未設定,請執行下列全域或區域範圍指令。 執行指令後,請檢查輸出內容,確認 OAuth 用戶端 ID 欄位是否為空白。
全球範圍
gcloud compute backend-services describe BACKEND_SERVICE_NAME \ --global
區域範圍
gcloud compute backend-services describe BACKEND_SERVICE_NAME \ --region REGION_NAME
API
執行下列指令,擷取已設定的 OAuth 2.0 用戶端 ID。
全球範圍
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ "https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices/BACKEND_SERVICE_NAME?fields=iap.oauth2ClientId"
區域範圍
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ "https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION_NAME/backendServices/BACKEND_SERVICE_NAME?fields=iap.oauth2ClientId"
執行下列指令,將現有的 IAP 設定擷取到
settings.json
檔案。全球範圍
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://iap.googleapis.com/v1/projects/PROJECT_ID/iap_web/compute/services/BACKEND_SERVICE_NAME:iapSettings" > settings.json
區域範圍
curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://iap.googleapis.com/v1/projects/PROJECT_ID/iap_web/compute-REGION_NAME/services/BACKEND_SERVICE_NAME:iapSettings" > settings.json
更新
settings.json
檔案,將先前儲存的 CLIENT_ID 新增為程式輔助用戶端。{ "accessSettings": { "oauthSettings": { "programmaticClients": [ "CLIENT_ID" ] }, }, }
執行下列指令來更新 IAP 設定。
全球範圍
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -d "@settings.json" \ "https://iap.googleapis.com/v1/projects/PROJECT_ID/iap_web/compute/services/BACKEND_SERVICE_NAME:iapSettings"
區域範圍
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -d "@settings.json" \ "https://iap.googleapis.com/v1/projects/PROJECT_ID/iap_web/compute-REGION_NAME/services/BACKEND_SERVICE_NAME:iapSettings"
執行下列指令來準備
settings.json
檔案。cat << EOF > settings.json { "iap": { "enabled":true, "oauth2ClientId": " ", "oauth2ClientSecret": " " } } EOF
執行下列指令來遷移資源。
全球範圍
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -d @settings.json \ "https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices/BACKEND_SERVICE_NAME"
區域範圍
curl -X PATCH
-H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -d @settings.json \ "https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION_NAME/backendServices/BACKEND_SERVICE_NAME"如要確認 OAuth 用戶端 ID 未設定,請執行下列全域或區域範圍指令。 執行指令後,請檢查輸出內容,確認 OAuth 用戶端 ID 欄位是否為空白。
全球範圍
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices/BACKEND_SERVICE_NAME"
區域範圍
curl -X PATCH \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ "https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/regions/REGION_NAME/backendServices/BACKEND_SERVICE_NAME"
遷移啟用 IAP 的 Google Kubernetes Engine 資源
將下列 IAP 區塊新增至 BackendConfig 自訂資源定義 (CRD)。這會啟用 IAP,並使用 Google 代管的 OAuth 2.0 用戶端。
apiVersion: cloud.google.com/v1
kind: BackendConfig
metadata:
name: config-default
namespace: my-namespace
spec:
iap:
enabled: true
使用服務帳戶 JWT 向 IAP 進行驗證
您可以使用服務帳戶 JWT 向 IAP 進行驗證,不必使用已淘汰的 OAuth 管理 API。
取得 OAuth 用戶端的密鑰
如要在不使用已淘汰的 OAuth 管理 API 的情況下取得 OAuth 用戶端的密鑰,請按照這個 Terraform 範例中的操作說明,使用 Secret Manager:
google_secret_manager_secret
。
判斷您是否使用 OAuth Admin API
如要確認您是否使用 OAuth Admin API,請完成下列步驟。
在 Google Cloud 控制台中開啟 IAP API 頁面,然後選取要分析的專案。
前往「IAP APIs」頁面在「選取圖表」清單中,選取「依 API 方法劃分的流量」,然後按一下「確定」。
在「方法」部分,找出任何帶有
google.cloud.iap.v1.IdentityAwareProxyOAuthService
前置字元的方法,這表示專案使用 OAuth Admin API。