Privileged Access with IAM

Solution for Privileged Access with IAM. 1 lab: GSP526. Fast copy-paste commands for Google Cloud.

GSP526 — Privileged Access with IAM: Challenge Lab

Estimated time: 30 minutes

> ⚠️ **Disclaimer:** This guide is provided for educational purposes only to help you learn Google Cloud concepts. Please ensure you follow **Google Cloud Skills Boost (Qwiklabs)** Terms of Service and **YouTube Community Guidelines**. > > **Credits:** DM for credit or removal request (no copyright intended). > © All rights and credits for the original content belong to **Google Cloud**. 🙏 This Challenge Lab focuses on **Privileged Access Manager (PAM)** and requires working with **two diff

clear
CYAN='\e[1;36m'
BLUE='\e[1;34m'
RESET='\e[0m'
BOLD='\e[1m'
echo -e "${CYAN}${BOLD}"
cat << "EOF"
  ____        _     _ _             __    ___            
 / __ \      | |   (_) |           / _|  / _ \           
| |  | |_ __| |__  _| |_   ___  | |_  | | | |_ __  ___ 
| |  | | '__| '_ \| | __| / _ \ |  _| | | | | '_ \/ __|
| |__| | |  | |_) | | |_ | (_) || |   | |_| | |_) \__ \
 \____/|_|  |_.__/|_|\__| \___/ |_|    \___/| .__/|___/
                                            | |        
                                            |_|        
EOF
echo -e "${RESET}"
echo -e "${BLUE}${BOLD}╔════════════════════════════════════════════════════════════╗${RESET}"
echo -e "${BLUE}${BOLD}║   🚀 BROUGHT TO YOU BY ORBIT OF OPS                        ║${RESET}"
echo -e "${BLUE}${BOLD}╚════════════════════════════════════════════════════════════╝${RESET}\n"

export PROJECT_ID=$(gcloud config get-value project)

echo "Enabling Privileged Access Manager API..."
gcloud services enable privilegedaccessmanager.googleapis.com

echo "Assigning IAM Role to the PAM Service Agent..."
PROJECT_NUMBER=$(gcloud projects describe $PROJECT_ID --format="value(projectNumber)")
PAM_SA="service-${PROJECT_NUMBER}@gcp-sa-pam.iam.gserviceaccount.com"

gcloud projects add-iam-policy-binding $PROJECT_ID \
    --member="serviceAccount:${PAM_SA}" \
    --role="roles/privilegedaccessmanager.serviceAgent"

# Subscribe to Orbit of Ops https://www.youtube.com/@orbitofops

MAGENTA='\e[1;35m'
echo -e "\n${MAGENTA}${BOLD}╔════════════════════════════════════════════════════════════╗${RESET}"
echo -e "${MAGENTA}${BOLD}║            🎉 AUTOMATION COMPLETED SUCCESSFULLY 🎉           ║${RESET}"
echo -e "${MAGENTA}${BOLD}╚════════════════════════════════════════════════════════════╝${RESET}"

# Subscribe to Orbit of Ops https://www.youtube.com/@orbitofops/videos