本頁面說明如何使用 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 用戶端就無法使用。
如果您尚未設定專案的 OAuth 同意畫面,系統會提示您進行設定。如要設定 OAuth 同意畫面,請參閱「設定 OAuth 同意畫面」。
設定 IAP 存取權
-
前往「Identity-Aware Proxy」頁面。
前往「Identity-Aware Proxy」頁面 - 選取要使用 IAP 保護的專案。
- 找出您要授予存取權的資源,然後勾選旁邊的核取方塊。
- 在右側面板中,按一下「Add principal」(新增管理員)。
-
在隨即顯示的「Add principals」(新增主體) 對話方塊中,輸入群組或個別使用者的電子郵件地址,這些群組或個別使用者應擁有專案的「IAP-Secured Web App User」(受 IAP 保護的網路應用程式使用者) 角色。
以下類型的主體可以擁有這個角色:
- Google 帳戶:user@gmail.com
- Google 群組:admins@googlegroups.com
- 服務帳戶:server@example。gserviceaccount.com
- Google Workspace 網域:example.com
請務必新增您可以存取的 Google 帳戶。
- 從「Roles」(角色) 下拉式清單中選取「Cloud IAP」>「IAP-secured Web App User」(受 IAP 保護的網路應用程式使用者)。
- 按一下「Save」(儲存)。
正在啟用 IAP
-
在「Identity-Aware Proxy」頁面的「APPLICATIONS」下方,尋找您要限制存取權的應用程式。如要為資源啟用 IAP,請在「IAP」欄中
- 在隨即顯示的「Turn on IAP」(開啟 IAP) 視窗中,按一下「Turn On」(開啟),確認您要使用 IAP 保護資源。啟用 IAP 後,系統會要求您提供負載平衡器所有連線的登入憑證。只有在專案中擁有「IAP-Secured Web App User」角色的帳戶才能取得存取權。
gcloud
Before you set up your project and IAP, you need an up-to-date version of the gcloud CLI. For instructions on how to install the gcloud CLI, see Install the gcloud CLI.
-
To authenticate, use the Google Cloud CLI and run the following command.
gcloud auth login - Click the URL that appears and sign in.
- After you sign in, copy the verification code that appears and paste it in the command line.
-
Run the following command to specify the project that contains the applications that you want to protect with IAP.
gcloud config set project PROJECT_ID -
To enable IAP, run the following command.
gcloud iap web enable --resource-type=app-engine --versions=version -
Add principals who should have the IAP-secured Web App user role to the project.
gcloud projects add-iam-policy-binding PROJECT_ID \ --member=PRINCIPAL_IDENTIFIER \ --role=roles/iap.httpsResourceAccessor- Replace PROJECT_ID with your project ID.
- Replace PRINCIPAL_IDENTIFIER with the necessary principals. This can be a
type of domain, group, serviceAccount, or user. For example,
user:myemail@example.com.
After you enable IAP, you can use the gcloud CLI to modify the
IAP access policy using the IAM role
roles/iap.httpsResourceAccessor. Learn more about
managing roles and permissions.
API
Run the following command to prepare a
settings.jsonfile.cat << EOF > settings.json { "iap": { "enabled":true } } EOFRun the following command to enable 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"
After you enable IAP, you can use the Google Cloud CLI to modify the
IAP access policy using the IAM role
roles/iap.httpsResourceAccessor. Learn more about
managing roles and permissions.
測試使用者驗證機制
從您新增至 IAP 的 Google 帳戶存取應用程式網址,並取得 IAP 受保護的網頁應用程式使用者 角色,如上文所述。您對應用程式的存取權應不受限制。
使用 Chrome 的無痕式視窗存取應用程式,並在系統提示時登入。如果您嘗試使用未經授權的帳戶存取應用程式,且該帳戶沒有「IAP 安全性保護的 Web 應用程式使用者」角色,系統會顯示您沒有存取權的訊息。