Web Application FirewallによるOCI Generative AIエンドポイントの保護 (2024/08/21)

Web Application FirewallによるOCI Generative AIエンドポイントの保護 (2024/08/21)

https://www.ateam-oracle.com/post/protecting-oci-generative-ai-endpoints-with-web-application-firewall

投稿者: Ramesh Balajepalli | Master Cloud Architect


生成AIベースのアプリケーションは急速に普及し、多くの企業が大規模な言語モデル(LLM)を業務に統合して顧客価値を高めています。AIがビジネス・プロセスの中心になるにつれ、生成AIエンドポイントの保護は、財務リスクの軽減だけでなく、ブランドの評判と顧客の信頼の保護にも不可欠です。敵対的な攻撃、データ中毒、不正アクセスなどのAIサービスに対するセキュリティの脅威が増加しています。大規模な言語モデル・アプリケーションについてはOWASP Top 10を参照し、LLMの様々な脅威ベクトルについてはMitre ATLASを参照してください。


このブログ投稿では、生成AIエンドポイントを保護し、ネットワークを保護するための戦略について説明します。OCI Web Application Firewallを使用することで、OWASP上位10件のWeb攻撃、共通脆弱性(CVE)および悪意のあるボット攻撃からアプリケーションを保護できます。



フローと実装のステップをすばやく説明します。


  • ステップ1&2: ユーザー・リクエストは、OCI WAFに関連付けられているLoad Balancerに移動します。すべてのトラフィックがこのレイヤーで検査され、この時点で悪意のあるトラフィックまたは不正なトラフィックがブロックされます。WAFルールの設定については、同僚が作成したこのブログ投稿を参照してください。
  • ステップ3: 許可されたトラフィックがプライベートAPIゲートウェイに送信されます。このプライベートAPI Gatewayでは、カスタマ認可プロバイダ・ファンクションまたはネイティブのOAuth検証を使用してユーザーが認証および認可されます。
  • ステップ4: カスタム認可プロバイダ関数を使用すると、Python、Java、Goなどの複数のサポートされている言語でAuthロジックを記述でき、OAuth、SAMLまたはその他の認証メカニズムを実装できます。カスタム認証関数の記述の詳細は、このページを参照してください。
  • ステップ5&6: OCI Functionsを使用したバックエンド・ルート – このFunctionsは、コンテンツのフィルタリング、高度なプロンプト・エンジニアリング技術の適用、OCI生成AIサービスにデプロイされたLLMに対するデータの問合せを行うための追加レイヤーとして機能します。


次に、Cohere Largeモデルの問合せに使用できるpythonコードの例を示します。APIゲートウェイにファンクションを呼び出すためのアクセス権があり、ファンクションが生成AIサービスにアクセスできることを確認します。


Policy Examples
ALLOW dynamic-group fn-group-name TO use generative-ai-family in TENANCY
ALLOW dynamic-group api-gw-group-name to manage functions-family in TENANCY


import io
import json
from datetime import datetime, timedelta
import logging
import oci

compartment_id = "ocid1.compartment.oc1..xxx"
CONFIG_PROFILE = "DEFAULT"
config = {}
signer = oci.auth.signers.get_resource_principals_signer()
input = "how do I use object Storage service with CLI"

# Service endpoint
endpoint = "https://inference.generativeai.us-chicago-1.oci.oraclecloud.com"

generative_ai_inference_client = oci.generative_ai_inference.GenerativeAiInferenceClient(config=config,signer=signer, service_endpoint=endpoint, retry_strategy=oci.retry.NoneRetryStrategy(), timeout=(10,240))

chat_detail = oci.generative_ai_inference.models.ChatDetails()

chat_request = oci.generative_ai_inference.models.CohereChatRequest()
chat_request.message = input
chat_request.max_tokens = 600
chat_request.temperature = 1
chat_request.frequency_penalty = 0
chat_request.top_p = 0.75
chat_request.top_k = 0

# Initialize chat history
chat_history = []

# Add first interaction to chat history
previous_chat_message_1 = oci.generative_ai_inference.models.CohereUserMessage(message="tell me about oci")
previous_chat_reply_1 = oci.generative_ai_inference.models.CohereChatBotMessage(message="OCI stands for Oracle Cloud Infrastructure. It's a suite of cloud services offered by Oracle Corporation for businesses to build, deploy, and manage resources in the cloud. Oracle Cloud Infrastructure provides the foundational services needed to run applications in the cloud, including computing, storage, and networking, along with various high-level services for AI, machine learning, databases, and more.\n\nHere's a breakdown of some key aspects of Oracle Cloud Infrastructure:\n1. Compute Service: This service allows users to provision and manage virtual machines (VMs) or \"instances\" that can run applications. These instances can be quickly scaled up or down based on demand.\n2. Storage Service: OCI offers block storage, which can be attached to instances, as well as object storage for large-scale, scalable data storage. It also provides archival storage for long-term data retention at a low cost.\n3. Virtual Networking: Users can create and manage virtual networks to enable communication between instances, load balancing, and network security.\n4. Autonomous Database: This is a managed database service that uses machine learning to automate many traditional database management tasks, such as provisioning, scaling, backups, and security.\n5. Container Engine: Oracle's container service allows developers to deploy, manage, and scale Docker containers in the cloud.\n6. Functions: This is a serverless computing service that lets developers write and deploy code without managing infrastructure.\n7. Load Balancing: OCI provides load balancing capabilities to distribute incoming application traffic across multiple instances, ensuring high availability and fault tolerance.\n8. Security: Oracle Cloud Infrastructure offers various security features, including identity and access management, encryption, and network security rules.\n9. Monitoring and Management: OCI provides tools for monitoring resources, managing performance, and visualizing cloud usage.\n10. Integration with Other Oracle Services: OCI works seamlessly with other Oracle services like Oracle Functions, Autonomous Database, and Oracle Application Container Cloud.\n\nOracle Cloud Infrastructure is designed to handle enterprise-level workloads and is known for its scalability, reliability, and security. Oracle targets OCI at organizations looking to move their existing workloads to the cloud or develop new cloud-native applications. They offer a range of pricing plans and support options to cater to different customer needs.")
chat_history.extend([previous_chat_message_1, previous_chat_reply_1])

