הפעלת האפשרות לאיתור התראות ב-Pub/Sub

בדף הזה מוסבר איך להפעיל התראות של Security Command Center API.

ההתראות שולחות ממצאים ועדכונים על ממצאים לנושא Pub/Sub תוך דקות. ההתראות של Security Command Center API כוללות את כל המידע על הממצאים שמוצג על ידי Security Command Center בGoogle Cloud מסוף.

אפשר לקשר התראות של Security Command Center ב-Pub/Sub ישירות לפעולות של פונקציות Cloud Run. דוגמאות לפונקציות שיכולות לעזור בתגובה, בהעשרה ובתיקון אפשר למצוא במאגר הקוד הפתוח של Security Command Center של פונקציות Cloud Run. המאגר מכיל פתרונות שיעזרו לכם לבצע פעולות אוטומטיות לגבי ממצאי אבטחה.

לחלופין, אפשר לייצא את הממצאים ל-BigQuery או להגדיר ייצוא רציף ל-Pub/Sub במסוף Google Cloud .

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

  1. כדי לקבל את ההרשאות שדרושות להגדרה ולהגדרה של התראות מ-Security Command Center API, צריך לבקש מהאדמין להקצות לכם את תפקידי ה-IAM הבאים:

    להסבר על מתן תפקידים, ראו איך מנהלים את הגישה ברמת הפרויקט, התיקייה והארגון.

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

  2. Enable the Security Command Center API:

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    gcloud services enable securitycenter.googleapis.com

המיקום של נתונים והתראות

אם הגדרתם את מיקום הנתונים ב-Security Command Center, ההגדרות שמגדירות ייצוא רציף ל-Pub/Sub – משאבי notificationConfig – כפופות לבקרה על מיקום הנתונים ומאוחסנות במיקום של Security Command Center.

כדי לייצא ממצאים במיקום של Security Command Center אל Pub/Sub, צריך להגדיר את הייצוא הרציף באותו מיקום של Security Command Center שבו נמצאים הממצאים.

המסננים שמשמשים לייצוא רציף יכולים להכיל נתונים שחלים עליהם אמצעי בקרה על מיקום הנתונים, ולכן חשוב לציין את המיקום הנכון לפני שיוצרים אותם. ב-Security Command Center אין הגבלה על המיקום שבו אפשר ליצור ייצוא.

ייצוא רציף נשמר רק במיקום שבו הוא נוצר, ואי אפשר לראות או לערוך אותו במיקומים אחרים.

אחרי שיוצרים ייצוא רציף, אי אפשר לשנות את המיקום שלו. כדי לשנות את המיקום, צריך למחוק את הייצוא הרציף וליצור אותו מחדש במיקום החדש.

הנחיות לשימוש ב-Security Command Center כשמפעילים את התכונה 'שמירת נתונים באזור מסוים' מופיעות במאמר נקודות קצה אזוריות של Security Command Center.

הגדרה של נושא Pub/Sub

במשימה הזו, אתם יוצרים נושא Pub/Sub ונרשמים אליו כדי לשלוח אליו התראות.

שלב 1: הגדרת Pub/Sub

כדי להגדיר נושא Pub/Sub ולהירשם אליו, מבצעים את הפעולות הבאות:

  1. נכנסים למסוף Google Cloud .

    כניסה ל Google Cloud מסוף

  2. בוחרים את הפרויקט שבו הפעלתם את Security Command Center API.

  3. לוחצים על הפעלת Cloud Shell.

  4. אופציונלי: כדי ליצור נושא חדש ב-Pub/Sub, מריצים את הפקודה הבאה:

    gcloud pubsub topics create TOPIC_ID
    

    מחליפים את TOPIC_ID בשם של נושא.

  5. יוצרים מינוי לנושא:

    gcloud pubsub subscriptions create SUBSCRIPTION_ID --topic=TOPIC_ID
    

    מחליפים את מה שכתוב בשדות הבאים:

    • SUBSCRIPTION_ID: מזהה המינוי
    • TOPIC_ID: מזהה הנושא

מידע נוסף על הגדרת Pub/Sub זמין במאמר ניהול נושאים ומינויים.

שלב 2: הקצאת תפקיד בנושא Pub/Sub

