Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Manage GCP IAM Members
📖 Scenario: You are setting up access control for a Google Cloud project. You need to manage members such as users, groups, and service accounts by adding them to the project's IAM policy.
🎯 Goal: Build a simple IAM policy configuration that includes specific members with their roles for a Google Cloud project.
📋 What You'll Learn
Create a dictionary called members with exact member emails and their roles
Add a variable called project_id with the exact project ID string
Write a function called build_iam_policy that returns the IAM policy dictionary with bindings
Add the final line that calls build_iam_policy() and assigns it to iam_policy
💡 Why This Matters
🌍 Real World
Managing IAM members and roles is essential for controlling access to cloud resources securely and efficiently.
💼 Career
Cloud engineers and administrators regularly configure IAM policies to enforce security and compliance in cloud environments.
Progress0 / 4 steps
1
Create the initial members dictionary
Create a dictionary called members with these exact entries: 'user:alice@example.com': 'roles/viewer', 'group:devs@example.com': 'roles/editor', and 'serviceAccount:my-service@project.iam.gserviceaccount.com': 'roles/owner'.
GCP
Hint
Use a Python dictionary with member strings as keys and role strings as values.
2
Add the project ID variable
Add a variable called project_id and set it exactly to 'my-gcp-project'.
GCP
Hint
Assign the exact string to project_id.
3
Write the function to build IAM policy
Write a function called build_iam_policy that returns a dictionary with a bindings key. The value should be a list of dictionaries, each with keys role and members. Group members by their roles from the members dictionary.
GCP
Hint
Use a dictionary to group members by role, then build the bindings list.
4
Assign the IAM policy to a variable
Add a line that calls build_iam_policy() and assigns the result to a variable called iam_policy.
GCP
Hint
Call the function and assign its return value to iam_policy.
Practice
(1/5)
1. Which of the following is a correct way to specify a user as a member in GCP IAM?
easy
A. user:alice@example.com
B. serviceaccount:alice@example.com
C. group:alice@example.com
D. member:alice@example.com
Solution
Step 1: Understand member types in GCP IAM
GCP IAM requires a prefix to identify the member type, such as user, group, or serviceaccount.
Step 2: Identify the correct prefix for a user
The prefix for an individual user is user:. So the correct format is user:email.
Final Answer:
user:alice@example.com -> Option A
Quick Check:
User members start with 'user:' [OK]
Hint: User members always start with 'user:' prefix [OK]
Common Mistakes:
Using 'member:' prefix which is invalid
Confusing group and user prefixes
Using serviceaccount prefix for users
2. Which of the following is the correct syntax to specify a service account member in GCP IAM?
easy
A. service-account:my-service@project.iam.gserviceaccount.com
B. serviceaccount:my-service@project.iam.gserviceaccount.com
C. group:my-service@project.iam.gserviceaccount.com
D. user:my-service@project.iam.gserviceaccount.com
Solution
Step 1: Recall the prefix for service accounts
Service accounts use the prefix serviceaccount: followed by the full service account email.
Step 2: Check each option's prefix
Only serviceaccount:my-service@project.iam.gserviceaccount.com uses the correct prefix serviceaccount: without hyphens or mistakes.
Final Answer:
serviceaccount:my-service@project.iam.gserviceaccount.com -> Option B
Quick Check:
Service accounts use 'serviceaccount:' prefix [OK]
Hint: Service accounts use 'serviceaccount:' prefix without hyphens [OK]
Common Mistakes:
Using 'service-account:' with a hyphen
Using 'user:' prefix for service accounts
Using incomplete email addresses
3. Given the following IAM policy binding snippet, which member will have access?