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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

המסוף

  1. מפעילים את Model Armor 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 זדוני.
  • הגדרות אבטחה מינימליות ברמת הפרויקט (ספציפיות יותר): בפרויקט שבתיקייה צריך להשתמש בזיהוי של החדרת פרומפטים ופריצת Jailbreak ברמת סמך בינונית.

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

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

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

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

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

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

אפשר להגדיר את ההגדרות של Floor ברמת הארגון, התיקייה והפרויקט. ממשק המשתמש זמין רק ברמת הפרויקט, ומאפשר לרשת הגדרות ברמת הארגון או התיקייה. כדי להגדיר את ההגדרות של רמות הגישה ברמת הארגון או התיקייה, צריך להשתמש ב-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. בדף קביעת הגדרות של מחיר מינימום, בוחרים את אפשרות ההגדרה.
  5. בקטע Detections, מגדירים את הגדרות הזיהוי.
  6. אופציונלי: אם בוחרים בזיהוי של Sensitive Data Protection, מגדירים את ההגדרות של Sensitive Data Protection.
  7. בקטע Responsible AI, מגדירים את רמת הסמך לכל מסנן תוכן.

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

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

  10. בוחרים באפשרות Enable multi-language support כדי להשתמש בהגדרות של זיהוי שפות מרובות.

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

Terraform

כדי לאכוף באופן הצהרתי ספי בטיחות מינימליים בכל הארגון, התיקייה או היררכיית הפרויקטים, מגדירים את המשאב google_model_armor_floorsetting באמצעות הספק google‏ (>= 6.13.0):

resource "google_model_armor_floorsetting" "floor_setting" {
  parent   = RESOURCE_PARENT
  location = "global"

  filter_config {
    rai_settings {
      rai_filters {
        filter_type      = "HATE_SPEECH"
        confidence_level = "MEDIUM_AND_ABOVE"
      }
      rai_filters {
        filter_type      = "HARASSMENT"
        confidence_level = "HIGH"
      }
      rai_filters {
        filter_type      = "DANGEROUS"
        confidence_level = "MEDIUM_AND_ABOVE"
      }
      rai_filters {
        filter_type      = "SEXUALLY_EXPLICIT"
        confidence_level = "MEDIUM_AND_ABOVE"
      }
    }

    sdp_settings {
      basic_config {
        filter_enforcement = "ENABLED"
      }
    }

    pi_and_jailbreak_filter_settings {
      filter_enforcement = "ENABLED"
      confidence_level   = "HIGH"
    }

    malicious_uri_filter_settings {
      filter_enforcement = "ENABLED"
    }
  }

  enable_floor_setting_enforcement = true

  integrated_services = [
    "AI_PLATFORM",
    "GOOGLE_MCP_SERVER",
  ]

  ai_platform_floor_setting {
    inspect_and_block    = true
    enable_cloud_logging = true
  }

  google_mcp_server_floor_setting {
    inspect_and_block    = true
    enable_cloud_logging = true
  }

  floor_setting_metadata {
    multi_language_detection {
      enable_multi_language_detection = true
    }
  }
}

מחליפים את RESOURCE_PARENT בהיקף ההיררכיה שבו חלה הגדרת המחיר המינימלי:

  • רמת הארגון: organizations/ORGANIZATION_ID, שחלה על כל התיקיות והפרויקטים בארגון.

  • ברמת התיקייה: folders/FOLDER_ID, שחלה על כל הפרויקטים בתיקייה.

  • רמת הפרויקט: projects/PROJECT_ID, שחלה על פרויקט אחד.

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

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

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

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

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

  • השבתה: השבתה של כל הגדרות מחיר מינימום שעברו בירושה. כלומר, כללי הזיהוי לא חלים על התבניות של Model Armor ועל Agent Platform בעומסי העבודה של Gemini. לוחצים על שמירת הגדרות המחיר המינימלי ומדלגים על שאר השלבים. הסטטוס "מושבת" מופיע בכרטיסייה הגדרות של מחיר מינימום.

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

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

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

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

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

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

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

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

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

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

המסוף

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

    כניסה לדף Model Armor

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

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

gcloud

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

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

       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.

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

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

    
    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.

  • הצגת הגדרת הסף של 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;
        }
      }
    }
  • הצגת הגדרת הסף של 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 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.

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

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

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

    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.

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

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

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: מזהה הארגון של הגדרות הקומה.

פקודת העדכון מחזירה את התגובה הבאה:

{
"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());
    }
  • עדכון הגדרת הסף של 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 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 בתבנית היא מושבתת, אבל ההגדרות של הסף דורשות שהיא תהיה מופעלת.

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

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