כדי ליצור NotificationConfig, צריך את התפקיד 'אדמין ב-Pub/Sub' (roles/pubsub.admin) בנושא ה-Pub/Sub שעבורו יצרתם מינוי.

כדי להעניק את התפקיד הזה:

  1. נכנסים למסוף Google Cloud .

    כניסה ל Google Cloud מסוף

  2. בוחרים את הפרויקט שעבורו הפעלתם את Security Command Center API.

  3. לוחצים על הפעלת Cloud Shell.

  4. מקצים לחשבון Google את התפקיד הנדרש בנושא Pub/Sub:

    gcloud pubsub topics add-iam-policy-binding \
        projects/PUBSUB_PROJECT/topics/TOPIC_ID \
        --member="user:GOOGLE_ACCOUNT" \
        --role="roles/pubsub.admin"
    

    מחליפים את מה שכתוב בשדות הבאים:

    • PUBSUB_PROJECT: הפרויקט Google Cloud שכולל את נושא ה-Pub/Sub
    • TOPIC_ID: מזהה הנושא
    • GOOGLE_ACCOUNT: כתובת האימייל של חשבון Google שלכם

יצירת NotificationConfig

לפני שיוצרים NotificationConfig, חשוב לדעת שלכל ארגון יכול להיות מספר מוגבל של קובצי NotificationConfig. מידע נוסף זמין במאמר מכסות ומגבלות.

השדה NotificationConfig כולל את השדה filter שמגביל את ההתראות לאירועים שימושיים. בשדה הזה אפשר להזין את כל המסננים שזמינים בשיטה findings.list של Security Command Center API.

כשיוצרים NotificationConfig, מציינים את ההורה של NotificationConfig מתוך היררכיית המשאבים Google Cloud , כלומר ארגון, תיקייה או פרויקט. אם תצטרכו לאחזר, לעדכן או למחוק את NotificationConfig בהמשך, תצטרכו לכלול את המזהה המספרי של ארגון האב, התיקייה או הפרויקט כשמפנים אליו.

במסוף Google Cloud , יכול להיות שלחלק מהמשאבים של NotificationConfig תהיה התווית Legacy, שמציינת שהם נוצרו באמצעות Security Command Center API בגרסה 1. אפשר לנהל את המשאבים האלה NotificationConfig באמצעות מסוף Google Cloud , ה-CLI של gcloud, Security Command Center API בגרסה v1 או ספריות הלקוח של Security Command Center בגרסה v1.

כדי לנהל את המשאבים האלה של NotificationConfig באמצעות ה-CLI של gcloud, אסור לציין מיקום כשמריצים את הפקודה של ה-CLI של gcloud.

כדי ליצור את NotificationConfig באמצעות השפה או הפלטפורמה שתבחרו:

gcloud

gcloud scc notifications create NOTIFICATION_NAME \
  --PARENT=PARENT_ID \
  --location=LOCATION \
  --description="NOTIFICATION_DESCRIPTION" \
  --pubsub-topic=PUBSUB_TOPIC \
  --filter="FILTER"

מחליפים את מה שכתוב בשדות הבאים:

  • NOTIFICATION_NAME: השם של ההתראה. השם צריך להיות באורך של 1 עד 128 תווים, ולהכיל רק תווים אלפאנומריים, קווים תחתונים או מקפים.
  • PARENT: ההיקף בהיררכיית המשאבים שההתראה רלוונטית לגביו, organization,‏ folder או project.
  • PARENT_ID: המזהה של הארגון, התיקייה או הפרויקט ברמת ההורה, שצוין בפורמט organizations/123,‏ folders/456 או projects/789.
  • LOCATION: המיקום של Security Command Center שבו יתבצע ה-; אם מופעלת שמירת נתונים באזור מסוים, צריך להשתמש ב-eu,‏ sa או us; אחרת, צריך להשתמש בערך global.
  • NOTIFICATION_DESCRIPTION: תיאור של ההתראה, באורך של עד 1,024 תווים.
  • PUBSUB_TOPIC: נושא ה-Pub/Sub שיקבל התראות. הפורמט שלו הוא projects/PROJECT_ID/topics/TOPIC.
  • FILTER: הביטוי שאתם מגדירים כדי לבחור אילו ממצאים יישלחו ל-Pub/Sub. לדוגמה, state=\"ACTIVE\".

