使用 Google Cloud 控制台授予 IAM 角色
瞭解如何使用 Google Cloud 控制台,在專案層級對主體授予 IAM 角色。
如需快速瞭解如何操作,請觀看以下影片:
如要直接在 Google Cloud 控制台按照逐步指南操作,請按一下「Guide me」(逐步引導):
事前準備
建立 Google Cloud 專案
在這個快速入門導覽課程中,您需要使用新的 Google Cloud 專案。
-
In the Google Cloud console, go to the project selector page.
-
Click Create project.
-
Name your project. Make a note of your generated project ID.
-
Edit the other fields as needed.
-
Click Create.
確認您具備必要角色
-
Make sure that you have the following role or roles on the project: Project IAM 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.
前往 IAM - 選取專案。
- 按一下「授予存取權」 。
-
在「New principals」(新增主體) 欄位中,輸入您的使用者 ID。 這通常是 Google 帳戶的電子郵件地址。
- 在「Select a role」(選取角色) 清單中,選取角色。
- 如要授予其他角色,請按一下 「新增其他角色」,然後新增每個其他角色。
- 按一下 [Save]。
啟用 API
Enable the IAM and Resource Manager APIs.
-
授予 IAM 角色
將專案的記錄檢視者角色授予主體。
前往 Google Cloud 控制台的「IAM」頁面。
選取新專案。
按一下「授予存取權」
。輸入主體的 ID。例如
my-user@example.com
。在「Select a role」(選取角色) 下拉式選單中搜尋「Logs Viewer」(記錄檢視者),然後按一下「Logs Viewer」(記錄檢視者)。
按一下 [儲存]。
確認 IAM 頁面上列出了主體和相應的角色。
您已成功將 IAM 角色授予主體。
觀察 IAM 角色的效果
請按照下列步驟操作,確認您授予角色的主體可以存取預期的Google Cloud 控制台頁面:
將以下網址傳送給在上一個步驟中獲派角色的主體:
https://console.cloud.google.com/logs?project=PROJECT_ID
這個網址會將主體導向至您專案的「Logs Explorer」(記錄檔探索工具) 頁面。
確認主體可以順利存取及查看網址。
如果主體試圖存取不具備存取權的其他 Google Cloud 控制台頁面,系統會顯示錯誤訊息。
為相同的主體授予其他角色
除了記錄檢視者角色外,也授予主體 Compute 檢視者角色。
前往 Google Cloud 控制台的「IAM」頁面。
找出要授予其他角色的主體,然後點選該列中的「Edit principal」(編輯主體)
。在「編輯權限」窗格中,按一下 [新增其他角色]。
在「Select a role」(選取角色) 下拉式選單中搜尋「Compute Viewer」(Compute 檢視者),然後按一下「Compute Viewer」(Compute 檢視者)。然後按一下 [儲存]。
按一下 [儲存]。
這個主體現已具備第二個身分與存取權管理角色。
撤銷 IAM 角色
按照下列步驟,撤銷您在上一個步驟中授予主體的角色:
找出您授予角色的主體,然後點選位於同一列中的「Edit principal」(編輯主體)
。在「編輯權限」窗格中,按一下「記錄檢視者」和「Compute 檢視者」角色旁的刪除圖示。
按一下 [儲存]。
您現在已經撤銷主體的兩個角色。如果該主體試圖查看「Logs Explorer」(記錄檔探索工具) 頁面,系統會顯示下列錯誤訊息:
You don't have permissions to view logs.
清除所用資源
如要避免系統向您的 Google Cloud 帳戶收取本頁所用資源的費用,請按照下列步驟操作。
如要清除所用資源,請刪除您在本快速入門導覽課程中建立的專案。
- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
後續步驟
- 瞭解 IAM 的基本概念。
- 查看所有 IAM 角色的清單。
- 瞭解如何透過 IAM 管理存取權。