קביעת הגדרות אבטחה מינימליות

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

להגדרות של רמת המודעות יש שתי מטרות עיקריות:

  • תאימות לתבנית: מוודאים שהתבניות החדשות מגבילות לפחות כמו התבניות שמוגדרות בהגדרות המינימום. התאמה לתבנית מוגדרת ברמת הארגון והתיקייה.

  • אכיפה מוטמעת: החלת אמצעי ההגנה של Model Armor על מודלים של Gemini ועל שרתי Google Cloud MCP. האכיפה המוטמעת מוגדרת ברמת הפרויקט. אם משתמשים בהגדרות אבטחה מינימליות לאכיפה מוטמעת, כל תבנית שיוצרים בפרויקט חייבת להתאים להגדרות אלה של אבטחה מינימלית.

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

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

קבלת ההרשאות הנדרשות

כדי לקבל את ההרשאות שנדרשות לניהול הגדרות הרצפה, צריך לבקש מהאדמין להקצות לכם את תפקיד ה-IAM‏ Model Armor Floor Setting Admin (roles/modelarmor.floorSettingsAdmin) בהגדרות הרצפה של Model Armor. כדי לקרוא הסבר על מתן תפקידים, ראו איך מנהלים את הגישה ברמת הפרויקט, התיקייה והארגון.

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

הפעלת ממשקי ה-API

כדי להשתמש בהגנה מוגברת על המודל, צריך להפעיל את Model Armor API.

המסוף

  1. מפעילים את הגנה מוגברת על המודל API.

    תפקידים שנדרשים להפעלת ממשקי API

    כדי להפעיל ממשקי API, צריך את תפקיד ה-IAM 'אדמין של Service Usage' (roles/serviceusage.serviceUsageAdmin), שכולל את ההרשאה serviceusage.services.enable. איך מקצים תפקידים

    להפעלת ה-API

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

gcloud

לפני שמתחילים, צריך לבצע את השלבים הבאים באמצעות Google Cloud CLI עם Model Armor API:

  1. במסוף Google Cloud , מפעילים את Cloud Shell.

    הפעלת Cloud Shell

    בחלק התחתון של Google Cloud המסוף יתחיל סשן של Cloud Shell ותופיע הודעה של שורת הפקודה. Cloud Shell היא סביבת מעטפת שבה ה-CLI של Google Cloud מותקן ומוגדרים ערכים לפרויקט הקיים. הסשן יופעל תוך כמה שניות.

  2. הגדרת שינוי מברירת המחדל של נקודת קצה ל-API באמצעות ה-CLI של gcloud

הגדרת שינוי מברירת המחדל של נקודת קצה ל-API באמצעות ה-CLI של gcloud

השלב הזה נדרש רק אם משתמשים ב-CLI של gcloud כדי להפעיל את Model Armor API. כדי לוודא שה-CLI של gcloud מנתב את הבקשות לשירות Model Armor בצורה נכונה, צריך להגדיר ידנית את החלפת נקודת הקצה של ה-API.

מריצים את הפקודה הבאה כדי להשתמש בנקודת קצה ל-API הגלובלית:

gcloud config set api_endpoint_overrides/modelarmor "https://modelarmor.googleapis.com/"

הגדרות אבטחה מינימליות

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

בטבלה הבאה מפורטות הגדרות אבטחה מינימליות ברמות השונות:

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

כדי להמחיש איך הגדרות אבטחה מינימליות מוחלים כשהן מוגדרות ברמות שונות, הנה תרחיש לדוגמה. לדוגמה, נניח שהגדרתם את הגדרות אבטחה מינימליות באופן הבא:

  • הגדרות אבטחה מינימליות ברמת התיקייה (פחות ספציפיות): בכל התוכן בתיקייה הזו צריך להפעיל מסנן של כתובות URI זדוניות.
  • הגדרות רמת המינימום (יותר ספציפיות) ברמת הפרויקט: בפרויקט בתיקייה צריך להשתמש בהחדרת הנחיות ובזיהוי פריצה עם רמת מהימנות בינונית.

במקרה כזה, ההגדרות יגרמו לתוצאות הבאות:

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

  • תבנית שנוצרה בפרויקט או בתיקייה אחרים לא מושפעת מכלל הסינון של כתובות URI זדוניות מהתיקייה הראשונה.

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

תאימות של תבניות והגדרות אבטחה מינימליות

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

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

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

המחאה הגדרות אבטחה מינימליות תבניות
תאימות לתבנית ההגדרה מתבצעת ברמת הארגון, התיקייה או הפרויקט.

הערה: אפשר להגדיר את Sensitive Data Protection כך שתאכוף מדיניות אבטחת מידע בתבניות. עם זאת, הוא לא מאמת את התאימות של התבנית.

מוגדר רק ברמת הפרויקט.
בדיקת נתונים האכיפה מתבצעת רק ברמת הפרויקט באמצעות מצב הבדיקה והחסימה. האכיפה מתבצעת באמצעות API בארכיטקטורת REST, Service Extensions, Gemini Enterprise ו-Agent Runtime.

אינטגרציה עם Gemini Enterprise Agent Platform ועם שרתי Google Cloud MCP

‫Model Armor משתלב עם Agent Platform ועם שרתי MCP של Google Cloud כדי לסנן בקשות ותשובות ממודלים של Gemini ומשרתי MCP מרוחקים על סמך הגדרות הרשאות הגישה שאתם מגדירים.Google Cloud כדי לראות את ההנחיות והתשובות, צריך להפעיל את Cloud Logging. מידע נוסף זמין במאמרים שילוב של Model Armor עם Gemini Enterprise Agent Platform ושילוב של Model Armor עם שרתי Google Cloud MCP.

קביעת הגדרות אבטחה מינימליות

הגדרת רמות הרגישות לזיהוי כדי להגדיר את ספי הזיהוי המינימליים עבור תבניות של Model Armor. ההגדרות האלה מבטיחות שכל התבניות החדשות והמשופרות יעמדו בדרישות ספציפיות.

כדי להגדיר את הגדרות אבטחה מינימליות:

  1. נכנסים לדף הגנה מוגברת על המודל במסוף Google Cloud .

    מעבר אל הגנה מוגברת על המודל

  2. בוחרים פרויקט.
  3. בדף Model Armor, עוברים לכרטיסייה Floor settings ולוחצים על Configure floor settings.
  4. בדף הגדרות אבטחה מינימליות, בוחרים את אפשרות ההגדרה.
  5. בקטע Detections (זיהויים), מגדירים את הגדרות הזיהוי.
  6. אופציונלי: אם בוחרים באפשרות Sensitive Data Protection detection, מגדירים את Sensitive Data Protection settings.
  7. בקטע אתיקה של בינה מלאכותית, מגדירים את רמת הסמך לכל מסנן תוכן.

  8. בקטע שירותים, בוחרים את השירותים שבהם יחולו הגדרות אבטחה מינימליות אלה.

  9. בקטע Logs, בוחרים באפשרות Enable Cloud Logging כדי לרשום ביומן את כל ההנחיות של המשתמשים, את התשובות של המודל ואת התוצאות של גלאי הגדרות אבטחה מינימליות.

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

  11. לוחצים על שמירת הגדרות אבטחה מינימליות.