Terraform

כדי ליצור NotificationConfig לארגון:

resource "google_pubsub_topic" "scc_v2_organization_notification_config" {
  name = "my-topic"
}

resource "google_scc_v2_organization_notification_config" "custom_organization_notification_config" {
  config_id    = "my-config"
  organization = "123456789"
  location     = "global"
  description  = "My custom Cloud Security Command Center Finding Organization Notification Configuration"
  pubsub_topic = google_pubsub_topic.scc_v2_organization_notification_config.id

  streaming_config {
    filter = "category = \"OPEN_FIREWALL\" AND state = \"ACTIVE\""
  }
}

כדי ליצור NotificationConfig לתיקייה:

resource "google_folder" "folder" {
  parent       = "organizations/123456789"
  display_name = "folder-name"
}

resource "google_pubsub_topic" "scc_v2_folder_notification_config" {
  name = "my-topic"
}

resource "google_scc_v2_folder_notification_config" "custom_notification_config" {
  config_id    = "my-config"
  folder       = google_folder.folder.folder_id
  location     = "global"
  description  = "My custom Cloud Security Command Center Finding Notification Configuration"
  pubsub_topic =  google_pubsub_topic.scc_v2_folder_notification_config.id

  streaming_config {
    filter = "category = \"OPEN_FIREWALL\" AND state = \"ACTIVE\""
  }
}

יצירת NotificationConfig לפרויקט:

resource "google_pubsub_topic" "scc_v2_project_notification" {
  name = "my-topic"
}

resource "google_scc_v2_project_notification_config" "custom_notification_config" {
  config_id    = "my-config"
  project      = "my-project-name"
  description  = "My custom Cloud Security Command Center Finding Notification Configuration"
  pubsub_topic =  google_pubsub_topic.scc_v2_project_notification.id

  streaming_config {
    filter = "category = \"OPEN_FIREWALL\" AND state = \"ACTIVE\""
  }
}

Go

import (
	"context"
	"fmt"
	"io"

	securitycenter "cloud.google.com/go/securitycenter/apiv2"
	"cloud.google.com/go/securitycenter/apiv2/securitycenterpb"
)

func createNotificationConfig(w io.Writer, orgID string, pubsubTopic string, notificationConfigID string) error {
	// orgID := "your-org-id"
	// pubsubTopic := "projects/{your-project}/topics/{your-topic}"
	// notificationConfigID := "your-config-id"

	ctx := context.Background()
	client, err := securitycenter.NewClient(ctx)

	if err != nil {
		return fmt.Errorf("securitycenter.NewClient: %w", err)
	}
	defer client.Close()

	req := &securitycenterpb.CreateNotificationConfigRequest{
		// Parent must be in one of the following formats:
		//		"organizations/{orgId}/locations/global"
		//		"projects/{projectId}/locations/global"
		//		"folders/{folderId}/locations/global"
		Parent:   fmt.Sprintf("organizations/%s/locations/global", orgID),
		ConfigId: notificationConfigID,
		NotificationConfig: &securitycenterpb.NotificationConfig{
			Description: "Go sample config",
			PubsubTopic: pubsubTopic,
			NotifyConfig: &securitycenterpb.NotificationConfig_StreamingConfig_{
				StreamingConfig: &securitycenterpb.NotificationConfig_StreamingConfig{
					Filter: `state = "ACTIVE"`,
				},
			},
		},
	}

	notificationConfig, err := client.CreateNotificationConfig(ctx, req)
	if err != nil {
		return fmt.Errorf("Failed to create notification config: %w", err)
	}
	fmt.Fprintln(w, "New NotificationConfig created: ", notificationConfig)

	return nil
}

Java


package vtwo.notifications;

import com.google.cloud.securitycenter.v2.LocationName;
import com.google.cloud.securitycenter.v2.NotificationConfig;
import com.google.cloud.securitycenter.v2.SecurityCenterClient;
import java.io.IOException;

public class CreateNotification {

