フロア設定の構成

このドキュメントでは、Model Armor のフロア設定を表示して更新する方法について説明し、フロア設定違反の例を示します。

最小価格の設定には、主に次の 2 つの目的があります。

  • テンプレートの適合性: 新しいテンプレートが、フロア設定で定義されたテンプレートと同等以上の制限を適用していることを確認します。テンプレートの適合性は、組織レベルとフォルダレベルで定義されます。

  • インライン適用: Gemini モデルと Google Cloud MCP サーバーに Model Armor の保護を適用します。インライン適用はプロジェクト レベルで構成されます。インライン適用にフロア設定を使用する場合、プロジェクトで作成するテンプレートは、それらのフロア設定に準拠している必要があります。

フロア設定を使用する場面

一般的なユースケースは次のとおりです。

  • テンプレートのコンプライアンスを適用し、ポリシーの回帰を防ぐ: 組織、フォルダ、プロジェクト レベルで最小フィルタしきい値を定義して、新しく作成および更新されたテンプレートがセキュリティ標準を満たし、確立されたベースラインを下回る保護レベルにならないようにします。
  • モデルとツールのインライン適用を有効にする: アプリケーション コードを変更せずに、サポートされている Gemini モデルと Google Cloud リモート MCP サーバーをプロジェクト レベルで保護します。
  • 分散型チーム構成を管理する: 自律的なプロジェクト チームがカスタム テンプレートを作成できるようにしながら、設定が組織のガバナンス ポリシーに準拠するようにします。

始める前に

始める前に、次のタスクを完了します。

必要な権限を取得する

フロア設定の管理に必要な権限を取得するには、Model Armor フロア設定に対する Model Armor Floor Setting 管理者(roles/modelarmor.floorSettingsAdmin)IAM ロールを付与するよう管理者に依頼してください。ロールの付与については、プロジェクト、フォルダ、組織に対するアクセス権の管理をご覧ください。

必要な権限は、カスタムロールや他の事前定義ロールから取得することもできます。

API を有効にする

Model Armor を使用するには、Model Armor API を有効にする必要があります。

コンソール

  1. Model Armor API を有効にします(有効になっていない場合)。

    API を有効にするために必要なロール

    API を有効にするには、serviceusage.services.enable 権限が必要です。プロジェクトを作成した場合は、オーナーロール(roles/owner)を介してこの権限がすでに付与されている可能性があります。それ以外の場合は、Service Usage 管理者ロール(roles/serviceusage.serviceUsageAdmin)を介してこの権限を取得できます。ロールを付与する方法を確認する。

    API の有効化

  2. Model Armor を有効にするプロジェクトを選択します。

gcloud

始める前に、Google Cloud CLI で Model Armor API を使用して、次の処理を行います。

  1. Google Cloud CLI をインストールし、フェデレーション ID を使用して gcloud CLI にログインします。ログイン後、次のコマンドを実行して Google Cloud CLI を初期化します。

    gcloud init

  2. Model Armor API を有効にします(有効になっていない場合)。

    API を有効にするために必要なロール

    API を有効にするには、serviceusage.services.enable 権限が必要です。プロジェクトを作成した場合は、オーナーロール(roles/owner)を介してこの権限がすでに付与されている可能性があります。それ以外の場合は、Service Usage 管理者ロール(roles/serviceusage.serviceUsageAdmin)を介してこの権限を取得できます。ロールを付与する方法を確認する。

    gcloud services enable modelarmor.googleapis.com

  3. gcloud CLI を使用して API エンドポイントのオーバーライドを設定する。

gcloud CLI を使用して API エンドポイントのオーバーライドを設定する

この手順は、Model Armor で gcloud CLI を使用し、デフォルトの us マルチリージョン以外のリージョンまたはマルチリージョンを使用する場合にのみ必要です。gcloud CLI がリクエストを Model Armor サービスに正しくルーティングするように、API エンドポイントのオーバーライドを手動で設定する必要があります。

次のコマンドを実行して、グローバル API エンドポイントを使用します。

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

フロア設定の適用