יש להמתין כמה דקות עד שהשינויים בהגדרות אבטחה מינימליות ייכנסו לתוקף.

הגדרת אופן ההורשה של הגדרות אבטחה מינימליות

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

  • העברה בירושה של הגדרות אבטחה מינימליות של ההורה: העברה בירושה של הגדרות אבטחה מינימליות שהוגדרו קודם לכן בהיררכיית המשאבים. לוחצים על שמירת הגדרות אבטחה מינימליות ומדלגים על השלבים הבאים. כדי לראות את ההגדרות שהועברו בירושה, עוברים לכרטיסייה הגדרות אבטחה מינימליות.

  • Custom (מותאם אישית): הגדרת הגדרות אבטחה מינימליות לפרויקט הזה. הגדרות מותאמות אישית שאתם מגדירים לפרויקט מבטלות את הגדרות אבטחה מינימליות שמוגדרות כברירת מחדל.

  • השבתה: השבתה של כל הגדרות אבטחה מינימליות שמועברות בירושה. המשמעות היא שכללי זיהוי לא חלים על תבניות הגנה מוגברת על המודל ועל Agent Platform עבור עומסי העבודה של Gemini. לוחצים על Save floor settings ומדלגים על שאר השלבים. סטטוס ההשבתה מוצג בכרטיסייה הגדרות אבטחה מינימליות.

הגדרת המקומות שבהם יחולו הגדרות אבטחה מינימליות

בוחרים אחד מהשירותים הבאים שבהם יחולו הגדרות אבטחה מינימליות שהוגדרו.

  • הגנה מוגברת על המודל – יצירה ועדכון של תבניות: הגנה מוגברת על המודל בודק כל תבנית חדשה או שעברה שינוי של הגנה מוגברת על המודל בפרויקט, כדי לוודא שההגדרות המינימליות תואמות להגדרות אבטחה מינימליות.

  • שרת MCP של Google: בקשות לבדיקת הגדרות מחיר מינימום שנשלחות אל שרתי MCP של Google או שרתי MCP מרוחקים או מהם, כדי לוודא שהן עומדות בספי מחיר המינימום. Google Cloud למידע נוסף, קראו את המאמר שילוב של הגנה מוגברת על המודל עם שרתי Google Cloud MCP (גרסת טרום-השקה (Preview)).

  • Agent Platform: מסנן בקשות שנשלחות למודלים של Gemini, ואז מתעד או חוסם בקשות שעומדות בסף הגדרות אבטחה מינימליות.

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

    • בדיקה בלבד: זיהוי בקשות שלא עומדות בהגדרות אבטחה מינימליות, אבל לא חסימה שלהן.
    • בדיקה וחסימה של הפרות: זיהוי וחסימה של בקשות שלא עומדות בהגדרות אבטחה מינימליות.

הצגת הגדרות הרצפה של Model Armor

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

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

המסוף

  1. נכנסים לדף הגנה מוגברת על המודל במסוף Google Cloud .

    מעבר אל הגנה מוגברת על המודל

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

  3. בדף Model Armor, עוברים לכרטיסייה Floor settings. אם הגדרות הרצפה מוגדרות ברמת הארגון, תוכלו לראות אותן. אם לא מוגדרות הגדרות אבטחה מינימליות, צריך להגדיר אותן. מידע נוסף זמין במאמר הגדרת רצפה.

gcloud

  • צפייה בהגדרת הרף של הגנה מוגברת על המודל בפרויקט.

      gcloud model-armor floorsettings describe \
          --full-uri='projects/PROJECT_ID/locations/global/floorSetting'
  • צפייה בהגדרת הרצפה של הגנה מוגברת על המודל בארגון.

      gcloud model-armor floorsettings describe \
          --full-uri='organizations/ORGANIZATION_ID/locations/global/floorSetting'
  • צפייה בהגדרת הרף של הגנה מוגברת על המודל בתיקייה.

       gcloud model-armor floorsettings describe \
           --full-uri='folders/FOLDER_ID/locations/global/floorSetting'

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

    • מזהה הפרויקט של הגדרות אבטחה מינימליות.
    • המזהה של התיקייה להגדרות אבטחה מינימליות.
    • המזהה של הארגון להגדרות אבטחה מינימליות.

REST

  • צפייה בהגדרת הרף של הגנה מוגברת על המודל בפרויקט.

    curl -X GET \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      -H "Content-Type: application/json" \
      "https://modelarmor.googleapis.com/v1/projects/PROJECT_ID/locations/global/floorSetting"
  • צפייה בהגדרת הרף של הגנה מוגברת על המודל בתיקייה.

    curl -X GET \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      -H "Content-Type: application/json" \
      "https://modelarmor.googleapis.com/v1/folders/FOLDER_ID/locations/global/floorSetting"
  • צפייה בהגדרת הרצפה של הגנה מוגברת על המודל בארגון.

    curl -X GET \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      -H "Content-Type: application/json" \
      "https://modelarmor.googleapis.com/v1/organizations/ORGANIZATION_ID/locations/global/floorSetting"

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

  • מזהה הפרויקט של הגדרות אבטחה מינימליות.
  • המזהה של התיקייה להגדרות אבטחה מינימליות.
  • המזהה של הארגון להגדרות אבטחה מינימליות.

C#‎

כדי להריץ את הקוד הזה, קודם צריך להגדיר סביבת פיתוח בשפת C# ‎ ולהתקין את Model Armor C# SDK.

המשך