  public static void main(String[] args) throws IOException {
    // parentId: must be in one of the following formats:
    //    "organizations/{organization_id}"
    //    "projects/{project_id}"
    //    "folders/{folder_id}"
    String parentId = "{parent-id}";
    String topicName = "{your-topic}";
    String notificationConfigId = "{your-notification-id}";
    // Specify the location of the notification config.
    String location = "global";

    createNotificationConfig(parentId, location, topicName, notificationConfigId);
  }

  // Crete a notification config.
  // Ensure the ServiceAccount has the "pubsub.topics.setIamPolicy" permission on the new topic.
  public static NotificationConfig createNotificationConfig(
      String parentId, String location, String topicName, String notificationConfigId)
      throws IOException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the "close" method on the client to safely clean up any remaining background resources.
    try (SecurityCenterClient client = SecurityCenterClient.create()) {

      String pubsubTopic = String.format("projects/%s/topics/%s", parentId, topicName);

      NotificationConfig notificationConfig = NotificationConfig.newBuilder()
          .setDescription("Java notification config")
          .setPubsubTopic(pubsubTopic)
          .setStreamingConfig(
              NotificationConfig.StreamingConfig.newBuilder().setFilter("state = \"ACTIVE\"")
                  .build())
          .build();

      NotificationConfig response = client.createNotificationConfig(
          LocationName.of(parentId, location), notificationConfig, notificationConfigId);

      System.out.printf("Notification config was created: %s%n", response);
      return response;
    }
  }
}

Node.js

// npm install '@google-cloud/security-center'
const {SecurityCenterClient} = require('@google-cloud/security-center').v2;
const uuidv1 = require('uuid').v1;

const client = new SecurityCenterClient();
/*
 *  Required. Resource name of the new notification config's parent. Its format
 *  is "organizations/[organization_id]/locations/[location_id]",
 *  "folders/[folder_id]/locations/[location_id]", or
 *  "projects/[project_id]/locations/[location_id]".
 */
const parent = `projects/${projectId}/locations/${location}`;

/**
 *  Required.
 *  Unique identifier provided by the client within the parent scope.
 *  It must be between 1 and 128 characters and contain alphanumeric
 *  characters, underscores, or hyphens only.
 */
const configId = 'notif-config-test-node-create-' + uuidv1();

// pubsubTopic = "projects/{your-project}/topics/{your-topic}";
const pubsubTopic = `projects/${projectId}/topics/${topicName}`;

/**
 *  Required. The notification config being created. The name and the service
 *  account will be ignored as they are both output only fields on this
 *  resource.
 */
const notificationConfig = {
  description: 'Sample config for node v2',
  pubsubTopic: pubsubTopic,
  streamingConfig: {filter: 'state = "ACTIVE"'},
};

// Build the request.
const createNotificationRequest = {
  parent: parent,
  configId: configId,
  notificationConfig: notificationConfig,
};

async function createNotificationConfig() {
  const [response] = await client.createNotificationConfig(
    createNotificationRequest
  );
  console.log('Notification configuration creation successful: %j', response);
}

await createNotificationConfig();

Python

def create_notification_config(
    parent_id, location_id, pubsub_topic, notification_config_id
) -> NotificationConfig:
    """
    This method is used to create the Notification Config.
    Args:
        parent_id: must be in one of the following formats:
            "organizations/{organization_id}"
            "projects/{project_id}"
            "folders/{folder_id}"
        location_id: "global"
        pubsub_topic: "projects/{your-project-id}/topics/{your-topic-id}"
        notification_config_id: "your-config-id"


    Ensure this ServiceAccount has the "pubsub.topics.setIamPolicy" permission on the new topic.
    """
    from google.cloud import securitycenter_v2 as securitycenter_v2

    client = securitycenter_v2.SecurityCenterClient()
    parent_id = parent_id + "/locations/" + location_id
    response = client.create_notification_config(
        request={
            "parent": parent_id,
            "config_id": notification_config_id,
            "notification_config": {
                "description": "Notification for active findings",
                "pubsub_topic": pubsub_topic,
                "streaming_config": {"filter": 'state = "ACTIVE"'},
            },
        }
    )
    print(f"create notification config response:{response}")
    return response

ההתראות מתפרסמות עכשיו בנושא Pub/Sub שציינתם.