ローカル設定は常に適用されます。たとえば、フロア設定が競合する場合は、リソース階層の下位にある設定が優先されます。同様に、プロジェクト レベルのフロア設定は、競合するフォルダレベルのフロア設定をオーバーライドします。

次の表に、さまざまなレベルで最小価格設定がどのように適用されるかを示します。

フロア設定のレベル アプリケーション
組織レベル 組織内のすべてのものに適用されます。
フォルダレベル その特定のフォルダ内のすべてのプロジェクトに適用されます。
プロジェクト レベル その特定のプロジェクトにのみ適用されます。

異なるレベルで設定された場合にフロア設定がどのように適用されるかを示すために、次の例を考えてみましょう。たとえば、フロア設定を次のように設定したとします。

  • フォルダレベル(より一般的)のフロア設定: このフォルダ内のすべてのコンテンツで、悪意のある URI フィルタを有効にする必要があります。
  • プロジェクト レベル(より具体的)のフロア設定: フォルダ内のプロジェクトでは、中程度の信頼度でプロンプト インジェクションとジェイルブレイクの検出を使用する必要があります。

このシナリオでは、設定は次のようになります。

  • プロジェクト レベルの設定は常にフォルダレベルの設定よりも優先されるため、プロジェクト内に作成するテンプレートには、プロンプト インジェクションとジェイルブレイクの検出フィルタを含める必要があります。

  • 別のプロジェクトまたはフォルダで作成されたテンプレートは、最初のフォルダの悪意のある URI フィルタ ルールの影響を受けません。

フロア設定は、階層内の特定のレベルにのみ適用されます。ただし、組織レベルで設定されている場合は、組織全体に適用されます。

テンプレートとフロア設定の適合性

Model Armor テンプレートが作成または更新されると、Model Armor はテンプレートの構成がフロア設定に準拠しているかどうかを確認します。フロア設定よりも厳格でないテンプレートを作成または更新することはできません。

フロア設定では、テンプレートに次の適合ルールが適用されます。

  • フィルタの適用: フロア設定でフィルタを有効にする必要がある場合(悪意のある URL、プロンプト インジェクションとジェイルブレイク、児童性的虐待のコンテンツ(CSAM)フィルタの適用が ENABLED に設定されている場合など)、そのスコープ内のテンプレートでフィルタを DISABLED に設定することはできません。
  • 信頼レベルの優先順位: テンプレートでは、フロア設定と同等以上の信頼レベルを構成する必要があります。たとえば、最小設定で責任ある AI または CSAM の検出に MEDIUM_AND_ABOVE が指定されている場合、テンプレートで信頼レベルを HIGH に設定することはできません。

フロア設定は、組織レベル、フォルダレベル、プロジェクト レベルで設定できます。ユーザー インターフェースはプロジェクト レベルでのみ使用でき、組織レベルまたはフォルダレベルの設定を継承できます。組織レベルまたはフォルダレベルでフロア設定を行うには、API を使用する必要があります。

テンプレートの適合性により、テンプレートの構成が検証されます。データ検査では、適合テンプレートで定義された構成を使用して、実行時にプロンプトまたはレスポンスを分析します。次の表に、テンプレートの適合性とデータ検査がテンプレートとフロア設定にどのように適用されるかを示します。

チェック フロア設定 テンプレート
テンプレートの適合性 組織、フォルダ、プロジェクトのいずれかのレベルで構成されます。

注: Sensitive Data Protection は、テンプレートにデータ セキュリティ ポリシーを適用するように設定できます。ただし、テンプレートの適合性は検証されません。

プロジェクト レベルでのみ構成されます。
データの検査 検査モードとブロックモードを使用して、プロジェクト レベルでのみ適用されます。 REST API、Service Extensions、Gemini Enterprise、Agent Runtime を使用して適用されます。

Gemini Enterprise Agent Platform と Google Cloud MCP サーバーとの統合