כדי להריץ את הקוד הזה, קודם צריך להגדיר סביבת פיתוח של Go ולהתקין את Model Armor Go SDK.

  • הצגת הגדרת הגנה מוגברת על המודל בפרויקט נתון.

    
    import (
    	"context"
    	"fmt"
    	"io"
    
    	modelarmor "cloud.google.com/go/modelarmor/apiv1"
    	modelarmorpb "cloud.google.com/go/modelarmor/apiv1/modelarmorpb"
    )
    
    // getProjectFloorSettings gets details of a single floor setting of a project.
    //
    // This method retrieves the details of a single floor setting of a project.
    //
    // w io.Writer: The writer to use for logging.
    // projectID string: The ID of the project.
    func getProjectFloorSettings(w io.Writer, projectID string) error {
    	ctx := context.Background()
    
    	// Create the Model Armor client.
    	client, err := modelarmor.NewClient(ctx)
    	if err != nil {
    		return fmt.Errorf("failed to create client: %w", err)
    	}
    	defer client.Close()
    
    	floorSettingsName := fmt.Sprintf("projects/%s/locations/global/floorSetting", projectID)
    
    	// Get the project floor setting.
    	req := &modelarmorpb.GetFloorSettingRequest{
    		Name: floorSettingsName,
    	}
    
    	response, err := client.GetFloorSetting(ctx, req)
    	if err != nil {
    		return fmt.Errorf("failed to get floor setting: %w", err)
    	}
    
    	// Print the retrieved floor setting using fmt.Fprintf with the io.Writer.
    	fmt.Fprintf(w, "Retrieved floor setting: %v\n", response)
    
    	return nil
    }
    
  • בודקים את הגדרת הרף של הגנה מוגברת על המודל בתיקייה מסוימת.

    
    import (
    	"context"
    	"fmt"
    	"io"
    
    	modelarmor "cloud.google.com/go/modelarmor/apiv1"
    	modelarmorpb "cloud.google.com/go/modelarmor/apiv1/modelarmorpb"
    )
    
    // getFolderFloorSettings gets details of a single floor setting of a folder.
    //
    // This method retrieves the details of a single floor setting of a folder.
    //
    // w io.Writer: The writer to use for logging.
    // folderID string: The ID of the folder.
    func getFolderFloorSettings(w io.Writer, folderID string) error {
    	ctx := context.Background()
    
    	// Create the Model Armor client.
    	client, err := modelarmor.NewClient(ctx)
    	if err != nil {
    		return fmt.Errorf("failed to create client: %w", err)
    	}
    	defer client.Close()
    
    	// Prepare folder floor setting path/name
    	floorSettingsName := fmt.Sprintf("folders/%s/locations/global/floorSetting", folderID)
    
    	// Get the folder floor setting.
    	req := &modelarmorpb.GetFloorSettingRequest{
    		Name: floorSettingsName,
    	}
    
    	response, err := client.GetFloorSetting(ctx, req)
    	if err != nil {
    		return fmt.Errorf("failed to get floor setting: %w", err)
    	}
    
    	// Print the retrieved floor setting using fmt.Fprintf with the io.Writer.
    	fmt.Fprintf(w, "Retrieved folder floor setting: %v\n", response)
    
    	return nil
    }
    
  • הצגת הגדרת הרצפה של הגנה מוגברת על המודל בארגון מסוים.

    
    import (
    	"context"
    	"fmt"
    	"io"
    
    	modelarmor "cloud.google.com/go/modelarmor/apiv1"
    	modelarmorpb "cloud.google.com/go/modelarmor/apiv1/modelarmorpb"
    )
    
    // getOrganizationFloorSettings gets details of a single floor setting of an organization.
    //
    // This method retrieves the details of a single floor setting of an organization.
    //
    // w io.Writer: The writer to use for logging.
    // organizationID string: The ID of the organization.
    func getOrganizationFloorSettings(w io.Writer, organizationID string) error {
    	ctx := context.Background()
    
    	// Create the Model Armor client.
    	client, err := modelarmor.NewClient(ctx)
    	if err != nil {
    		return fmt.Errorf("failed to create client: %w", err)
    	}
    	defer client.Close()
    
    	floorSettingsName := fmt.Sprintf("organizations/%s/locations/global/floorSetting", organizationID)
    
    	// Get the organization floor setting.
    	req := &modelarmorpb.GetFloorSettingRequest{
    		Name: floorSettingsName,
    	}
    
    	response, err := client.GetFloorSetting(ctx, req)
    	if err != nil {
    		return fmt.Errorf("failed to get floor setting: %w", err)
    	}
    
    	// Print the retrieved floor setting using fmt.Fprintf with the io.Writer.
    	fmt.Fprintf(w, "Retrieved org floor setting: %v\n", response)
    
    	return nil
    }
    

Java

כדי להריץ את הקוד הזה, קודם צריך להגדיר סביבת פיתוח ב-Java ולהתקין את Model Armor Java SDK.

  • הצגת הגדרת הגנה מוגברת על המודל בפרויקט נתון.

    
    import com.google.cloud.modelarmor.v1.FloorSetting;
    import com.google.cloud.modelarmor.v1.FloorSettingName;
    import com.google.cloud.modelarmor.v1.GetFloorSettingRequest;
    import com.google.cloud.modelarmor.v1.ModelArmorClient;
    import java.io.IOException;
    
    public class GetProjectFloorSetting {
    
      public static void main(String[] args) throws IOException {
        // TODO(developer): Replace these variables before running the sample.
        String projectId = "your-project-id";
    
        getProjectFloorSetting(projectId);
      }
    
      public static FloorSetting getProjectFloorSetting(String projectId) 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.
        try (ModelArmorClient client = ModelArmorClient.create()) {
          String name = FloorSettingName.of(projectId, "global").toString();
    
          GetFloorSettingRequest request = GetFloorSettingRequest.newBuilder().setName(name).build();
    
          FloorSetting floorSetting = client.getFloorSetting(request);
          System.out.println("Fetched floor setting for project: " + projectId);
    
          return floorSetting;
        }
      }
    }
  • בודקים את הגדרת הרף של הגנה מוגברת על המודל בתיקייה מסוימת.

    
    import com.google.cloud.modelarmor.v1.FloorSetting;
    import com.google.cloud.modelarmor.v1.FloorSettingName;
    import com.google.cloud.modelarmor.v1.GetFloorSettingRequest;
    import com.google.cloud.modelarmor.v1.ModelArmorClient;
    import java.io.IOException;
    
    public class GetFolderFloorSetting {
    
      public static void main(String[] args) throws IOException {
        // TODO(developer): Replace these variables before running the sample.
        String folderId = "your-folder-id";
    
        getFolderFloorSetting(folderId);
      }
    
      public static FloorSetting getFolderFloorSetting(String folderId) 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.
        try (ModelArmorClient client = ModelArmorClient.create()) {
          String name = FloorSettingName.ofFolderLocationName(folderId, "global").toString();
    
          GetFloorSettingRequest request = GetFloorSettingRequest.newBuilder().setName(name).build();
    
          FloorSetting floorSetting = client.getFloorSetting(request);
          System.out.println("Fetched floor setting for folder: " + folderId);
    
          return floorSetting;
        }
      }
    }
  • הצגת הגדרת הרצפה של הגנה מוגברת על המודל בארגון מסוים.

    
    import com.google.cloud.modelarmor.v1.FloorSetting;
    import com.google.cloud.modelarmor.v1.FloorSettingName;
    import com.google.cloud.modelarmor.v1.GetFloorSettingRequest;
    import com.google.cloud.modelarmor.v1.ModelArmorClient;
    import java.io.IOException;
    
    public class GetOrganizationFloorSetting {
    
      public static void main(String[] args) throws IOException {
        // TODO(developer): Replace these variables before running the sample.
        String organizationId = "your-organization-id";
    
        getOrganizationFloorSetting(organizationId);
      }
    
      public static FloorSetting getOrganizationFloorSetting(String organizationId) 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.
        try (ModelArmorClient client = ModelArmorClient.create()) {
          String name = FloorSettingName.ofOrganizationLocationName(organizationId, "global")
              .toString();
    
          GetFloorSettingRequest request = GetFloorSettingRequest.newBuilder().setName(name).build();
    
          FloorSetting floorSetting = client.getFloorSetting(request);
          System.out.println("Fetched floor setting for organization: " + organizationId);
    
          return floorSetting;
        }
      }
    }

Node.js