כדי לפרסם התראות, נוצר עבורכם חשבון שירות בפורמט service-org-ORGANIZATION_ID@gcp-sa-scc-notification.iam.gserviceaccount.com. חשבון השירות הזה נוצר כשיוצרים את NotificationConfig הראשון, ומקבל אוטומטית את התפקיד securitycenter.notificationServiceAgent במדיניות IAM עבור PUBSUB_TOPIC כשיוצרים את הגדרת ההתראות. תפקיד חשבון השירות הזה נדרש כדי שההתראות יפעלו.

איך מעניקים גישה להיקף ב-VPC Service Controls

אם אתם משתמשים ב-VPC Service Controls ונושא ה-Pub/Sub שלכם הוא חלק מפרויקט בתוך גבולות גזרה לשירות, אתם צריכים להעניק גישה לפרויקטים כדי ליצור התראות.

כדי להעניק גישה לפרויקטים, צריך ליצור כללים לתעבורת נתונים נכנסת (ingress) ויוצאת (egress) עבור הגורמים המורשים והפרויקטים שמשמשים ליצירת התראות. הכללים מאפשרים גישה למשאבים מוגנים ומאפשרים ל-Pub/Sub לאמת שלמשתמשים יש הרשאה setIamPolicy בנושא Pub/Sub.

לפני שיוצרים NotificationConfig

לפני שמבצעים את השלבים במאמר יצירה של NotificationConfig, צריך לבצע את השלבים הבאים.

המסוף

  1. נכנסים לדף VPC Service Controls במסוף Google Cloud .

    מעבר אל VPC Service Controls

  2. בוחרים את הארגון.
  3. ברשימה הנפתחת, בוחרים את מדיניות הגישה שמכילה את גבולות הגזרה לשירות שרוצים להעניק לו גישה.

    גבולות הגזרה לשירות שמשויכים למדיניות הגישה מופיעים ברשימה.

  4. לוחצים על השם של גבולות הגזרה לשירות שרוצים לעדכן.

    כדי למצוא את גבולות הגזרה לשירות שצריך לשנות, אפשר לבדוק ביומנים ערכים שמציינים RESOURCES_NOT_IN_SAME_SERVICE_PERIMETER הפרות. ברשומות האלה, בודקים את השדה servicePerimeterName:

    accessPolicies/ACCESS_POLICY_ID/servicePerimeters/SERVICE_PERIMETER_NAME
  5. לוחצים על עריכה.
  6. לוחצים על מדיניות יציאה.
  7. לוחצים על הוספת כלל ליציאה.
  8. בקטע מאת, מגדירים את הפרטים הבאים:

    1. בקטע זהויות > זהות, בוחרים באפשרות בחירת זהויות וקבוצות.
    2. לוחצים על הוספת זהויות.
    3. מזינים את כתובת האימייל שמזהה את חשבון המשתמש שמשמש לקריאה ל-API של Security Command Center.
    4. בוחרים את הגורם המורשה או לוחצים על ENTER, ואז לוחצים על הוספת זהויות.
  9. בקטע To (אל), מגדירים את הפרטים הבאים:

    1. בקטע Resources > Projects, בוחרים באפשרות All projects.
    2. בקטע Operations or IAM roles (פעולות או תפקידי IAM), בוחרים באפשרות Select operations (בחירת פעולות).
    3. לוחצים על הוספת פעולות ומוסיפים את הפעולות הבאות:

      • מוסיפים את השירות pubsub.googleapis.com.
        1. לוחצים על כל השיטות.
        2. לוחצים על הוספת כל האמצעים.
  10. לוחצים על Ingress policy (מדיניות כניסה).
  11. לוחצים על הוספת כלל תעבורה נכנסת.
  12. בקטע מאת, מגדירים את הפרטים הבאים:

    1. בקטע זהויות > זהות, בוחרים באפשרות בחירת זהויות וקבוצות.
    2. לוחצים על הוספת זהויות.
    3. מזינים את כתובת האימייל שמזהה את חשבון המשתמש שמשמש לקריאה ל-API של Security Command Center.
    4. בוחרים את הגורם המורשה או לוחצים על ENTER, ואז לוחצים על הוספת זהויות.
  13. בקטע To (אל), מגדירים את הפרטים הבאים:

    1. בקטע Resources > Projects (משאבים > פרויקטים), בוחרים באפשרות Select projects (בחירת פרויקטים).
    2. לוחצים על Add projects ומוסיפים את הפרויקט שמכיל את נושא ה-Pub/Sub.
    3. בקטע Operations or IAM roles (פעולות או תפקידי IAM), בוחרים באפשרות Select operations (בחירת פעולות).
    4. לוחצים על הוספת פעולות ומוסיפים את הפעולות הבאות:

      • מוסיפים את השירות pubsub.googleapis.com.
        1. לוחצים על כל השיטות.
        2. לוחצים על הוספת כל האמצעים.
  14. לוחצים על Save.