Model Armor は、Agent Platform および Google Cloud MCP サーバーと統合され、定義されたフロア設定に基づいて Gemini モデルとGoogle Cloud リモート MCP サーバーからのリクエストとレスポンスをスクリーニングします。プロンプトとレスポンスを表示するには、Cloud Logging を有効にする必要があります。詳細については、Model Armor と Gemini Enterprise Agent Platform の統合と Model Armor と Google Cloud MCP サーバーの統合をご覧ください。

フロア設定のフィルタ バージョン

最小価格の設定では、デフォルトで Stable フィルタ バージョンが使用されます。次のリストは、フィルタ バージョンが各統合でどのように機能するかを示しています。

フロア設定の構成

フロア設定を構成して、Model Armor テンプレートの最小検出しきい値を定義します。これらの設定により、新規および変更済みのテンプレートがすべて特定の要件を満たしていることを確認します。

フロア設定を構成するには、次のいずれかのオプションを選択します。

コンソール

  1. Google Cloud コンソールで、[Model Armor] ページに移動します。

    [Model Armor] に移動

  2. プロジェクトを選択します。
  3. [Model Armor] ページで、[フロア設定] タブに移動し、[フロア設定を構成] をクリックします。
  4. [フロア設定の構成] ページで、構成オプションを選択します。
  5. [検出] セクションで、検出設定を構成します。
  6. 省略可: Sensitive Data Protection の検出を選択する場合は、Sensitive Data Protection の設定を構成します。
  7. [責任ある AI] セクションで、コンテンツ フィルタごとに信頼度を設定します。

  1. [サービス] セクションで、これらのフロア設定を適用するサービスを選択します。
  2. [ログ] セクションで、[Cloud Logging を有効にする] を選択して、すべてのユーザー プロンプト、モデル レスポンス、フロア設定の検出機能の結果をログに記録します。
  3. 多言語検出の設定を使用するには、[多言語サポートを有効にする] を選択します。
  4. [フロア設定を保存] をクリックします。

gcloud

gcloud model-armor floorsettings update コマンドを実行して、フロア設定を構成します。

gcloud model-armor floorsettings update \
    --full-uri='RESOURCE_PARENT/locations/global/floorSetting' \
    --rai-settings-filters='[{"filterType": "HATE_SPEECH", "confidenceLevel": "MEDIUM_AND_ABOVE"}, {"filterType": "HARASSMENT", "confidenceLevel": "HIGH"}, {"filterType": "DANGEROUS", "confidenceLevel": "MEDIUM_AND_ABOVE"}, {"filterType": "SEXUALLY_EXPLICIT", "confidenceLevel": "MEDIUM_AND_ABOVE"}]' \
    --basic-config-filter-enforcement=ENABLED \
    --pi-and-jailbreak-filter-settings-enforcement=ENABLED \
    --pi-and-jailbreak-filter-settings-confidence-level=HIGH \
    --malicious-uri-filter-settings-enforcement=ENABLED \
    --enable-floor-setting-enforcement=true \
    --add-integrated-services=AI_PLATFORM,GOOGLE_MCP_SERVER \
    --vertex-ai-enforcement-type=INSPECT_AND_BLOCK \
    --enable-vertex-ai-cloud-logging \
    --google-mcp-server-enforcement-type=INSPECT_AND_BLOCK \
    --enable-google-mcp-server-cloud-logging \
    --enable-multi-language-detection

RESOURCE_PARENT は、フロア設定が適用される階層スコープに置き換えます。

  • 組織レベル: organizations/ORGANIZATION_ID。組織内のすべてのフォルダとプロジェクトを管理します。

  • フォルダレベル: folders/FOLDER_ID。フォルダ内のすべてのプロジェクトを管理します。

  • プロジェクト レベル: projects/PROJECT_ID。1 つのプロジェクトを管理します。

REST

REST API を使用してフロア設定を構成するには、floorSetting リソースに PATCH リクエストを送信します。