כדי להריץ את הקוד הזה, קודם צריך להגדיר סביבת פיתוח של Node.js ולהתקין את Model Armor Node.js SDK.

  • הצגת הגדרת הגנה מוגברת על המודל בפרויקט נתון.

    /**
     * TODO(developer): Uncomment these variables before running the sample.
     */
    // const projectId = 'your-project-id';
    
    const name = `projects/${projectId}/locations/global/floorSetting`;
    
    // Imports the Modelarmor library
    const {ModelArmorClient} = require('@google-cloud/modelarmor').v1;
    
    // Instantiates a client
    const modelarmorClient = new ModelArmorClient();
    
    async function getProjectFloorSettings() {
      // Construct request
      const request = {
        name,
      };
    
      // Run request
      const [response] = await modelarmorClient.getFloorSetting(request);
      return response;
    }
    
    return await getProjectFloorSettings();
  • בודקים את הגדרת הרף של הגנה מוגברת על המודל בתיקייה מסוימת.

    /**
     * TODO(developer): Uncomment these variables before running the sample.
     */
    // const folderId = 'your-folder-id';
    
    const name = `folders/${folderId}/locations/global/floorSetting`;
    
    // Imports the Modelarmor library
    const {ModelArmorClient} = require('@google-cloud/modelarmor').v1;
    
    // Instantiates a client
    const modelarmorClient = new ModelArmorClient();
    
    async function getFolderFloorSettings() {
      // Construct request
      const request = {
        name,
      };
    
      const [response] = await modelarmorClient.getFloorSetting(request);
      return response;
    }
    
    return await getFolderFloorSettings();
  • הצגת הגדרת הרצפה של הגנה מוגברת על המודל בארגון מסוים.

    /**
     * TODO(developer): Uncomment these variables before running the sample.
     */
    // const organizationId = 'your-organization-id';
    const name = `organizations/${organizationId}/locations/global/floorSetting`;
    
    // Imports the Modelarmor library
    const {ModelArmorClient} = require('@google-cloud/modelarmor').v1;
    
    // Instantiates a client
    const modelarmorClient = new ModelArmorClient();
    
    async function getOrganizationFloorSettings() {
      // Construct request
      const request = {
        name,
      };
    
      // Run request
      const [response] = await modelarmorClient.getFloorSetting(request);
      return response;
    }
    
    return await getOrganizationFloorSettings();

PHP

כדי להריץ את הקוד הזה, קודם צריך להגדיר סביבת פיתוח של PHP ולהתקין את Model Armor PHP SDK.

  • הצגת הגדרת הגנה מוגברת על המודל בפרויקט נתון.

    use Google\Cloud\ModelArmor\V1\Client\ModelArmorClient;
    use Google\Cloud\ModelArmor\V1\GetFloorSettingRequest;
    
    /**
     * Gets the floor settings for a given project.
     *
     * @param string $projectId The project Id for which the floor settings is to be retrieved.
     *
     */
    function get_project_floor_settings(string $projectId): void
    {
        $client = new ModelArmorClient();
    
        $floorSettingsName = sprintf('projects/%s/locations/global/floorSetting', $projectId);
    
        $response = $client->getFloorSetting((new GetFloorSettingRequest())->setName($floorSettingsName));
    
        printf("Floor settings retrieved successfully: %s\n", $response->serializeToJsonString());
    }
  • בודקים את הגדרת הרף של הגנה מוגברת על המודל בתיקייה מסוימת.

    use Google\Cloud\ModelArmor\V1\Client\ModelArmorClient;
    use Google\Cloud\ModelArmor\V1\GetFloorSettingRequest;
    
    /**
     * Gets the floor settings for a given folder.
     *
     * @param string $folderId The folder Id for which the floor settings is to be retrieved.
     *
     */
    function get_folder_floor_settings(string $folderId): void
    {
        $client = new ModelArmorClient();
    
        $floorSettingsName = sprintf('folders/%s/locations/global/floorSetting', $folderId);
    
        $response = $client->getFloorSetting((new GetFloorSettingRequest())->setName($floorSettingsName));
    
        printf("Floor settings retrieved successfully: %s\n", $response->serializeToJsonString());
    }
  • הצגת הגדרת הרצפה של הגנה מוגברת על המודל בארגון מסוים.

    use Google\Cloud\ModelArmor\V1\Client\ModelArmorClient;
    use Google\Cloud\ModelArmor\V1\GetFloorSettingRequest;
    
    /**
     * Gets the floor settings for a given organization.
     *
     * @param string $organizationId The organization Id for which the floor settings is to be retrieved.
     *
     */
    function get_organization_floor_settings(string $organizationId): void
    {
        $client = new ModelArmorClient();
    
        $floorSettingsName = sprintf('organizations/%s/locations/global/floorSetting', $organizationId);
    
        $response = $client->getFloorSetting((new GetFloorSettingRequest())->setName($floorSettingsName));
    
        printf("Floor settings retrieved successfully: %s\n", $response->serializeToJsonString());
    }

Python

כדי להריץ את הקוד הזה, קודם צריך להגדיר סביבת פיתוח של Python ולהתקין את Model Armor Python SDK.

  • הצגת הגדרת הגנה מוגברת על המודל בפרויקט נתון.

    
    from google.cloud import modelarmor_v1
    
    # Create the Model Armor client.
    client = modelarmor_v1.ModelArmorClient(transport="rest")
    
    # TODO(Developer): Uncomment below variable.
    # project_id = "YOUR_PROJECT_ID"
    
    floor_settings_name = f"projects/{project_id}/locations/global/floorSetting"
    
    # Get the project floor setting.
    response = client.get_floor_setting(
        request=modelarmor_v1.GetFloorSettingRequest(name=floor_settings_name)
    )
    
    # Print the retrieved floor setting.
    print(response)
    
  • בודקים את הגדרת הרף של הגנה מוגברת על המודל בתיקייה מסוימת.

    
    from google.cloud import modelarmor_v1
    
    # Create the Model Armor client.
    client = modelarmor_v1.ModelArmorClient(transport="rest")
    
    # TODO(Developer): Uncomment below variable.
    # folder_id = "YOUR_FOLDER_ID"
    
    # Prepare folder floor setting path/name
    floor_settings_name = f"folders/{folder_id}/locations/global/floorSetting"
    
    # Get the folder floor setting.
    response = client.get_floor_setting(
        request=modelarmor_v1.GetFloorSettingRequest(name=floor_settings_name)
    )
    
    # Print the retrieved floor setting.
    print(response)
    
  • הצגת הגדרת הרצפה של הגנה מוגברת על המודל בארגון מסוים.

    
    from google.cloud import modelarmor_v1
    
    # Create the Model Armor client.
    client = modelarmor_v1.ModelArmorClient(transport="rest")
    
    # TODO(Developer): Uncomment below variable.
    # organization_id = "YOUR_ORGANIZATION_ID"
    
    floor_settings_name = (
        f"organizations/{organization_id}/locations/global/floorSetting"
    )
    
    # Get the organization floor setting.
    response = client.get_floor_setting(
        request=modelarmor_v1.GetFloorSettingRequest(name=floor_settings_name)
    )
    
    # Print the retrieved floor setting.
    print(response)
    

עדכון הגדרות הרצפה של Model Armor

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

מריצים את הפקודה הבאה כדי לעדכן את הגדרות הרף של Model Armor.

המסוף

  1. נכנסים לדף הגנה מוגברת על המודל במסוף Google Cloud .

    מעבר אל הגנה מוגברת על המודל

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

  3. בדף Model Armor, עוברים לכרטיסייה Floor settings ולוחצים על Configure floor settings.

  4. מעדכנים את שדות החובה ולוחצים על שמירת הגדרות אבטחה מינימליות.