gcloud

  1. אם עדיין לא הגדרתם פרויקט מכסת מכסות, תצטרכו להגדיר אותו. בוחרים פרויקט שבו מופעל Access Context Manager API.

    gcloud config set billing/quota_project QUOTA_PROJECT_ID

    מחליפים את QUOTA_PROJECT_ID במזהה הפרויקט שבו רוצים להשתמש לחיוב ולמכסה.

  2. יוצרים קובץ בשם egress-rule.yaml עם התוכן הבא:

    - egressFrom:
        identities:
        - PRINCIPAL_ID
      egressTo:
        operations:
        - serviceName: pubsub.googleapis.com
          methodSelectors:
          - method: '*'
        resources:
        - '*'

    מחליפים את PRINCIPAL_ID במזהה של החשבון הראשי שמשמש לקריאה ל-Security Command Center API.

  3. יוצרים קובץ בשם ingress-rule.yaml עם התוכן הבא:

    - ingressFrom:
        identities:
        - PRINCIPAL_ID
        sources:
        - accessLevel: '*'
      ingressTo:
        operations:
        - serviceName: pubsub.googleapis.com
          methodSelectors:
          - method: '*'
        resources:
        - '*'

    מחליפים את PRINCIPAL_ID במזהה של החשבון הראשי שמשמש לקריאה ל-Security Command Center API.

  4. מוסיפים את כלל היציאה להיקף:

    gcloud access-context-manager perimeters update PERIMETER_NAME \
        --set-egress-policies=egress-rule.yaml

    מחליפים את מה שכתוב בשדות הבאים:

    • PERIMETER_NAME: שם ההיקף. לדוגמה: accessPolicies/1234567890/servicePerimeters/example_perimeter.

      כדי למצוא את גבולות הגזרה לשירות שרוצים לשנות, אפשר לבדוק ביומנים אם יש רשומות שבהן מופיע RESOURCES_NOT_IN_SAME_SERVICE_PERIMETER הפרה. ברשומות האלה, בודקים את השדה servicePerimeterName:

      accessPolicies/ACCESS_POLICY_ID/servicePerimeters/SERVICE_PERIMETER_NAME
  5. מוסיפים את כלל הכניסה להיקף:

    gcloud access-context-manager perimeters update PERIMETER_NAME \
        --set-ingress-policies=ingress-rule.yaml

    מחליפים את מה שכתוב בשדות הבאים:

    • PERIMETER_NAME: שם ההיקף. לדוגמה: accessPolicies/1234567890/servicePerimeters/example_perimeter.

      כדי למצוא את גבולות הגזרה לשירות שרוצים לשנות, אפשר לבדוק ביומנים אם יש רשומות שבהן מופיע RESOURCES_NOT_IN_SAME_SERVICE_PERIMETER הפרה. ברשומות האלה, בודקים את השדה servicePerimeterName:

      accessPolicies/ACCESS_POLICY_ID/servicePerimeters/SERVICE_PERIMETER_NAME

מידע נוסף זמין במאמר בנושא כללי כניסה ויציאה.

יצירת כלל כניסה ל-NotificationConfig

כדי ליצור כלל תעבורת נתונים נכנסת (ingress) ל-NotificationConfig, פועלים לפי ההוראות שבמאמר יצירת NotificationConfig, ואז מבצעים את השלבים הבאים.