curl -X PATCH \
    -H "Authorization: Bearer $(gcloud auth print-access-token)" \
    -H "Content-Type: application/json" \
    -d '{
      "filterConfig": {
        "raiSettings": {
          "raiFilters": [
            {
              "filterType": "HATE_SPEECH",
              "confidenceLevel": "MEDIUM_AND_ABOVE"
            },
            {
              "filterType": "HARASSMENT",
              "confidenceLevel": "HIGH"
            },
            {
              "filterType": "DANGEROUS",
              "confidenceLevel": "MEDIUM_AND_ABOVE"
            },
            {
              "filterType": "SEXUALLY_EXPLICIT",
              "confidenceLevel": "MEDIUM_AND_ABOVE"
            }
          ]
        },
        "sdpSettings": {
          "basicConfig": {
            "filterEnforcement": "ENABLED"
          }
        },
        "piAndJailbreakFilterSettings": {
          "filterEnforcement": "ENABLED",
          "confidenceLevel": "HIGH"
        },
        "maliciousUriFilterSettings": {
          "filterEnforcement": "ENABLED"
        }
      },
      "enableFloorSettingEnforcement": true,
      "integratedServices": [
        "AI_PLATFORM",
        "GOOGLE_MCP_SERVER"
      ],
      "aiPlatformFloorSetting": {
        "inspectAndBlock": true,
        "enableCloudLogging": true
      },
      "googleMcpServerFloorSetting": {
        "inspectAndBlock": true,
        "enableCloudLogging": true
      },
      "floorSettingMetadata": {
        "multiLanguageDetection": {
          "enableMultiLanguageDetection": true
        }
      }
    }' \
    "https://modelarmor.googleapis.com/v1/RESOURCE_PARENT/locations/global/floorSetting"

RESOURCE_PARENT は、フロア設定が適用される階層スコープに置き換えます。

  • 組織レベル: organizations/ORGANIZATION_ID。組織内のすべてのフォルダとプロジェクトを管理します。

  • フォルダレベル: folders/FOLDER_ID。フォルダ内のすべてのプロジェクトを管理します。

  • プロジェクト レベル: projects/PROJECT_ID。1 つのプロジェクトを管理します。

Terraform

組織、フォルダ、プロジェクトの階層全体に最小安全しきい値を宣言的に適用するには、google プロバイダ(>= 6.13.0)を使用して google_model_armor_floorsetting リソースを構成します。

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。1 つのプロジェクトを管理します。

フロア設定の変更が反映されるまで数分かかります。

フロア設定の継承方法を定義する

フロア設定を構成するときに、構成オプションを選択します。

  • 親のフロア設定を継承する: リソース階層の上位で設定されたフロア設定を継承します。[フロア設定を保存] をクリックして、残りの手順をスキップします。継承された設定を表示するには、[フロア設定] タブに移動します。

  • カスタム: このプロジェクトのフロア設定を定義します。プロジェクトに定義したカスタム設定によって、継承されたフロア設定がオーバーライドされます。

  • 無効: 継承されたフロア設定を無効にします。つまり、Gemini ワークロードの Model Armor テンプレートと Agent Platform に検出ルールが適用されません。[フロア設定を保存] をクリックして、残りの手順をスキップします。[フロア設定] タブで無効ステータスを確認します。

フロア設定の適用先を定義する

構成したフロア設定が適用される次のいずれかのサービスを選択します。

  • Model Armor - テンプレートの作成と更新: Model Armor は、プロジェクト内の新規および変更済みのすべての Model Armor テンプレートをチェックして、最小設定がフロア設定に沿っていることを確認します。

  • Google MCP サーバー: フロア設定では、Google または Google Cloud リモート MCP サーバーとの間で送受信されるリクエストがフロア設定のしきい値を満たしているかどうかを確認します。詳細については、Model Armor と Google Cloud MCP サーバーの統合(プレビュー)をご覧ください。

  • Agent Platform: Gemini モデルに送信されたリクエストをスクリーニングし、フロア設定のしきい値を満たすリクエストをログに記録するかブロックします。

    [Agent Platform] を選択すると、[Agent Platform] セクションが表示され、フロア設定の適用方法を選択できます。

    • 検査のみ: フロア設定を満たしていないリクエストを検出しますが、ブロックしません。
    • 違反を検出し、ブロックする: フロア設定を満たしていないリクエストを検出してブロックします。