gcloud

   gcloud model-armor floorsettings update --full-uri=<full-uri-of-the-floorsetting>

פקודה לדוגמה:

       gcloud model-armor floorsettings update \
           --malicious-uri-filter-settings-enforcement=ENABLED \
           --pi-and-jailbreak-filter-settings-enforcement=DISABLED \
           --pi-and-jailbreak-filter-settings-confidence-level=LOW_AND_ABOVE \
           --basic-config-filter-enforcement=ENABLED \
           --add-rai-settings-filters='[{"confidenceLevel": "low_and_above", "filterType": "HARASSMENT"}, {"confidenceLevel": "high", "filterType": "SEXUALLY_EXPLICIT"}]' \
           --full-uri='folders/FOLDER_ID/locations/global/floorSetting' \
           --enable-floor-setting-enforcement=true

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

    gcloud model-armor floorsettings update \
        --full-uri=projects/PROJECT_ID/locations/global/floorSetting \
        --enable-multi-language-detection

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

  • PROJECT_ID: מזהה הפרויקט של הגדרות אבטחה מינימליות.
  • FOLDER_ID: המזהה של התיקייה להגדרות אבטחה מינימליות.

REST

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

    curl -X PATCH
      -d '{"filterConfig" :{"piAndJailbreakFilterSettings": { "filterEnforcement": "ENABLED"}, "maliciousUriFilterSettings": { "filterEnforcement": "ENABLED" }, "rai_settings":{"rai_filters":{"filter_type":"DANGEROUS", "confidence_level":"LOW_AND_ABOVE" }, \
      "rai_filters":{"filter_type":"HATE_SPEECH", "confidence_level":"LOW_AND_ABOVE" }, "rai_filters":{"filter_type":"HARASSMENT", "confidence_level":"LOW_AND_ABOVE" }, "rai_filters":{"filter_type":"SEXUALLY_EXPLICIT", "confidence_level":"LOW_AND_ABOVE" }}},"enableFloorSettingEnforcement":"true"}' \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $(gcloud auth print-access-token) \
      "https://modelarmor.googleapis.com/v1/projects/PROJECT_ID/locations/global/floorSetting"
  • מעדכנים את הגדרת הרמה של הגנה מוגברת על המודל לתיקייה מסוימת.

    curl -X PATCH \
      -d '{"filterConfig" :{"piAndJailbreakFilterSettings": { "filterEnforcement": "ENABLED"}, "maliciousUriFilterSettings": {"filterEnforcement": "ENABLED" }},"enableFloorSettingEnforcement":"true"}' \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
      "https://modelarmor.googleapis.com/v1/folders/FOLDER_ID/locations/global/floorSetting"
  • עדכון הגדרת הרמה של הגנה מוגברת על המודל בארגון מסוים.

    curl -X PATCH \
      -d '{"filterConfig" :{"piAndJailbreakFilterSettings": { "filterEnforcement": "ENABLED"}, "maliciousUriFilterSettings": {
          "filterEnforcement": "ENABLED" }},"enableFloorSettingEnforcement":"true"}' \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $(gcloud auth print-access-token)" \
          "https://modelarmor.googleapis.com/v1/organizations/ORGANIZATION_ID/locations/global/floorSetting"

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

  • PROJECT_ID: מזהה הפרויקט של הגדרות אבטחה מינימליות.
  • FOLDER_ID: המזהה של התיקייה להגדרות אבטחה מינימליות.
  • ORGANIZATION_ID: המזהה של הארגון להגדרות הקומה.

הפקודה update מחזירה את התגובה הבאה:

{
"name": "projects/PROJECT_ID/locations/global/floorSetting",
"updateTime": "2024-12-19T15:36:21.318191Z",
"filterConfig": {
  "piAndJailbreakFilterSettings": {
    "filterEnforcement": "ENABLED"
  },
"maliciousUriFilterSettings": {
  "filterEnforcement": "ENABLED"
 }
}
}

C#‎

כדי להריץ את הקוד הזה, קודם צריך להגדיר סביבת פיתוח בשפת C# ‎ ולהתקין את Model Armor C# SDK.

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

    using Google.Cloud.ModelArmor.V1;
    using System;
    
    public class UpdateProjectFloorSettings
    {
        public FloorSetting UpdateProjectFloorSetting(string projectId)
        {
            // Create the client
            ModelArmorClient client = ModelArmorClient.Create();
    
            // Construct the floor settings name
            string floorSettingsName = $"projects/{projectId}/locations/global/floorSetting";
    
            // Build the floor settings with your preferred filters
            // For more details on filters, please refer to the following doc:
            // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
            var raiFilter = new RaiFilterSettings.Types.RaiFilter
            {
                FilterType = RaiFilterType.HateSpeech,
                ConfidenceLevel = DetectionConfidenceLevel.High,
            };
    
            var raiFilterSettings = new RaiFilterSettings();
            raiFilterSettings.RaiFilters.Add(raiFilter);
    
            var filterConfig = new FilterConfig { RaiSettings = raiFilterSettings };
    
            var floorSetting = new FloorSetting
            {
                Name = floorSettingsName,
                FilterConfig = filterConfig,
                EnableFloorSettingEnforcement = true,
            };
    
            // Create the update request
            var updateRequest = new UpdateFloorSettingRequest { FloorSetting = floorSetting };
    
            // Update the floor settings
            FloorSetting response = client.UpdateFloorSetting(updateRequest);
    
            Console.WriteLine($"Floor setting updated: {response.Name}");
    
            return response;
        }
    }
  • מעדכנים את הגדרת הרמה של הגנה מוגברת על המודל לתיקייה מסוימת.

    using Google.Cloud.ModelArmor.V1;
    using System;
    
    public class UpdateFolderFloorSettings
    {
        public FloorSetting UpdateFolderFloorSetting(string folderId)
        {
            // Create the client
            ModelArmorClient client = ModelArmorClient.Create();
    
            // Construct the floor settings name
            string floorSettingsName = $"folders/{folderId}/locations/global/floorSetting";
    
            // Build the floor settings with your preferred filters
            // For more details on filters, please refer to the following doc:
            // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
            var raiFilter = new RaiFilterSettings.Types.RaiFilter
            {
                FilterType = RaiFilterType.HateSpeech,
                ConfidenceLevel = DetectionConfidenceLevel.High,
            };
    
            var raiFilterSettings = new RaiFilterSettings();
            raiFilterSettings.RaiFilters.Add(raiFilter);
    
            var filterConfig = new FilterConfig { RaiSettings = raiFilterSettings };
    
            var floorSetting = new FloorSetting
            {
                Name = floorSettingsName,
                FilterConfig = filterConfig,
                EnableFloorSettingEnforcement = true,
            };
    
            // Create the update request
            var updateRequest = new UpdateFloorSettingRequest { FloorSetting = floorSetting };
    
            // Update the floor settings
            FloorSetting response = client.UpdateFloorSetting(updateRequest);
    
            Console.WriteLine($"Floor setting updated: {response.Name}");
    
            return response;
        }
    }
  • עדכון הגדרת הרמה של הגנה מוגברת על המודל בארגון מסוים.

    using Google.Cloud.ModelArmor.V1;
    using System;
    
    public class UpdateOrganizationFloorSettings
    {
        public FloorSetting UpdateOrganizationFloorSetting(string organizationId)
        {
            // Create the client
            ModelArmorClient client = ModelArmorClient.Create();
    
            // Construct the floor settings name
            string floorSettingsName = $"organizations/{organizationId}/locations/global/floorSetting";
    
            // Build the floor settings with your preferred filters
            // For more details on filters, please refer to the following doc:
            // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
            var raiFilter = new RaiFilterSettings.Types.RaiFilter
            {
                FilterType = RaiFilterType.HateSpeech,
                ConfidenceLevel = DetectionConfidenceLevel.High,
            };
    
            var raiFilterSettings = new RaiFilterSettings();
            raiFilterSettings.RaiFilters.Add(raiFilter);
    
            var filterConfig = new FilterConfig { RaiSettings = raiFilterSettings };
    
            var floorSetting = new FloorSetting
            {
                Name = floorSettingsName,
                FilterConfig = filterConfig,
                EnableFloorSettingEnforcement = true,
            };
    
            // Create the update request
            var updateRequest = new UpdateFloorSettingRequest { FloorSetting = floorSetting };
    
            // Update the floor settings
            FloorSetting response = client.UpdateFloorSetting(updateRequest);
    
            Console.WriteLine($"Floor setting updated: {response.Name}");
    
            return response;
        }
    }