המסוף

  1. פותחים מחדש את גבולות הגזרה לשירות מהקטע הקודם.

    מעבר אל VPC Service Controls

  2. לוחצים על Ingress policy (מדיניות כניסה).
  3. לוחצים על הוספת כלל תעבורה נכנסת.
  4. בקטע מאת, מגדירים את הפרטים הבאים:

    1. בקטע זהויות > זהות, בוחרים באפשרות בחירת זהויות וקבוצות.
    2. לוחצים על הוספת זהויות.
    3. מזינים את כתובת האימייל שמזהה את סוכן השירות של NotificationConfig. הכתובת הזו היא בפורמט הבא:

      service-org-ORGANIZATION_ID@gcp-sa-scc-notification.iam.gserviceaccount.com

      מחליפים את ORGANIZATION_ID במזהה הארגון.

    4. בוחרים את סוכן השירות או לוחצים על ENTER, ואז לוחצים על הוספת זהויות.
  5. בקטע To (אל), מגדירים את הפרטים הבאים:

    1. בקטע Resources > Projects (משאבים > פרויקטים), בוחרים באפשרות Select projects (בחירת פרויקטים).
    2. לוחצים על Add projects ומוסיפים את הפרויקט שמכיל את נושא ה-Pub/Sub.
    3. בקטע Operations or IAM roles (פעולות או תפקידי IAM), בוחרים באפשרות Select operations (בחירת פעולות).
    4. לוחצים על הוספת פעולות ומוסיפים את הפעולות הבאות:

      • מוסיפים את השירות pubsub.googleapis.com.
        1. לוחצים על כל השיטות.
        2. לוחצים על הוספת כל האמצעים.
  6. לוחצים על Save.

gcloud

  1. אם עדיין לא הגדרתם פרויקט מכסת מכסות, תצטרכו להגדיר אותו. בוחרים פרויקט שבו מופעל Access Context Manager API.

    gcloud config set billing/quota_project QUOTA_PROJECT_ID

    מחליפים את QUOTA_PROJECT_ID במזהה הפרויקט שבו רוצים להשתמש לחיוב ולמכסה.

  2. יוצרים קובץ בשם ingress-rule.yaml עם התוכן הבא:

    - ingressFrom:
        identities:
        - serviceAccount:service-org-ORGANIZATION_ID@gcp-sa-scc-notification.iam.gserviceaccount.com
        sources:
        - accessLevel: '*'
      ingressTo:
        operations:
        - serviceName: pubsub.googleapis.com
          methodSelectors:
          - method: '*'
        resources:
        - '*'

    מחליפים את ORGANIZATION_ID במזהה הארגון.

  3. מוסיפים את כלל הכניסה להיקף:

    gcloud access-context-manager perimeters update PERIMETER_NAME \
        --set-ingress-policies=ingress-rule.yaml

    מחליפים את מה שכתוב בשדות הבאים:

    • PERIMETER_NAME: שם ההיקף. לדוגמה: accessPolicies/1234567890/servicePerimeters/example_perimeter.

      כדי למצוא את גבולות הגזרה לשירות שרוצים לשנות, אפשר לבדוק ביומנים אם יש רשומות שבהן מופיע RESOURCES_NOT_IN_SAME_SERVICE_PERIMETER הפרה. ברשומות האלה, בודקים את השדה servicePerimeterName:

      accessPolicies/ACCESS_POLICY_ID/servicePerimeters/SERVICE_PERIMETER_NAME

מידע נוסף זמין במאמר בנושא כללי כניסה ויציאה.

עכשיו הפרויקטים, המשתמשים וחשבונות השירות שנבחרו יכולים לגשת למשאבים המוגנים וליצור התראות.

אם פעלתם לפי כל השלבים במדריך הזה וההתראות פועלות בצורה תקינה, אתם יכולים למחוק את הפריטים הבאים:

  • כלל הכניסה (ingress) עבור החשבון הראשי
  • כלל היציאה (egress) של החשבון הראשי

הכללים האלה נדרשו רק כדי להגדיר את NotificationConfig. עם זאת, כדי שההתראות ימשיכו לפעול, צריך להשאיר את כלל הכניסה עבור NotificationConfig, שמאפשר לו לפרסם התראות בנושא Pub/Sub מאחורי גבולות גזרה לשירות.

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