本頁面說明如何使用 Identity-Aware Proxy (IAP) 保護 App Engine 執行個體。
事前準備
如要為 App Engine 啟用 IAP,請先準備好下列項目:
- 已啟用計費功能的 Google Cloud 主控台專案。
如果您尚未設定 App Engine 執行個體,請參閱「部署 App Engine」一文,取得完整逐步操作說明。
IAP 會使用 Google 代管的 OAuth 用戶端來驗證使用者。只有貴機構的使用者可以存取啟用 IAP 的應用程式。如要允許機構外使用者存取,請參閱「為外部應用程式啟用應用程式內購功能」。
啟用 IAP
控制台
使用 Google Cloud 主控台啟用 IAP 時,Google 代管的 OAuth 用戶端就無法使用。
If you haven't configured your project's OAuth consent screen, you'll be prompted to do so. To configure your OAuth consent screen, see Setting up your OAuth consent screen.
Setting up IAP access
-
Go to the
Identity-Aware Proxy page.
Go to the Identity-Aware Proxy page - Select the project you want to secure with IAP.
- Select the checkbox next to the resource you want to grant access to.
- On the right side panel, click Add principal.
-
In the Add principals dialog that appears, enter the email addresses of groups or
individuals who should have the IAP-secured Web App User role for the project.
The following kinds of principals can have this role:
- Google Account: user@gmail.com
- Google Group: admins@googlegroups.com
- Service account: server@example.gserviceaccount.com
- Google Workspace domain: example.com
Make sure to add a Google Account that you have access to.
- Select Cloud IAP > IAP-secured Web App User from the Roles drop-down list.
- Click Save.
Turning on IAP
-
On the Identity-Aware Proxy page, under APPLICATIONS,
find the application you want to restrict
access to. To turn on IAP for a resource,
- In the Turn on IAP window that appears, click Turn On to confirm that you want IAP to secure your resource. After you turn on IAP, it requires login credentials for all connections to your load balancer. Only accounts with the IAP-Secured Web App User role on the project will be given access.
gcloud
您需要最新版的 gcloud CLI,才能設定專案和 IAP。如需安裝 gcloud CLI 的操作說明,請參閱「安裝 gcloud CLI」。
-
如要驗證,請使用 Google Cloud CLI 執行下列指令。
gcloud auth login - 點選畫面顯示的網址,然後登入。
- 登入之後,複製顯示的驗證碼並貼到指令列中。
-
執行下列指令,指定包含您要使用 IAP 保護的應用程式專案。
gcloud config set project PROJECT_ID -
如要啟用 IAP,請執行下列指令。
gcloud iap web enable --resource-type=app-engine --versions=version -
將應擁有「IAP-Secured Web App User」(受 IAP 保護的網路應用程式使用者) 角色的主體新增至專案。
gcloud projects add-iam-policy-binding PROJECT_ID \ --member=PRINCIPAL_IDENTIFIER \ --role=roles/iap.httpsResourceAccessor- 將 PROJECT_ID 替換為您的專案 ID。
- 請將 PRINCIPAL_IDENTIFIER 替換為必要的管理者。這可以是網域、群組、服務帳戶或使用者的類型。例如
user:myemail@example.com。
啟用 IAP 後,您可以使用 gcloud CLI 以 IAM 角色 roles/iap.httpsResourceAccessor 修改 IAP 存取權政策。進一步瞭解如何管理角色和權限。
API
執行下列指令來準備
settings.json檔案。cat << EOF > settings.json { "iap": { "enabled":true } } 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://appengine.googleapis.com/v1/apps/PROJECT_ID?updateMask=iap"
啟用 IAP 後,您可以使用 Google Cloud CLI 以 IAM 角色 roles/iap.httpsResourceAccessor 修改 IAP 存取權政策。進一步瞭解如何管理角色和權限。
測試使用者驗證機制
從您新增至 IAP 的 Google 帳戶存取應用程式網址,並取得 IAP 受保護的網頁應用程式使用者 角色,如上文所述。您對應用程式的存取權應不受限制。
使用 Chrome 的無痕式視窗存取應用程式,並在系統提示時登入。如果您嘗試使用未經授權的帳戶存取應用程式,且該帳戶沒有「IAP 安全性保護的 Web 應用程式使用者」角色,系統會顯示您沒有存取權的訊息。