המשך

כדי להריץ את הקוד הזה, קודם צריך להגדיר סביבת פיתוח של Go ולהתקין את Model Armor Go SDK.

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

    
    import (
    	"context"
    	"fmt"
    	"io"
    
    	modelarmor "cloud.google.com/go/modelarmor/apiv1"
    	modelarmorpb "cloud.google.com/go/modelarmor/apiv1/modelarmorpb"
    )
    
    // updateProjectFloorSettings updates the floor settings of a project.
    //
    // This method updates the floor settings of a project.
    //
    // w io.Writer: The writer to use for logging.
    // projectID string: The ID of the project.
    func updateProjectFloorSettings(w io.Writer, projectID string) error {
    	ctx := context.Background()
    
    	// Create the Model Armor client.
    	client, err := modelarmor.NewClient(ctx)
    	if err != nil {
    		return fmt.Errorf("failed to create client: %w", err)
    	}
    	defer client.Close()
    
    	// Prepare project floor setting path/name
    	floorSettingsName := fmt.Sprintf("projects/%s/locations/global/floorSetting", projectID)
    
    	// Update the project floor setting
    	// For more details on filters, please refer to the following doc:
    	// [https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters](https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters)
    	enableEnforcement := true
    	req := &modelarmorpb.UpdateFloorSettingRequest{
    		FloorSetting: &modelarmorpb.FloorSetting{
    			Name: floorSettingsName,
    			FilterConfig: &modelarmorpb.FilterConfig{
    				RaiSettings: &modelarmorpb.RaiFilterSettings{
    					RaiFilters: []*modelarmorpb.RaiFilterSettings_RaiFilter{
    						{
    							FilterType:      modelarmorpb.RaiFilterType_HATE_SPEECH,
    							ConfidenceLevel: modelarmorpb.DetectionConfidenceLevel_HIGH,
    						},
    					},
    				},
    			},
    			EnableFloorSettingEnforcement: &enableEnforcement,
    		},
    	}
    
    	response, err := client.UpdateFloorSetting(ctx, req)
    	if err != nil {
    		return fmt.Errorf("failed to update floor setting: %w", err)
    	}
    
    	// Print the updated config
    	fmt.Fprintf(w, "Updated project floor setting: %+v\n", response)
    
    	return nil
    }
    
  • מעדכנים את הגדרת הרמה של הגנה מוגברת על המודל לתיקייה מסוימת.

    
    import (
    	"context"
    	"fmt"
    	"io"
    
    	modelarmor "cloud.google.com/go/modelarmor/apiv1"
    	modelarmorpb "cloud.google.com/go/modelarmor/apiv1/modelarmorpb"
    )
    
    // updateFolderFloorSettings updates floor settings of a folder.
    //
    // This method updates the floor settings of a folder.
    //
    // w io.Writer: The writer to use for logging.
    // folderID string: The ID of the folder.
    func updateFolderFloorSettings(w io.Writer, folderID string) error {
    	ctx := context.Background()
    
    	// Create the Model Armor client.
    	client, err := modelarmor.NewClient(ctx)
    	if err != nil {
    		return fmt.Errorf("failed to create client: %w", err)
    	}
    	defer client.Close()
    
    	// Prepare folder floor settings path/name
    	floorSettingsName := fmt.Sprintf("folders/%s/locations/global/floorSetting", folderID)
    
    	// Prepare the floor setting update
    	enableEnforcement := true
    	floorSetting := &modelarmorpb.FloorSetting{
    		Name: floorSettingsName,
    		FilterConfig: &modelarmorpb.FilterConfig{
    			RaiSettings: &modelarmorpb.RaiFilterSettings{
    				RaiFilters: []*modelarmorpb.RaiFilterSettings_RaiFilter{
    					{
    						FilterType:      modelarmorpb.RaiFilterType_HATE_SPEECH,
    						ConfidenceLevel: modelarmorpb.DetectionConfidenceLevel_HIGH,
    					},
    				},
    			},
    		},
    		EnableFloorSettingEnforcement: &enableEnforcement,
    	}
    
    	// Prepare request for updating the floor setting.
    	req := &modelarmorpb.UpdateFloorSettingRequest{
    		FloorSetting: floorSetting,
    	}
    
    	// Update the floor setting.
    	response, err := client.UpdateFloorSetting(ctx, req)
    	if err != nil {
    		return fmt.Errorf("failed to update floor setting: %w", err)
    	}
    
    	// Print the updated config
    	fmt.Fprintf(w, "Updated folder floor setting: %v\n", response)
    
    	return nil
    
    }
    
  • עדכון הגדרת הרמה של הגנה מוגברת על המודל בארגון מסוים.

    
    import (
    	"context"
    	"fmt"
    	"io"
    
    	modelarmor "cloud.google.com/go/modelarmor/apiv1"
    	modelarmorpb "cloud.google.com/go/modelarmor/apiv1/modelarmorpb"
    )
    
    // updateOrganizationFloorSettings updates floor settings of an organization.
    //
    // This method updates the floor settings of an organization.
    //
    // w io.Writer: The writer to use for logging.
    // organizationID string: The ID of the organization.
    func updateOrganizationFloorSettings(w io.Writer, organizationID string) error {
    	ctx := context.Background()
    
    	// Create the Model Armor client.
    	client, err := modelarmor.NewClient(ctx)
    	if err != nil {
    		return fmt.Errorf("failed to create client: %w", err)
    	}
    	defer client.Close()
    
    	// Prepare organization floor setting path/name
    	floorSettingsName := fmt.Sprintf("organizations/%s/locations/global/floorSetting", organizationID)
    
    	// Update the organization floor setting
    	// For more details on filters, please refer to the following doc:
    	// [https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters](https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters)
    	enableEnforcement := true
    	req := &modelarmorpb.UpdateFloorSettingRequest{
    		FloorSetting: &modelarmorpb.FloorSetting{
    			Name: floorSettingsName,
    			FilterConfig: &modelarmorpb.FilterConfig{
    				RaiSettings: &modelarmorpb.RaiFilterSettings{
    					RaiFilters: []*modelarmorpb.RaiFilterSettings_RaiFilter{
    						{
    							FilterType:      modelarmorpb.RaiFilterType_HATE_SPEECH,
    							ConfidenceLevel: modelarmorpb.DetectionConfidenceLevel_HIGH,
    						},
    					},
    				},
    			},
    			EnableFloorSettingEnforcement: &enableEnforcement,
    		},
    	}
    
    	response, err := client.UpdateFloorSetting(ctx, req)
    	if err != nil {
    		return fmt.Errorf("failed to update floor setting: %w", err)
    	}
    
    	// Print the updated config
    	fmt.Fprintf(w, "Updated org floor setting: %+v\n", response)
    

Java

כדי להריץ את הקוד הזה, קודם צריך להגדיר סביבת פיתוח ב-Java ולהתקין את Model Armor Java SDK.

Node.js

כדי להריץ את הקוד הזה, קודם צריך להגדיר סביבת פיתוח של Node.js ולהתקין את Model Armor Node.js SDK.

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

    /**
     * TODO(developer): Uncomment these variables before running the sample.
     */
    // const projectId = 'your-project-id';
    
    const modelarmor = require('@google-cloud/modelarmor');
    const {ModelArmorClient} = modelarmor.v1;
    const {protos} = modelarmor;
    
    // Initiate client
    const client = new ModelArmorClient();
    
    async function updateProjectFloorSettings() {
      const floorSettingsName = `projects/${projectId}/locations/global/floorSetting`;
    
      // Build the floor settings with your preferred filters
      // For more details on filters, please refer to the following doc:
      // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
      const floorSetting = {
        name: floorSettingsName,
        filterConfig: {
          raiSettings: {
            raiFilters: [
              {
                filterType:
                  protos.google.cloud.modelarmor.v1.RaiFilterType.HARASSMENT,
                confidenceLevel:
                  protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel
                    .LOW_AND_ABOVE,
              },
              {
                filterType:
                  protos.google.cloud.modelarmor.v1.RaiFilterType
                    .SEXUALLY_EXPLICIT,
                confidenceLevel:
                  protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel
                    .LOW_AND_ABOVE,
              },
            ],
          },
        },
        enableFloorSettingEnforcement: true,
      };
    
      const request = {
        floorSetting: floorSetting,
      };
    
      const [response] = await client.updateFloorSetting(request);
      return response;
    }
    
    return await updateProjectFloorSettings();
  • מעדכנים את הגדרת הרמה של הגנה מוגברת על המודל לתיקייה מסוימת.

    /**
     * TODO(developer): Uncomment these variables before running the sample.
     */
    // const folderId = 'your-folder-id';
    
    // Imports the Model Armor library
    const modelarmor = require('@google-cloud/modelarmor');
    const {ModelArmorClient} = modelarmor.v1;
    const {protos} = modelarmor;
    
    // Instantiates a client
    const client = new ModelArmorClient();
    
    async function updateFolderFloorSettings() {
      const floorSettingsName = `folders/${folderId}/locations/global/floorSetting`;
    
      // Build the floor settings with your preferred filters
      // For more details on filters, please refer to the following doc:
      // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
      const floorSetting = {
        name: floorSettingsName,
        filterConfig: {
          raiSettings: {
            raiFilters: [
              {
                filterType:
                  protos.google.cloud.modelarmor.v1.RaiFilterType.HARASSMENT,
                confidenceLevel:
                  protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel
                    .LOW_AND_ABOVE,
              },
              {
                filterType:
                  protos.google.cloud.modelarmor.v1.RaiFilterType
                    .SEXUALLY_EXPLICIT,
                confidenceLevel:
                  protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel
                    .LOW_AND_ABOVE,
              },
            ],
          },
        },
        enableFloorSettingEnforcement: true,
      };
    
      const request = {
        floorSetting: floorSetting,
      };
    
      const [response] = await client.updateFloorSetting(request);
      return response;
    }
    
    return await updateFolderFloorSettings();
  • עדכון הגדרת הרמה של הגנה מוגברת על המודל בארגון מסוים.

    /**
     * TODO(developer): Uncomment these variables before running the sample.
     */
    // const organizationId = 'your-organization-id';
    
    const modelarmor = require('@google-cloud/modelarmor');
    const {ModelArmorClient} = modelarmor.v1;
    const {protos} = modelarmor;
    
    const client = new ModelArmorClient();
    
    async function updateOrganizationFloorSettings() {
      const floorSettingsName = `organizations/${organizationId}/locations/global/floorSetting`;
    
      // Build the floor settings with your preferred filters
      // For more details on filters, please refer to the following doc:
      // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
      const floorSetting = {
        name: floorSettingsName,
        filterConfig: {
          raiSettings: {
            raiFilters: [
              {
                filterType:
                  protos.google.cloud.modelarmor.v1.RaiFilterType.HARASSMENT,
                confidenceLevel:
                  protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel
                    .LOW_AND_ABOVE,
              },
              {
                filterType:
                  protos.google.cloud.modelarmor.v1.RaiFilterType
                    .SEXUALLY_EXPLICIT,
                confidenceLevel:
                  protos.google.cloud.modelarmor.v1.DetectionConfidenceLevel
                    .LOW_AND_ABOVE,
              },
            ],
          },
        },
        enableFloorSettingEnforcement: true,
      };
    
      const request = {
        floorSetting: floorSetting,
      };
    
      const [response] = await client.updateFloorSetting(request);
      return response;
    }
    
    return await updateOrganizationFloorSettings();

PHP

כדי להריץ את הקוד הזה, קודם צריך להגדיר סביבת פיתוח של PHP ולהתקין את Model Armor PHP SDK.

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

    use Google\Cloud\ModelArmor\V1\Client\ModelArmorClient;
    use Google\Cloud\ModelArmor\V1\RaiFilterType;
    use Google\Cloud\ModelArmor\V1\DetectionConfidenceLevel;
    use Google\Cloud\ModelArmor\V1\UpdateFloorSettingRequest;
    use Google\Cloud\ModelArmor\V1\FilterConfig;
    use Google\Cloud\ModelArmor\V1\FloorSetting;
    use Google\Cloud\ModelArmor\V1\RaiFilterSettings;
    use Google\Cloud\ModelArmor\V1\RaiFilterSettings\RaiFilter;
    
    /**
     * Updates the floor settings for a given project.
     *
     * @param string $projectId The project Id for which the floor settings is to be updated.
     *
     */
    function update_project_floor_settings(string $projectId): void
    {
        $client = new ModelArmorClient();
    
        $floorSettingsName = sprintf('projects/%s/locations/global/floorSetting', $projectId);
    
        // Build the floor settings with your preferred filters
        // For more details on filters, please refer to the following doc:
        // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
    
        $raiFilterSetting = (new RaiFilterSettings())
            ->setRaiFilters([
                (new RaiFilter())
                    ->setFilterType(RaiFilterType::HATE_SPEECH)
                    ->setConfidenceLevel(DetectionConfidenceLevel::HIGH)
            ]);
    
        $filterConfig = (new FilterConfig())->setRaiSettings($raiFilterSetting);
        $floorSetting = (new FloorSetting())
            ->setName($floorSettingsName)
            ->setFilterConfig($filterConfig)
            ->setEnableFloorSettingEnforcement(true);
    
        $updateRequest = (new UpdateFloorSettingRequest())->setFloorSetting($floorSetting);
    
        $response = $client->updateFloorSetting($updateRequest);
    
        printf("Floor setting updated: %s\n", $response->getName());
    }
  • מעדכנים את הגדרת הרמה של הגנה מוגברת על המודל לתיקייה מסוימת.

    use Google\Cloud\ModelArmor\V1\Client\ModelArmorClient;
    use Google\Cloud\ModelArmor\V1\RaiFilterType;
    use Google\Cloud\ModelArmor\V1\DetectionConfidenceLevel;
    use Google\Cloud\ModelArmor\V1\UpdateFloorSettingRequest;
    use Google\Cloud\ModelArmor\V1\FilterConfig;
    use Google\Cloud\ModelArmor\V1\FloorSetting;
    use Google\Cloud\ModelArmor\V1\RaiFilterSettings;
    use Google\Cloud\ModelArmor\V1\RaiFilterSettings\RaiFilter;
    
    /**
     * Updates the floor settings for a given folder.
     *
     * @param string $folderId The folder Id for which the floor settings is to be updated.
     *
     */
    function update_folder_floor_settings(string $folderId): void
    {
        $client = new ModelArmorClient();
    
        $floorSettingsName = sprintf('folders/%s/locations/global/floorSetting', $folderId);
    
        // Build the floor settings with your preferred filters
        // For more details on filters, please refer to the following doc:
        // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
    
        $raiFilterSetting = (new RaiFilterSettings())
            ->setRaiFilters([
                (new RaiFilter())
                    ->setFilterType(RaiFilterType::HATE_SPEECH)
                    ->setConfidenceLevel(DetectionConfidenceLevel::HIGH)
            ]);
    
        $filterConfig = (new FilterConfig())->setRaiSettings($raiFilterSetting);
        $floorSetting = (new FloorSetting())
            ->setName($floorSettingsName)
            ->setFilterConfig($filterConfig)
            ->setEnableFloorSettingEnforcement(true);
    
        $updateRequest = (new UpdateFloorSettingRequest())->setFloorSetting($floorSetting);
    
        $response = $client->updateFloorSetting($updateRequest);
    
        printf("Floor setting updated: %s\n", $response->getName());
    }
  • עדכון הגדרת הרמה של הגנה מוגברת על המודל בארגון מסוים.

    use Google\Cloud\ModelArmor\V1\Client\ModelArmorClient;
    use Google\Cloud\ModelArmor\V1\RaiFilterType;
    use Google\Cloud\ModelArmor\V1\DetectionConfidenceLevel;
    use Google\Cloud\ModelArmor\V1\UpdateFloorSettingRequest;
    use Google\Cloud\ModelArmor\V1\FilterConfig;
    use Google\Cloud\ModelArmor\V1\FloorSetting;
    use Google\Cloud\ModelArmor\V1\RaiFilterSettings;
    use Google\Cloud\ModelArmor\V1\RaiFilterSettings\RaiFilter;
    
    /**
     * Updates the floor settings for a given organization.
     *
     * @param string $organizationId The organization Id for which the floor settings is to be updated.
     *
     */
    function update_organization_floor_settings(string $organizationId)
    {
        $client = new ModelArmorClient();
    
        $floorSettingsName = sprintf('organizations/%s/locations/global/floorSetting', $organizationId);
    
        // Build the floor settings with your preferred filters
        // For more details on filters, please refer to the following doc:
        // https://cloud.google.com/security-command-center/docs/key-concepts-model-armor#ma-filters
    
        $raiFilterSetting = (new RaiFilterSettings())
            ->setRaiFilters([
                (new RaiFilter())
                    ->setFilterType(RaiFilterType::HATE_SPEECH)
                    ->setConfidenceLevel(DetectionConfidenceLevel::HIGH)
            ]);
    
        $filterConfig = (new FilterConfig())->setRaiSettings($raiFilterSetting);
        $floorSetting = (new FloorSetting())
            ->setName($floorSettingsName)
            ->setFilterConfig($filterConfig)
            ->setEnableFloorSettingEnforcement(true);
    
        $updateRequest = (new UpdateFloorSettingRequest())->setFloorSetting($floorSetting);
    
        $response = $client->updateFloorSetting($updateRequest);
    
        printf("Floor setting updated: %s\n", $response->getName());
    }

Python

כדי להריץ את הקוד הזה, קודם צריך להגדיר סביבת פיתוח של Python ולהתקין את Model Armor Python SDK.

בדיקת הממצאים לגבי הפרה של הגדרת ערך הסף

כל ממצא של Model Armor מזהה הפרה של הגדרת רמת ההגנה. הפרה מתרחשת כששבלונת Model Armor לא עומדת בסטנדרטים המינימליים של האבטחה שמוגדרים בהגדרות הסף של היררכיית המשאבים. הגדרות אבטחה מינימליות מגדירות את הדרישות המינימליות לתבניות.

הממצאים נוצרים כשמתרחשת אחת מהפרות ההגדרה הבאות:

  • תבנית עם הגדרות פחות מגבילות נוצרת לפני שמגדירים את הגדרות אבטחה מינימליות.
  • בתבנית חסרים מסננים נדרשים.
  • תבנית לא עומדת ברמת המהימנות המינימלית של המסננים.

כשהמערכת מזהה הפרה, היא יוצרת ממצא ברמת חומרה גבוהה ב-Security Command Center (אם אתם משתמשים במסלול Premium או Enterprise של Security Command Center). בממצא מצוינת הגדרת המחיר המינימלי שהופרה, התבנית שלא עומדת בדרישות ופרטים על ההפרה.

בדוגמה הבאה מוצג השדה sourceProperties של הממצא. ההפרה הזו, שקשורה למסנן URI זדוני, התרחשה כי הגדרת התבנית של maliciousUriFilterSettings היא DISABLED, אבל הגדרות אבטחה מינימליות מחייבות שהיא תהיה ENABLED.

{
  "filterConfig": {
    "raiSettings": {
      "raiFilters": [
        {
          "filterType": "HATE_SPEECH",
          "confidenceLevel": {
            "floorSettings": "LOW_AND_ABOVE",
            "template": "MEDIUM_AND_ABOVE"
          }
        },
        {
          "filterType": "HARASSMENT",
          "confidenceLevel": {
            "floorSettings": "MEDIUM_AND_ABOVE",
            "template": "HIGH"
          }
        }
      ]
    },
    "piAndJailbreakFilterSettings": {
      "confidenceLevel": {
        "floorSettings": "LOW_AND_ABOVE",
        "template": "HIGH"
      }
    },
    "maliciousUriFilterSettings": {
      "floorSettings": "ENABLED",
      "template": "DISABLED"
    }
  }
}

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