檢視次數:
在您的應用程式中整合 AI Guard,以掃瞄您的 AI 使用情況,檢測有害內容生成、敏感信息洩漏和提示注入。
如需趨勢科技託管的整合,請參閱 整合 Trend 託管的 AI 防護。為了資料主權,請在您的 AWS 環境中部署和託管趨勢科技 Artifact 掃瞄器。Trend Vision One 僅接收掃瞄結果。
AI 應用程式安全使用點數進行模型掃描。根據預期的模型掃描來規劃每月的點數使用。
先決條件:
  • 具有創建 API 金鑰和執行掃描權限的 Trend Vision One 角色。
  • 確認您的 AWS 帳戶是否有足夠的配額來支持隨需 G 和 VT 實例類型。趨勢科技建議增加緩衝以應對實例大小可能的變更。
  • 在您的AWS帳戶中啟用CloudWatch日誌記錄權限。

步驟

  1. 前往Cloud SecurityCloud AccountsAWS以連接或更新您的AWS帳戶。
  2. 要設定新的 AWS 帳戶:
    1. 點選Add Account
    2. 對於Deployment Method,選擇CloudFormation
    3. 選取帳號類型:
      • Single AWS Account
      • AWS Organization
    4. 提供「帳號」「說明」以顯示在Cloud Accounts中。
    5. 指定「Organizational Unit ID」。當您新增 AWS 組織時,所有在 AWS 中未指定別名的成員帳戶將在 Cloud Accounts 中收到自動生成的名稱。
  3. 要配置現有的 AWS 帳戶:
    1. 按一下「Update AWS account」,然後按一下帳號名稱。
    2. 「Cloud Accounts Settings」中,點擊「Stack Update」標籤。
  4. 選擇 AWS 區域以部署 CloudFormation 範本。
  5. 要將自訂標籤新增到 Trend Vision One 部署的資源,請選擇Resource tagging並指定鍵值對。
    • 要新增最多三個標籤,請按一下「Create a new tag」
  6. 點選下一步
  7. 啟用「AI Application Security」
  8. 選取「部署」
  9. 選擇「Enable AI Guard」
  10. 在同一瀏覽器會話中的新標籤頁中,使用具有管理員權限的角色登入您要連接的 AWS 帳戶。
  11. 對於現有的 AWS 帳戶
    1. 「Update the CloudFormation template」下,按一下「Copy S3 URL」
    2. 如果 API 金鑰已過期,請點擊「Copy Vision One API key」,然後在 CloudFormation 中替換 API 金鑰。Trend Vision One API 金鑰有效期為 90 天。
    3. 若要在部署前檢視範本,請點擊「Download and Review Template」
    4. 前往「Stacks」,然後點擊您想要更新的堆疊名稱。
      • Vision-One-雲端帳戶管理
    5. 按一下「更新」。
    6. 選擇「Replace current template」
    7. 將範本 S3 URL 貼入「Amazon S3 URL」
    8. 按「下一步」。
  12. 對於新的 AWS 帳戶
    1. 按「下一步」。
    2. 要使用自動部署:
      1. 選取「Automated」做為部署類型。
      2. 點擊「Launch stack」以在 AWS 控制台中啟動 CloudFormation 範本。
      3. 完成「Quick Create Stack」中的步驟。
    3. 要使用手動部署:
      1. 選取「手動」做為部署類型。
      2. 點擊「Download the template and stack parameters as a .zip」
      3. 前往「CloudFormation」下的「Stacks」
      4. 使用 .zip 檔案中的參數建立新堆疊。
  13. Trend Vision One中,點擊「完成」
  14. 在另一個分頁中,登入 AWS 管理控制台並開啟 CloudFormation 堆疊。
  15. 前往「Outputs」標籤頁並複製GuardAPIEndpoint。
  16. 將 AI Guard 整合到您的應用程式中。請參考以下程式碼片段進行整合。
    import os
    import requests
    
    # Get your Trend Vision One API key from environment variable
    api_key = os.environ.get("V1_API_KEY")
    if not api_key:
        raise ValueError("Missing V1_API_KEY environment variable")
    
    # Get your Trend Micro AI Guard URL from environment variable
    ai_guard_url = os.environ.get("AI_GUARD_URL")
    if not ai_guard_url:
        raise ValueError("Missing AI_GUARD_URL environment variable")
    
    # Configure headers
    headers = {
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json",
        "TMV1-Application-Name": "your-application-name"  # Required
    }
    
    # Prepare the payload
    payload = {
        "prompt": "Your prompt or message here"
    }
    
    # Copy AI Guard URL from AWS template Stack Output
    url = f"{ai_guard_url}"
    
    # Make the API request
    response = requests.post(
        url,
        headers=headers,
        json=payload
    )
    
    # Check response status
    if response.status_code == 200:
        result = response.json()
    
        # API returns action and optional reasons
        action = result.get("action")
        reasons = result.get("reasons", [])
    
        if action == "Allow":
            print("Request allowed by AI Guard")
        elif action == "Block":
            print(f"Request blocked by AI Guard")
            print(f"Reasons: {', '.join(reasons)}")
    
        print(f"Response ID: {result.get('id')}")
    else:
        print(f"Error: {response.status_code} - {response.text}")
    
    • 使用 GuardAPIEndpoint 的值來設定 AI_GUARD_URL 的值。

    請求選項

    參數
    描述
    請求類型
    簡單請求或 OpenAI 聊天格式
    選擇具有TMV1-Request-Type標頭的項目。
    回應詳情
    最小或表示
    使用Prefer標頭進行控制。
    驗證
    Bearer API 金鑰
    授權:Bearer <token>

關閉自託管AI防護 上層主題

步驟

  1. 移至Cloud SecurityCloud AccountsAWS
  2. 記錄哪些帳戶已啟動 AI 安全功能。
  3. 「Cloud Accounts Settings」中,點擊「Stack Update」標籤。
  4. 關閉「AI Application Security」
  5. 「Update the CloudFormation template」下,按一下「Copy S3 URL」
  6. 前往「Stacks」並點擊您想要更新的堆疊名稱。
    • Vision-One-雲端帳戶管理
  7. 按一下「更新」。
  8. 如果 API 金鑰已過期,請點擊「Copy Vision One API key」,然後在 CloudFormation 中替換 API 金鑰。Trend Vision One API 金鑰有效期為 90 天。
  9. 驗證移除 AI 安全功能堆疊。

後續步驟

疑難排解

問題
原因
處理行動
來自 API 的 401 或 403
無效或過期的API金鑰;角色缺乏權限
重新生成密鑰或指派具有AI Guard掃瞄權限的角色。
action=封鎖意外地
政策過於激進
降低至「中」或調整類別切換。
Trend Vision One 中沒有結果
自託管未連接或未應用CloudFormation
重新執行「Update AWS account」並確認堆疊已完成。
解析錯誤
錯誤的 TMV1-Request-Type 用於有效負載
將標頭與請求格式匹配。