# Add second interaction to chat history
previous_chat_message_2 = oci.generative_ai_inference.models.CohereUserMessage(message="tell me about its sdk")
previous_chat_reply_2 = oci.generative_ai_inference.models.CohereChatBotMessage(message="Oracle Cloud Infrastructure (OCI) provides Software Development Kits (SDKs) that allow developers to interact programmatically with various services offered by Oracle Cloud. These SDKs are designed to make it easier for developers to build, deploy, and manage resources in the Oracle Cloud using applications developed in various programming languages.\n\nOracle Cloud Infrastructure SDK is available in multiple programming languages, including:\n1. Python: The Python SDK allows Python developers to integrate their applications seamlessly with Oracle Cloud Services. It provides a range of client libraries for compute, storage, networking, and other services. Developers can use this SDK to create, configure, and manage resources in their Oracle Cloud environment.\n2. Java: For Java developers, the Java SDK offers a collection of libraries and tools to interact with OCI services. It enables developers to write applications that provision and manage resources, handle storage, and perform other cloud operations.\n3. Go: The Go SDK enables developers who prefer the Go language to work with Oracle Cloud services. It provides packages for the core compute, storage, and network services, making it easier to develop applications that leverage OCI.\n4. JavaScript/TypeScript: The JavaScript/TypeScript SDK allows developers to integrate Oracle Cloud services into Node.js applications. This SDK is useful for developing serverless applications, web services, or front-end applications that interact with OCI.\n5. Ruby: Ruby developers can use the Ruby SDK to interface with Oracle Cloud. This SDK gives them the ability to manage resources, provision instances, and interact with other OCI services.\n6. .NET: The .NET SDK enables C# and VB.NET developers to work with OCI services. It includes client libraries for core cloud services and helps developers build .NET applications that leverage the cloud infrastructure.\n\nThese SDKs are designed to abstract the complexities of interacting directly with the Oracle Cloud API endpoints, making it simpler for developers to integrate and build applications on top of Oracle Cloud Infrastructure. They provide convenient methods and data models that align with the respective programming languages, making the code more readable and easier to write.\n\nIn addition to these language-specific SDKs, Oracle also provides CLI (Command Line Interface) tools that allow users to manage their Oracle Cloud resources from the command line, which can be useful for scripting and automation tasks.\n\nDevelopers can download the appropriate SDK from the Oracle Cloud Infrastructure SDK repository on GitHub, where they can also find detailed documentation, code samples, and instructions for using the SDKs. These SDKs are regularly updated to keep pace with the latest changes and additions to the Oracle Cloud Infrastructure services.")
#chat_history.extend([previous_chat_message_2, previous_chat_reply_2])

# Assign the accumulated chat history to the chat request
chat_request.chat_history = chat_history

# Set chat details and make the request
chat_detail.serving_mode = oci.generative_ai_inference.models.OnDemandServingMode(model_id="ocid1.generativeaimodel.oc1.us-chicago-1.amaaaaaask7dceyawk6mgunzodenakhkuwxanvt6wo3jcpf72ln52dymk4wq")
chat_detail.chat_request = chat_request
chat_detail.compartment_id = compartment_id

chat_response = generative_ai_inference_client.chat(chat_detail)

# Print result
print("**************************Chat Result**************************")
print(chat_response.data)


ノート: サンプル・コードでは、LLMのコンテキストを構築するためにチャット履歴を送信しています。これはクライアント・アプリケーションで処理する必要があります。

ご存知でしたか?

生成AIサービスを使用した各推論によって、コストのかかる計算がトリガーされます。たとえば、OCI Large Cohereモデルを使用すると、チャット履歴を含む6,000文字の単一推論(100万回繰り返す)のコストは約12,000ドルになります。これらのAIエンドポイントが保護されていない場合は、多額の請求を受ける可能性があります。


このブログ投稿では、ネットワーク・ペリメータ保護戦略をOCI環境内の生成AIベースのアプリケーションに効果的に適用する方法について考察しました。このブログで説明するアーキテクチャは、OCI上の生成AIサービスに関するカスタム・アプリケーションを構築および強化するためにさらに拡張できます。


ネットワーク・ペリメータの保護と生成AIセキュリティに関する詳細なインサイトについては、OCIセキュリティ・ブログ・チャネルで他の投稿を確認してください。


コメント

このブログの人気の投稿

Oracle RACによるメンテナンスのためのドレインとアプリケーション・コンティニュイティの仕組み (2023/11/01)

Oracle APEXのInteractive Gridで、Oracle Formsと比較して、重複行の検証を制御/通過させる方法 (2022/07/21)

Oracle APEX 24.1の一般提供の発表 (2024/06/17)