Model Armor のフロア設定を表示する

Model Armor のフロア設定を表示して、既存の設定の確認、AI アプリケーションの最小要件の特定、テンプレートが想定どおりに動作しない場合の問題のトラブルシューティングを行います。

次のコマンドを実行して、Model Armor のフロア設定を表示します。

コンソール

  1. Google Cloud コンソールで、[Model Armor] ページに移動します。

    [Model Armor] に移動

  2. Model Armor を有効にしたプロジェクトが表示されていることを確認します。

  3. [Model Armor] ページの [フロア設定] タブに移動します。フロア設定が組織レベルで設定されている場合は、ここで確認できます。フロア設定が定義されていない場合は、構成する必要があります。詳細については、フロア設定を構成するをご覧ください。

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'

    次のように置き換えます。

    • フロア設定のプロジェクトの ID。
    • フロア設定のフォルダの ID。
    • フロア設定の組織の ID。

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"

次のように置き換えます。

  • フロア設定のプロジェクトの ID。
  • フロア設定のフォルダの ID。
  • フロア設定の組織の ID。

C#

このコードを実行するには、まず C# 開発環境を設定し、Model Armor C# SDK をインストールします。

Go

このコードを実行するには、まず 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
    }
    
  • 特定の組織の 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;
        }
      }
    }
  • 特定のフォルダの 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;
        }
      }
    }
  • 特定の組織の 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();
  • 特定のフォルダの 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();
  • 特定の組織の 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());
    }
  • 特定のフォルダの 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());
    }
  • 特定の組織の 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)
    
  • 特定のフォルダの 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)
    
  • 特定の組織の Model Armor のフロア設定を表示します。

    
    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. Google Cloud コンソールで、[Model Armor] ページに移動します。

    [Model Armor] に移動

  2. Model Armor を有効にしたプロジェクトが表示されていることを確認します。

  3. [Model Armor] ページで、[フロア設定] タブに移動し、[フロア設定を構成] をクリックします。

  4. 必須フィールドを更新して、[フロア設定を保存] をクリックします。

gcloud

   gcloud model-armor floorsettings update --full-uri=FULL_URI

コマンドの例:

       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

次のように置き換えます。

  • FULL_URI: フロア設定の完全なリソース URI。
  • PROJECT_ID: フロア設定のプロジェクトの ID。
  • FOLDER_ID: フロア設定のフォルダの ID。

REST

  • 特定のプロジェクトの Model Armor のフロア設定を更新します。

    curl -X PATCH \ \
      -d '{"filterConfig": {"piAndJailbreakFilterSettings": {"filterEnforcement": "ENABLED"}, "maliciousUriFilterSettings": {"filterEnforcement": "ENABLED"}, "csamFilterSettings": { "filterEnforcement": "ENABLED", "confidenceLevel": "LOW_AND_ABOVE" }, "raiSettings": {"raiFilters": [{"filterType": "DANGEROUS", "confidenceLevel": "LOW_AND_ABOVE"}, {"filterType": "HATE_SPEECH", "confidenceLevel": "LOW_AND_ABOVE"}, {"filterType": "HARASSMENT", "confidenceLevel": "LOW_AND_ABOVE"}, {"filterType": "SEXUALLY_EXPLICIT", "confidenceLevel": "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" }, "csamFilterSettings": {"filterEnforcement": "ENABLED", "confidenceLevel": "LOW_AND_ABOVE" }},"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" }, "csamFilterSettings": { "filterEnforcement": "ENABLED", "confidenceLevel": "LOW_AND_ABOVE" }},"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: フロア設定のプロジェクトの ID。
  • FOLDER_ID: フロア設定のフォルダの ID。
  • ORGANIZATION_ID: フロア設定の組織の 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

このコードを実行するには、まず 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 に重大度の高い検出結果が生成されます(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"
    },
    "csamFilterSettings": {
      "confidenceLevel": {
        "floorSettings": "MEDIUM_AND_ABOVE",
        "template": "HIGH"
      }
    }
  }
}

次のステップ