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
Creating and Assigning GCP Roles: Basic, Predefined, and Custom
📖 Scenario: You are managing access control in a Google Cloud Platform (GCP) project. You want to understand how to create and assign different types of roles: basic roles, predefined roles, and custom roles.This project will guide you step-by-step to create a custom role, assign a basic role, and assign a predefined role to a user in your GCP project.
🎯 Goal: Build a simple GCP IAM configuration that includes:A variable holding the project ID.A variable holding the user email to assign roles.A custom role definition with specific permissions.Assignments of a basic role, a predefined role, and the custom role to the user.
📋 What You'll Learn
Create a variable called project_id with the exact value "my-gcp-project".
Create a variable called user_email with the exact value "user@example.com".
Define a custom role called customRole with the title "Custom Viewer" and the permission "storage.buckets.get".
Assign the basic role roles/viewer to the user.
Assign the predefined role roles/storage.objectViewer to the user.
Assign the custom role customRole to the user.
💡 Why This Matters
🌍 Real World
Managing access control in GCP projects is essential for security and proper resource management. This project simulates how to define and assign roles to users.
💼 Career
Cloud engineers and administrators often create and assign roles to control who can do what in cloud environments. Understanding roles is key to secure cloud infrastructure.
Progress0 / 4 steps
1
Set up project and user variables
Create a variable called project_id and set it to "my-gcp-project". Also create a variable called user_email and set it to "user@example.com".
GCP
Hint
Use simple variable assignments with exact string values.
2
Define a custom role
Define a dictionary called customRole with keys title set to "Custom Viewer" and permissions set to a list containing "storage.buckets.get".
GCP
Hint
Use a dictionary with exact keys and values as specified.
3
Assign basic and predefined roles to the user
Create a list called role_assignments containing three dictionaries. The first dictionary assigns the basic role roles/viewer to user_email. The second dictionary assigns the predefined role roles/storage.objectViewer to user_email. The third dictionary will be added in the next step.
GCP
Hint
Use a list of dictionaries with exact keys role and member. Use f-strings for member values.
4
Add custom role assignment to the user
Add a third dictionary to the role_assignments list that assigns the custom role customRole to user_email. Use the role name "projects/my-gcp-project/roles/customRole" exactly.
GCP
Hint
Append the custom role assignment dictionary exactly as shown.
Practice
(1/5)
1. Which type of Google Cloud role provides broad access across all services with simple permissions like Owner, Editor, and Viewer?
easy
A. Predefined roles
B. Basic roles
C. Custom roles
D. Service accounts
Solution
Step 1: Understand role categories
Google Cloud has three main role types: basic, predefined, and custom.
Step 2: Identify broad access roles
Basic roles like Owner, Editor, and Viewer provide broad access across all services.
Final Answer:
Basic roles -> Option B
Quick Check:
Broad access = Basic roles [OK]
Hint: Basic roles cover broad access across all services [OK]
Common Mistakes:
Confusing predefined roles with basic roles
Thinking custom roles are broad by default
Mixing service accounts with roles
2. Which of the following is the correct way to create a custom role in Google Cloud IAM?
easy
A. Use the gcloud CLI with 'gcloud iam roles create' and specify permissions
B. Assign a predefined role to a user
C. Use the Google Cloud Console to assign a basic role
D. Create a service account with custom permissions
Solution
Step 1: Identify how to create custom roles
Custom roles require specifying exact permissions and are created via CLI or console.
Step 2: Match correct command
The 'gcloud iam roles create' command is used to create custom roles with specific permissions.
Final Answer:
Use the gcloud CLI with 'gcloud iam roles create' and specify permissions -> Option A
Quick Check:
Create custom role = gcloud iam roles create [OK]
Hint: Custom roles need explicit creation with permissions via CLI [OK]
Common Mistakes:
Confusing assigning roles with creating roles
Using service accounts to create roles
Assigning basic roles instead of creating custom ones