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

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

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

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

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

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

הנה כמה תרחישי שימוש נפוצים:

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

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

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

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

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

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

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

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

המסוף

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

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

    כדי להפעיל ממשקי API, צריך את ההרשאה serviceusage.services.enable. אם יצרתם את הפרויקט, סביר להניח שכבר יש לכם את ההרשאה הזו דרך התפקיד 'בעלים' (roles/owner). אחרת, תוכלו לקבל את ההרשאה הזו דרך התפקיד 'אדמין בממשק 'שימוש בשירות'' (roles/serviceusage.serviceUsageAdmin). איך מקצים תפקידים

    להפעלת ה-API

  2. בוחרים את הפרויקט שבו רוצים להפעיל את Model Armor.

gcloud

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

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

    הפעלת Cloud Shell

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

  2. מפעילים את Model Armor API, אם הוא עדיין לא מופעל:

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

    כדי להפעיל ממשקי API, צריך את ההרשאה serviceusage.services.enable. אם יצרתם את הפרויקט, סביר להניח שכבר יש לכם את ההרשאה הזו דרך התפקיד "בעלים" (roles/owner). אחרת, תוכלו לקבל את ההרשאה הזו דרך התפקיד "אדמין בממשק 'שימוש בשירות'" (roles/serviceusage.serviceUsageAdmin). איך מקצים תפקידים

    gcloud services enable modelarmor.googleapis.com

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

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

השלב הזה נחוץ רק אם משתמשים ב-CLI של gcloud עם Model Armor ורוצים להשתמש באזור או במספר אזורים שונים מאזור ברירת המחדל us. כדי לוודא שה-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 עם שרתי MCP ב-Google Cloud.

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

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

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

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

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

  1. נכנסים לדף Model Armor במסוף Google Cloud .

    כניסה לדף Model Armor

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

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

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

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

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

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

הגדרת אופן ההורשה של הגדרות סף המחיר המינימלי

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

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

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

  • ‫Disable: השבתה של כל הגדרות האבטחה המינימליות שעברו בירושה. המשמעות היא שאין כללי זיהוי שחלים על תבניות Model Armor ועל Agent Platform עבור עומסי העבודה של Gemini. לוחצים על Save floor settings (שמירת הגדרות הרצפה) ומדלגים על שאר השלבים. בכרטיסייה Floor settings אפשר לראות שהסטטוס הוא "מושבת".

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

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

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

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

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

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

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

הצגת הגדרות הסף של Model Armor

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

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

המסוף

  1. נכנסים לדף Model Armor במסוף Google Cloud .

    כניסה לדף Model Armor

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

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

gcloud

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

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

      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

  • הצגת הגדרת הרף של Model Armor בפרויקט.

    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"
  • צפייה בהגדרת הרף של Model Armor לתיקייה.

    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"
  • הצגת הגדרת האבטחה המינימלית של Model Armor לארגון.

    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
    }
    
  • הצגת הגדרת הרף של Model Armor בארגון מסוים.

    
    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.

  • הצגת הגדרת הרף של Model Armor בפרויקט נתון.

    
    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;
        }
      }
    }
  • הצגת הגדרת האבטחה המינימלית של Model Armor בארגון מסוים.

    
    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.

  • הצגת הגדרת הרף של Model Armor בפרויקט נתון.

    /**
     * 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();
  • הצגת הגדרת האבטחה המינימלית של Model Armor בארגון מסוים.

    /**
     * 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.

  • הצגת הגדרת הרף של Model Armor בפרויקט נתון.

    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());
    }
  • הצגת הגדרת הרף של Model Armor בארגון מסוים.

    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.

  • הצגת הגדרת הרף של Model Armor בפרויקט נתון.

    
    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 כדי לשנות את דרישות המינימום לתבניות, לשקף שינויים במדיניות האבטחה, לתקן הגדרות שגויות או לפתור קונפליקטים בין הגדרות הרצפה.

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

המסוף

  1. נכנסים לדף Model Armor במסוף Google Cloud .

    מעבר אל Model Armor

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

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

  4. מעדכנים את שדות החובה ולוחצים על Save floor settings.

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

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

    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"
  • מעדכנים את הגדרת הרמה של Model Armor לתיקייה מסוימת.

    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"
  • מעדכנים את הגדרת הרמה של Model Armor בארגון מסוים.

    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.

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

    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;
        }
    }
  • מעדכנים את הגדרת הרמה של Model Armor לתיקייה מסוימת.

    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;
        }
    }
  • מעדכנים את הגדרת הרמה של Model Armor בארגון מסוים.

    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.

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

    
    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
    }
    
  • מעדכנים את הגדרת הרמה של Model Armor לתיקייה מסוימת.

    
    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
    
    }
    
  • עדכון הגדרת האבטחה המינימלית של Model Armor לארגון נתון.

    
    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.

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

    /**
     * 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();
  • מעדכנים את הגדרת הרמה של Model Armor לתיקייה מסוימת.

    /**
     * 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();
  • עדכון הגדרת האבטחה המינימלית של Model Armor לארגון נתון.

    /**
     * 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.

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

    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());
    }
  • מעדכנים את הגדרת הרמה של Model Armor לתיקייה מסוימת.

    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"
    }
  }
}

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