הפעלת אישור גישה באמצעות Terraform

Terraform הוא כלי תוכנה בקוד פתוח מסוג תשתית כקוד (IaC), שמאפשר לכם לנהל את בקשות אישור הגישה. באמצעות Terraform אפשר לבצע את כל הפעולות שאפשר לבצע באמצעות ממשקי ה-API של אישור הגישה.

בדף הזה מוסבר איך להפעיל את אישור הגישה באמצעות Terraform. במדריך הזה נעשה שימוש ב-Google Cloud Terraform Provider.

מטרה

במדריך הזה מוסבר איך ליצור קובץ תצורה של Terraform ש:

  • הגדרת כתובות אימייל לקבלת התראות על בקשות לאישורי גישה.
  • הפעלת אישור גישה לכל המוצרים הנתמכים. Google Cloud כאן אפשר לעיין ברשימה המלאה של מוצרים שנתמכים על ידי אישור גישה. Google Cloud

לפני שמתחילים

  • כדי להשתמש ב-Access Approval וב-Access Transparency, הארגון שלכם צריך לעמוד בדרישות תמיכה ספציפיות. מידע נוסף זמין במאמר בנושא הדרישות לשימוש באישור גישה.
  • מפעילים את Access Transparency בארגון. מידע נוסף זמין במאמר בנושא הפעלת Access Transparency.
  • מוודאים שיש לכם את התפקיד עורך הגדרות של אישור גישה (roles/accessapproval.configEditor) בניהול הזהויות והרשאות הגישה (IAM). מידע נוסף על תפקידי IAM לאישור גישה זמין במאמר תפקידים לאישור גישה.

יצירת Google Cloud פרויקט

  1. נכנסים לחשבון Google Cloud . אם אתם משתמשים חדשים ב- Google Cloud, צרו חשבון כדי שתוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Enable the Access Approval API.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the API

  4. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  5. Enable the Access Approval API.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the API

התקנת Google Cloud CLI

התקינו את ה-CLI של Google Cloud. אחר כך, אתחלו את ה-CLI של Google Cloud באמצעות הפקודה הבאה:

gcloud init

אם אתם משתמשים בספק זהויות חיצוני (IdP), קודם אתם צריכים להיכנס ל-CLI של gcloud באמצעות המאגר המאוחד לניהול זהויות.

כשמתבקשים, בוחרים את הפרויקט שבחרתם או שיצרתם קודם.

אם כבר התקנתם את Google Cloud CLI, אתם יכולים לעדכן אותו באמצעות הפקודה הבאה:

gcloud components update

יצירת קובץ תצורה של Terraform

  1. פותחים את Cloud Shell כדי להפעיל סשן עצמאי של Cloud Shell.
  2. פותחים סביבת עבודה.
  3. יוצרים תיקייה חדשה.
  4. מוסיפים לתיקייה הזו קובץ תצורה של Terraform בשם main.tf.
  5. מעתיקים את המשאב הבא ומדביקים אותו בקובץ main.tf.

    main.tf

    variable "parent_value" {
    type        = string
    }
    
    variable "email_1" {
    type        = string
    }
    
    variable "email_2" {
    type        = string
    }
    
    resource "google_folder" "my_folder" {
    display_name = "my-folder"
    parent       = var.parent_value
    # parent = "organizations/123456789"
    }
    
    resource "google_folder_access_approval_settings" "folder_access_approval" {
    folder_id           = google_folder.my_folder.folder_id
    notification_emails = [var.email_1, var.email_2]
    
    enrolled_services {
      cloud_product = "all"
      }
    }
    

    מזינים ערכים למשתנים הבאים:

    • email_1 ו-email_2: מזינים את כתובות האימייל של המשתמשים שרוצים להגדיר כבודקים של בקשות הגישה לפרויקט הזה.

הרצת קובץ התצורה של Terraform

מריצים את הפקודות הבאות ב-Cloud Shell.

  1. מפעילים את Terraform בספרייה.

    terraform init
    
  2. מריצים את קובץ התצורה של Terraform שנוצר.

    terraform apply
    
  3. כשמופיעה בקשה לאישור שרוצים להפעיל את קובץ ההגדרות, מזינים yes.

מידע נוסף על הפעלת אישור גישה באמצעות Terraform זמין במסמך Terraform הבא: google_folder_access_approval_settings.

המאמרים הבאים