本頁適用於 Apigee 和 Apigee Hybrid。
查看
Apigee Edge 說明文件。
本頁說明如何在 Apigee 機構中建立 Apigee Spaces,以便大規模管理 Apigee API 資源的身分與存取權管理 (IAM) 政策。
本指南將概述下列步驟:
如要進一步瞭解使用 Apigee Spaces 管理 API 資源的好處,請參閱「Apigee Spaces」。
事前準備
開始使用聊天室前:
- 佈建 Apigee。確認您要使用的 Apigee 訂閱或即付即用機構已佈建。如要進一步瞭解 Apigee 佈建所需的步驟,請參閱佈建簡介。
- 取得驗證憑證。在指令列上執行指令來建立及管理聊天室之前,請使用下列指令取得
gcloud
驗證憑證:export TOKEN=$(gcloud auth print-access-token)
必要角色和權限
Make sure that you have the following role or roles on the project: Apigee > Apigee Organization Admin
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
前往「身分與存取權管理」頁面 - 選取專案。
- 按一下 「授予存取權」。
-
在「New principals」(新增主體) 欄位中輸入使用者 ID。 通常是 Google 帳戶的電子郵件地址。
- 在「請選擇角色」清單中,選取角色。
- 如要授予其他角色,請按一下 「Add another role」(新增其他角色),然後新增其他角色。
- 按一下 [Save]。
- ORG_NAME 是 Apigee 機構的名稱。
- SPACE_NAME 是聊天室的名稱和 ID。
- DISPLAY_NAME 是工作區的名稱,應顯示在 Cloud 主控台中的 Apigee UI 中。如未提供顯示名稱,系統會使用空間名稱做為顯示名稱。
- 聊天室成員清單
- 授予成員的角色或角色清單
- ORG_NAME 是 Apigee 機構的名稱。
- SPACE_NAME 是聊天室名稱。
- USER_EMAIL 是您要新增至聊天室的使用者電子郵件地址。
- IAM_ROLE 是指您要指派給使用者做為聊天室成員的 IAM 角色名稱。
- ORG_NAME 是 Apigee 機構的名稱。
- SPACE_NAME 是聊天室名稱。
- GROUP_EMAIL 是您要新增至聊天室的群組電子郵件地址。
- IAM_ROLE 是指派給團隊的 IAM 角色名稱,用於聊天室成員。
- ORG_NAME 是 Apigee 機構的名稱。
- SPACE_NAME 是聊天室名稱。
- ORG_NAME 是 Apigee 機構的名稱。
- SPACE_NAME 是聊天室名稱。
- ORG_NAME 是 Apigee 機構的名稱。
- SPACE_NAME 是聊天室的名稱和 ID。
- DISPLAY_NAME 是工作區的新顯示名稱。
- 進一步瞭解 Apigee Spaces。
- 瞭解如何使用 Apigee Spaces 管理 API 資源。
- 查看身分與存取權管理 (IAM) 說明文件。
建立聊天室
如要執行這項工作,您必須具備 apigee.spaces.create
權限。Apigee Organization Admin
角色具有此權限。
如要在 Apigee 機構中建立空間,請使用下列指令:
curl -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \ "https://apigee.googleapis.com/v1/organizations/ORG_NAME/spaces" \ --data-raw '{ "name":"SPACE_NAME", "displayName":"DISPLAY_NAME", }'
其中:
舉例來說,下列指令會在 acme 機構中建立名為 red 的聊天室:
curl -X POST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \ https://apigee.googleapis.com/v1/organizations/acme/spaces \ --data-raw '{ "name":"red", "displayName":"Red", }'
在貴機構中建立 Space 後,使用 Cloud 控制台中的 Apigee UI 的機構成員在使用者介面中建立 API 資源時,會看到 Space 做為可用的參數。此外,在 UI 中查看 API Proxy、API 產品和共用流程的清單時,工作區會顯示為指派給該工作區的 API 資源屬性。
聊天室。管理聊天室中的成員和角色
建立聊天室後,您可以將團隊成員新增至聊天室,並指派 IAM 角色,以便在聊天室中建立及管理 API 資源。Apigee 使用者只能在獲得適當權限的團隊成員所在的聊天室中,建立及管理資源。由於 IAM 存取權控管是在聊天室層級授予,因此除非組織成員明確新增至聊天室,否則無法存取或管理屬於該聊天室的 Apigee API 資源。如要瞭解管理聊天室資源所需的 IAM 角色和權限,請參閱「 建立及管理聊天室資源」。
將機構成員新增至聊天室
當機構成員加入聊天室時,系統會為該聊天室建立身分與存取權管理政策繫結,該繫結會採用兩個引數:
如要執行這項工作,您必須具備 apigee.spaces.setIamPolicy
權限。Apigee Organization Admin
角色具有此權限。
如要將組織成員新增至聊天室並指派 IAM 角色,請使用下列指令:
curl -X POST -H "Authorization: Bearer $TOKEN" -H "Content-type: application/json" \ "https://apigee.googleapis.com/v1/organizations/ORG_NAME/spaces/SPACE_NAME:setIamPolicy" -d \ '{ "policy":{ "bindings":[ { "members": ["user:USER_EMAIL"], "role": "roles/IAM_ROLE" } ] } }'
其中:
舉例來說,這個指令會將 [email protected] 使用者新增至 acme 機構中的 red 聊天室,並授予 IAM 角色 apigee.spaceContentEditor
:
curl -X POST -H "Authorization: Bearer $TOKEN" -H "Content-type: application/json" \ "https://apigee.googleapis.com/v1/organizations/acme/spaces/red:setIamPolicy" -d \ '{ "policy":{ "bindings":[ { "members": ["user:[email protected]"], "role": "roles/apigee.spaceContentEditor" } ] } }'
您可以更新聊天室的 IAM 政策,為聊天室成員新增其他角色和權限。如要更新工作區的 IAM 政策,請使用本節所述的 setIamPolicy
方法,並使用經修訂的所需角色和權限清單。這會為空間建立新的 IAM 政策,並相應調整角色和權限。
將團隊成員新增至聊天室
或者,您也可以將團隊成員新增至聊天室,並指派 IAM 角色。如要將團隊成員新增至聊天室並指派 IAM 角色,請使用下列指令:
curl -X POST -H "Authorization: Bearer $TOKEN" -H "Content-type: application/json" \ "https://apigee.googleapis.com/v1/organizations/ORG_NAME/spaces/SPACE_NAME:setIamPolicy" -d \ '{ "policy":{ "bindings":[ { "members": ["group:GROUP_EMAIL"], "role": "roles/IAM_ROLE" } ] } }'
其中:
舉例來說,這項指令會將 [email protected] 群組新增至 acme 機構中的紅色聊天室,並將 apigee.spaceContentEditor
角色授予該群組:
curl -X POST -H "Authorization: Bearer $TOKEN" -H "Content-type: application/json" \ "https://apigee.googleapis.com/v1/organizations/acme/spaces/red:setIamPolicy" -d \ '{ "policy":{ "bindings":[ { "members": ["group:[email protected]"], "role": "roles/apigee.spaceContentEditor" } ] } }'
如將機構成員新增至聊天室所述,IAM 角色 apigee.spaceContentEditor
包含管理聊天室資源所需的許多權限。不過,您可能需要為使用者授予其他角色,才能執行特定工作。
確認 Spaces 身分與存取權管理政策指派
如要執行這項工作,您必須具備 apigee.spaces.getIamPolicy
權限。Apigee Organization Admin
角色具有此權限。
如要確認 IAM 政策是否正確套用至工作區,請使用下列指令:
curl -X GET -H "Authorization: Bearer $TOKEN" \ "https://apigee.googleapis.com/v1/organizations/ORG_NAME/spaces/SPACE_NAME:getIamPolicy"
其中:
舉例來說,您可以使用下列指令,確認 acme 組織中的 red 工作區的身分與存取權管理政策設定正確無誤:
curl -X GET -H "Authorization: Bearer $TOKEN" \ "https://apigee.googleapis.com/v1/organizations/acme/spaces/red:getIamPolicy"
指令的輸出內容會傳回空間目前的 IAM 政策,內容應如下所示:
{ "version": "0", "bindings": [ { "role": "roles/apigee.spaceContentEditor", "members": [ "group:[email protected]" ] } ] }
在這個範例中,聊天室的 IAM 政策會將 apigee.spaceContentEditor
角色授予聊天室成員,在本例中是群組 [email protected] 的成員
請注意,只有 red 團隊的成員才有權存取 red 聊天室。 也就是說,只有紅隊成員可以在紅色聊天室中建立及管理 API 資源。如果其他機構團隊成員 (例如 [email protected]) 嘗試存取在 red 工作區下建立的 API 代理程式,就會看到以下錯誤訊息:
{ "error": { "code": 403, "message": "Permission denied on resource \"organizations\/acme\/apis\/proxy-1\" (or it may not exist).", "status": "PERMISSION_DENIED" } }
從聊天室中移除成員
如要從聊天室中移除成員或一組成員,您必須為聊天室設定新的 IAM 政策,並提供修訂過的成員或群組名單。使用 setIamPolicy
方法會為聊天室建立新的 IAM 政策,並相應調整角色和成員。
舉例來說,如要更新 blue 團隊聊天的成員,您可以先使用下列指令檢查目前的 IAM 政策:
curl -X GET -H "Authorization: Bearer $TOKEN" \ "https://apigee.googleapis.com/v1/organizations/acme/spaces/blue:getIamPolicy"
指令的輸出內容會傳回空間目前的 IAM 政策,內容應如下所示:
{ "version": "0", "bindings": [ { "role": "roles/apigee.spaceContentEditor", "members": [ "group: [email protected]", "users: [email protected], [email protected], [email protected]" ] } ] }
如要從聊天室中移除 [email protected],請使用下列指令:
curl -X POST -H "Authorization: Bearer $TOKEN" -H "Content-type: application/json" \ "https://apigee.googleapis.com/v1/organizations/acme/spaces/blue:setIamPolicy" -d \ '{ "policy":{ "bindings":[ { "members": [ "group:[email protected]", "users: [email protected], [email protected]" ] "role": "roles/apigee.spaceContentEditor" } ] } }'
聊天室的新身分與存取權管理政策將不再包含 [email protected]。
如要從聊天室中移除群組成員,請先從群組中移除該成員,然後重新執行 setIamPolicy 指令,以群組電子郵件別名的正確成員資格更新聊天室的 IAM 政策。
列出機構中的所有聊天室
如要執行這項工作,您必須具備 apigee.spaces.list
權限。Apigee Organization Admin
角色具有此權限。
如要列出 Apigee 機構中的所有空間,請使用下列指令:
curl -X GET -H "Authorization: Bearer $TOKEN" \ "https://apigee.googleapis.com/v1/organizations/ORG_NAME/spaces"
其中 ORG_NAME 是 Apigee 機構的名稱。
舉例來說,下列指令會列出 acme 組織中的所有工作區:
curl -X GET -H "Authorization: Bearer $TOKEN" \ "https://apigee.googleapis.com/v1/organizations/acme/spaces"
這個指令會傳回類似以下的內容:
{ "spaces": [ { "name": "red", "createTime": "2024-08-02T23:26:03.001512Z", "updateTime": "2024-08-02T23:26:03.001512Z" }, { "name": "blue", "createTime": "2024-08-02T00:34:54.159331Z", "updateTime": "2024-08-02T00:34:54.159331Z" } ] }
取得聊天室詳細資料
如要執行這項工作,您必須具備 apigee.spaces.get
權限。Apigee Organization Admin
角色具有此權限。
使用下列指令取得空間詳細資料:
curl -X GET -H "Authorization: Bearer $TOKEN" \ "https://apigee.googleapis.com/v1/organizations/ORG_NAME/spaces/SPACE_NAME"
其中:
舉例來說,下列指令可取得 acme 組織中「red」 工作區的詳細資料:
curl -X GET -H "Authorization: Bearer $TOKEN" \ "https://apigee.googleapis.com/v1/organizations/acme/spaces/red"
這個指令會傳回類似以下的內容:
{ "name": "red", "createTime": "2024-08-02T23:26:03.001512Z", "updateTime": "2024-08-02T23:26:03.001512Z" }
更新聊天室
如要執行這項工作,您必須具備 apigee.spaces.update
權限。Apigee Organization Admin
角色具有此權限。
如要更新 Apigee 機構中的 Space,請使用下列指令:
curl -X PATCH -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \ "https://apigee.googleapis.com/v1/organizations/ORG_NAME/spaces/SPACE_NAME" \ --data-raw '{ "displayName":"DISPLAY_NAME" }'
其中:
舉例來說,下列指令會更新 acme 組織中 red 工作區的顯示名稱:
curl -X PATCH -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \ "https://apigee.googleapis.com/v1/organizations/acme/spaces/red" -d \ '{ "displayName": "Red team space" }'
刪除聊天室
如要執行這項工作,您必須具備 apigee.spaces.delete
權限。Apigee Organization Admin
角色具有此權限。刪除聊天室前,請務必先刪除聊天室中的所有資源。
如要刪除 Apigee 機構中的 Space,請使用下列指令:
curl -X DELETE -H "Authorization: Bearer $TOKEN" \ "https://apigee.googleapis.com/v1/organizations/ORG_NAME/spaces/SPACE_NAME"
舉例來說,下列指令會刪除 acme 組織中的「red」工作區:
curl -X DELETE -H "Authorization: Bearer $TOKEN" \ "https://apigee.googleapis.com/v1/organizations/acme/spaces/red"
如果您嘗試刪除仍與相關聯的有效資源的聊天室,系統會顯示以下錯誤訊息:
{ "error": { "code": 400, "message": "Space \"red\" has resources associated with it. Please delete the resources before deleting the space.", "status": "FAILED_PRECONDITION" } }
如要解決這項錯誤,請先刪除或移動工作區中的資源,再嘗試刪除工作區。