Upgrade to Pro — share decks privately, control downloads, hide ads and more …

AgentCoreで実現するマルチテナントAIエージェント

Avatar for iganin iganin
December 20, 2025

 AgentCoreで実現するマルチテナントAIエージェント

AI Builders Day 登壇資料
https://jawsug.connpass.com/event/371658/

Avatar for iganin

iganin

December 20, 2025
Tweet

More Decks by iganin

Other Decks in Technology

Transcript

  1. | 2 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. 自己紹介 Pub lic 名前 > 伊賀 裕展 会社 > エクサウィザーズ 職種 > ソフトウェアエンジニア 好きなサービス > Amazon Bedrock AgentCore Twitter > @iganin_dev LinkedIn > https://www.linkedin.com/in/hironobu-iga- 79994010a/
  2. | 5 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. SaaS 従来型ソフトウェアとSaaS Pub lic 従来型 https://docs.aws.amazon.com/ja_jp/whitepapers/latest/saas-architecture-fundamentals/the-initial-motivation.html • 製品をインストールしたスタンドアロン環境で運用 • 実行する製品のバージョンをカスタマーが制御 • 新機能のリリースのオーバーヘッドが大きくなる
  3. | 6 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. SaaS 従来型ソフトウェアとSaaS Pub lic 従来型 • 製品をインストールしたスタンドアロン環境で運用 • 実行する製品のバージョンをカスタマーが制御 • 新機能のリリースのオーバーヘッドが非常に大きく なる チームのサイクル時間が長くなり、新機能が ユーザーの手に届くまでの時間が伸びる 結果として、市場のダイナミクスに対応する 能力を損なう可能性がある https://docs.aws.amazon.com/ja_jp/whitepapers/latest/saas-architecture-fundamentals/the-initial-motivation.html
  4. | 7 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. SaaS 従来型ソフトウェアとSaaS Pub lic 従来型 SaaS https://docs.aws.amazon.com/ja_jp/whitepapers/latest/saas-architecture-fundamentals/moving-to-a-unified-experience.html • 製品をインストールしたスタンドアロン環境で運用 • 実行する製品のバージョンをカスタマーが制御 • 新機能のリリースのオーバーヘッドが非常に大きく なる チームのサイクル時間が長くなり、新機能が ユーザーの手に届くまでの時間が伸びる 結果として、市場のダイナミクスに対応する 能力を損なう可能性がある • すべてのテナントは 1 つの集合的な SaaS 環境で管 理される • すべてのテナントが同じバージョンのアプリケー ションを実行 https://docs.aws.amazon.com/ja_jp/whitepapers/latest/saas-architecture-fundamentals/the-initial-motivation.html
  5. | 8 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. SaaS 従来型ソフトウェアとSaaS Pub lic 従来型 SaaS • 製品をインストールしたスタンドアロン環境で運用 • 実行する製品のバージョンをカスタマーが制御 • 新機能のリリースのオーバーヘッドが非常に大きく なる チームのサイクル時間が長くなり、新機能が ユーザーの手に届くまでの時間が伸びる 結果として、市場のダイナミクスに対応する 能力を損なう可能性がある • すべてのテナントは 1 つの集合的な SaaS 環境で管 理される • すべてのテナントが同じバージョンのアプリケー ションを実行 単一の共有プロセスですべてのテナントに新 しい機能をデプロイ可能 運用上のオーバーヘッドを増やすことなく新 しいテナントを追加可能 https://docs.aws.amazon.com/ja_jp/whitepapers/latest/saas-architecture-fundamentals/the-initial-motivation.html https://docs.aws.amazon.com/ja_jp/whitepapers/latest/saas-architecture-fundamentals/moving-to-a-unified-experience.html
  6. | 9 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. SaaS SaaS Pub lic 顧客ごとの個別導入ではなく 多数の顧客に同じ仕組みを提供する つまり、同じシステムを、複数の顧客が同時に使う 顧客間で環境を共有する「マルチテナント」が重要になる
  7. | 10 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. SaaS SaaSのコントロールプレーンとアプリケーションプレーン Pub lic アドミニストレーション アプリケーション SaaS アプリケーション コントロールプレーン アプリケーションプレーン オンボーディング 支払い管理 メトリクス テナント管理 アイデンティティ 管理 アドミンユーザー 管理 サービス サービス コアサービス テ ナ ン ト プ ロ ビ ジ ョ ニ ン グ サービス サービス アプリケーションサービス データ データ
  8. | 11 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. SaaS SaaSのコントロールプレーンとアプリケーションプレーン Pub lic アドミニストレーション アプリケーション SaaS アプリケーション コントロールプレーン アプリケーションプレーン オンボーディング 支払い管理 メトリクス テナント管理 アイデンティティ 管理 アドミンユーザー 管理 サービス サービス コアサービス テ ナ ン ト プ ロ ビ ジ ョ ニ ン グ サービス サービス データ データ コントロールプレーン はSaaS全体で1つ アプリケーションプレーン はSaaSで複数のデプロイパターン アプリケーションサービス
  9. | 12 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. SaaS アプリケーションプレーンにおけるデプロイパターン Pub lic サイロ プール サービス データ サービス サービス データ サービス テナント 1 テナント 2 サービス データ サービス テナント 1 テナント 2 サービス データ サービス データ テナント 1 テナント 2 サービス データ サービス テナント 3 データ ハイブリッド
  10. | 13 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. SaaS サイロモデル(専用モデル) 各テナントでインフラストラクチャを占有 メリット • 強力で自然なテナント分離 • リソース消費がテナントと直接紐づく デメリット • コストが高くなる傾向がある • テナント数が増えると運用が複雑化する など... Pub lic サービス データ サービス サービス データ サービス テナント 1 テナント 2
  11. | 14 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. SaaS プールモデル(共有モデル) Pub lic 複数テナントでインフラストラクチャを共有 メリット • 高いリソース効率 • 迅速なオンボーディング デメリット • 設計と実装が複雑化しやすい傾向がある • データ分離のための厳格なアクセス制御 など... サービス データ サービス テナント 1 テナント 2
  12. | 15 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. SaaS ハイブリッドモデル(混合モデル) Pub lic サイロとプールが共存 リソースごとの例 • Computingはプール • Databaseはサイロ Tierによる違いの例 • プレミアムはサイロ • 通常は一部リソースをプール サービス データ サービス データ テナント 1 テナント 2 サービス データ サービス テナント 3 データ
  13. | 16 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. SaaS アプリケーションプレーンにおけるデプロイパターン Pub lic サイロ ハイブリッド プール サービス データ サービス サービス データ サービス テナント 1 テナント 2 サービス データ サービス テナント 1 テナント 2 サービス データ サービス データ テナント 1 テナント 2 サービス データ サービス テナント 3 データ テナントのティア リソース効率 運用効率 を考慮して、どのパターンにするかを検討する
  14. | 17 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. SaaS さらなる詳細はSaaS Lensで... Pub lic サイロ、プールのメリット・デメリットは他にもあります AWS Well-Architected フレームワーク SaaS レンズ により詳細が載っていますので、ぜひご確認ください! https://docs.aws.amazon.com/ja_jp/wellarchitected/latest/saas-lens/silo-isolation.html https://docs.aws.amazon.com/ja_jp/wellarchitected/latest/saas-lens/pool-isolation.html https://docs.aws.amazon.com/ja_jp/wellarchitected/latest/saas-lens/bridge-model.html
  15. | 19 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. マルチテナントの課題 課題の一覧 ・テナントコンテキストの伝播 ・データのパーティショニング ・テナント分離 ・うるさい隣人問題 ・テナントごとのオブサーバビリティ ・etc Pub lic
  16. | 20 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. マルチテナントの課題 テナントコンテキスト Pub lic SaaS 環境全体で使用されるテナントに関する重要な情報(※1) • テナントID o テナントの固有識別子 • テナントティア o standard, premiumなど • etc ※1 http://docs.aws.amazon.com/ja_jp/whitepapers/latest/saas-architecture-fundamentals/saas-identity.html
  17. | 21 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. マルチテナントの課題 テナントコンテキストの伝播 テナントコンテキストはマルチテナントを扱う上での重要情報 ルーティングやアクセス制御などの基礎となる SaaS全体に伝播する必要がある Pub lic
  18. | 22 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. マルチテナントの課題 データのパーティショニング 個々のテナントに対してテナントデータがどのように保存されるかを決める サイロ: データは分離され混合されることは基本的にはない プール: データは混在するので、テナント識別子などでテナントと紐づける 例: DynamoDB サイロ: 1テナント 1テーブル プール: テーブルのPartitioning Key に テナント識別子 を使用 Pub lic
  19. | 23 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. マルチテナントの課題 データのパーティション化 - Dynamo DB Pub lic サイロ プール
  20. | 24 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. マルチテナントの課題 テナント分離 テナントコンテキストを使用してリソースへのアクセスを制限する アプリケーションロジックだけでなくストレージ / DBレイヤーでの保護を追加する 多層防御の実現により、よりセキュアな実装が可能 Pub lic
  21. | 25 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. マルチテナントの課題 テナント分離 - DynamoDB Dynamo DBの例 Policyでアクセスを制御 dynamodb:LeadingKeys DynamoDBのpartition keyの値 Partition keyがtenant id と同一のデータしか アクセスできないことが保証される Pub lic Permission Policy の例 { "Effect": "Allow", "Action": [...], "Resource": [...], "Condition": { "ForAllValues:StringEquals": { "dynamodb:LeadingKeys": [ "{tenant_id}" ] } } }
  22. | 26 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. マルチテナントの課題 うるさい隣人問題 プールされているリソース • 特定のテナントがリソースを大きく使用 • テナント間の不公平・リソース枯渇 • システム全体の不安定化 対処 • 使用量の監視 o 閾値を超えた際のスロットル o レイトリミットの実装 o 閾値を超えたらティアを変更する • キューを使った制御 • オートスケーリングの導入 Pub lic
  23. | 27 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. マルチテナントの課題 テナントごとのオブサーバビリティ Pub lic 通常のメトリクスではテナントはファーストクラスの指標ではない メトリクスにテナントコンテキストを含める必要がある その上で、テナントを加味したダッシュボードを作成する https://docs.aws.amazon.com/ja_jp/wellarchitected/latest/saas-lens/tenant-insights.html
  24. | 28 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCoreにおける対応 03.
  25. | 29 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Amazon Bedrock AgentCore Pub lic Amazon Bedrock AgentCore は、 あらゆるフレームワークと基盤モデル を使用して、大規模かつ安全に、 非常に効果的なエージェントを構築、 デプロイ、運用するための エージェントプラットフォーム https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/what-is-bedrock-agentcore.html
  26. | 30 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore AgentCoreにおける対応 Pub lic 基本的には従来の対応と大きな差はない サービスごとに サイロ / プール を決める その上で、テナントコンテキストの伝播、データパーティショニング、テナント分離を検討 これ以降、以下のコンポーネントに関して確認する • AgentCore Runtime • AgentCore Memory • AgentCore Gateway
  27. | 31 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Runtime A.
  28. | 32 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Runtime AgentCore Runtime Pub lic AI エージェントやツールのデプロイと実行に特化した、 安全でサーバーレスなホスティング環境を提供 • セッション分離 • モデルの柔軟性 • フレームワーク非依存 • 消費ベースの価格設定モデル • etc https://github.com/awslabs/amazon-bedrock-agentcore-samples/tree/main/01-tutorials/01-AgentCore-runtime
  29. | 33 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Runtime AgentCore Runtimeのセッション分離 Pub lic Firecracker MicroVM レベルで分離 メモリ等のコンタミネーションを避けられる AWS re:Invent 2025 - Transforming from SaaS to multi-tenant agentic SaaS (SAS304)
  30. | 34 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Runtime AgentCore Runtime と テナントコンテキスト Pub lic AgentCore Runtime では Agent や ツール がホスティングされる 入り口として、テナントコンテキストをクライアントから受け取る必要がある その上で、テナントコンテキストをダウンストリームに伝える Tenant Context
  31. | 35 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Runtime Runtimeへのテナントコンテキストの伝播 Pub lic 手順 • IdPをCognitoとして、カスタムクレームでテナントコンテキストを定義 • Pre Token Generation Lambda Triggerでアクセストークンにカスタムトークンを含める • AgentCore RuntimeのrequestHeaderAllowlistにAuthorizationを登録 • PyJWTパッケージなどでクレームを取得
  32. | 36 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Runtime JWT 使用 • JWTを使用してテナントコンテキストを伝 える • 署名されているため、検証することでかい ざんされていないことを保証できる Pub lic { "iss": 発行者の識別子, "sub": ユーザー識別子, ”cid”: ”client_id", "exp": トークンの有効期限のタイムスタンプ, "iat": トークン発行日時のタイムスタンプ, "aud" : トークンの受信者識別子, "scopes": 情報の範囲や権限, "tenant_id": テナント識別子, "tenant_tier": テナントのティア } テナント コンテキス トを含める
  33. | 37 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Runtime CognitoにおけるCustom Claimsの設定 Pub lic CognitoのUserPoolにcustom claimsを定義し、テナントコンテキストを含める
  34. | 38 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Runtime Pre Token Generation Lambda Trigger Pub lic Custom Claims は通常 ID Token に含まれるが Acccess Token には含まれない Pre Token Generation Lambda Trigger で Access Token にも含めるようにする Version2 を使用
  35. | 39 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Runtime Pre Token Generation Lambda Trigger Pub lic def lambda_handler(event, context): # ユーザー属性からテナントコンテキストを取得 tenant_id = event.get('request', {}).get('userAttributes', {}).get('custom:tenant_id') tenant_tier = event.get('request', {}).get('userAttributes', {}).get('custom:tenant_tier') # アクセストークンにテナントコンテキストを追加 event['response'] = event.get('response', {}) event['response']['claimsAndScopeOverrideDetails'] = { 'accessTokenGeneration': { 'claimsToAddOrOverride': {' tenant_id': tenant_id , tenant_tier: tenant_tier } } } return event
  36. | 40 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Runtime RuntimeのrequestHeaderAllowlistの設定 Pub lic Runtimeの requestHeaderAllowlist で Authorization を許可し、 tokenをRuntimeから取得できるようにする agentcore configure --entrypoint agent.py \ --name sample_agent \ --execution-role sample-role-arn \ --requirements-file requirements.txt \ --authorizer-config "{\"customJWTAuthorizer\": ~~~ \ --request-header-allowlist "Authorization"
  37. | 41 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Runtime RuntimeのcontextからJWTを取得しデコードする Pub lic Runtimeのentrypointのcontextからtokenを取得しPyJWKClientでdecodeする claims からテナントコンテキストを取得できる @app.entrypoint def invoke(payload, context): auth_header = context.request_headers.get('Authorization') token = auth_header.replace('Bearer ', '') if auth_header.startswith(' Bearer ') else auth_header jwks_client = PyJWKClient(jwks_url) signing_key = jwks_client.get_signing_key_from_jwt(token) decoded = jwt.decode( access_token, signing_key.key, algorithms=["RS256"], issuer=f"https://cognito-idp.{region}.amazonaws.com/{user_pool_id}", options={"require": ["exp", "iat", "iss", "token_use"]}, )
  38. | 42 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. テナントコンテキストの伝播 Runtime以降のテナントコンテキストの伝播 Pub lic Runtime以降のダウンストリームへのテナントコンテキストの伝播 JWTを利用する場合以下の2つの方法がある • Impersonation - なりすまし • Act on behalf Delegation - 代理実行
  39. | 43 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. テナントコンテキストの伝播 Impersonation - なりすまし Pub lic クライアントから受け取ったTokenをダウンストリームに渡し続ける 同一Tokenなので、Scopeも元のまま... scope> item:read, record:write scope> item:read, record:write scope> item:read, record:write
  40. | 44 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. テナントコンテキストの伝播 Act on behalf Delegation - 代理実行 Pub lic クライアントから受け取ったTokenを変更しながらダウンストリームに渡す 下の例ではtoolに渡される際にscopeが絞られている scope> item:read, record:write scope> item:read Scope> record: write
  41. | 45 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. テナントコンテキストの伝播 なりすましでおきる問題 Pub lic クライアントから受け取ったTokenをダウンストリームに渡し続ける 最小権限の原則に違反し、必要以上に大きな権限を持つことになる 下流に渡したTokenが漏れた場合に「サービス全体のアクセス」ができてしまう 混乱した代理人問題が起きる可能性もある scope> item:read, record:write
  42. | 46 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. テナントコンテキストの伝播 AI Agent では 代理実行 パターンを使う Pub lic ホップ毎に Token Exchange を行う代理実行パターンで認証・認可情報をつたえる 代理実行パターンによって、最小権限の原則を守り、セキュリティを高く保つ AIエージェント A AIエージェント B サービス A
  43. | 47 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. テナントコンテキストの伝播 Token Exchange について Pub lic Token Exchangeについて、2025年12月18日に 14-token-exchange-at-request-interceptorというサンプルが amazon-bedrock-agentcore-samplesに追加されました。 ご興味のある方はぜひ確認してみてください!
  44. | 48 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Memory B.
  45. | 49 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Memory AgentCore Memory Pub lic AIエージェントに過去のインタラクションを記憶する機能を提供するフルマネージドサービス 短期的なコンテキストと長期的な知識の保持の両方をシンプルかつ強力に処理可能 https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/memory.html
  46. | 50 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Memory AgentCore Memory Pub lic AgentCore Memoryにはユーザーとの会話履歴が保存される ユーザー、テナント固有の情報も含まれる可能性がある データ層としてデータパーティショニングやテナント分離がとても重要 テナント A ユーザー A メモリー テナント A ユーザー B メモリー テナント B ユーザー C メモリー
  47. | 51 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Memory Memoryのデータパーティショニング Long Term Memory namespaceで論理分離 namespaceにテナントコンテキストを含める actorId=${tenantId}:${userId} namespace=/strategy/{memoryStrategyId}/a ctor/{actorId} Pub lic Short Term Memory actorId, sessionIdで分離 actorIdにテナントコンテキストを含める 例: actorId=${tenantId}:${userId}
  48. | 52 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Memory Memoryのテナント分離 Pub lic ActorIdやnamespaceに対してIAM PolicyのConditionで条件を絞る Runtime から AWS STSを使用して一時credentialsを発行して使用
  49. | 53 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Memory Memoryのテナント分離手順 Pub lic • IAM Roleに付与するPermisson Policyを定義 • IAM Roleに付与するTrust Policyを定義 o ① assumeRoleの呼び出し許可 o ② SessionTag付け許可 • STSでTagを付与してassumeRoleを実行 • 一時クレデンシャルを用いたMemoryへのアクセス
  50. | 54 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Memory Memoryのテナント分離 - Permission Policy ① Pub lic Short Term Memoryへのアクセス許可 bedrock-agentcore:actorIdをconditionで指定する { "Sid": "ShortTermMemoryPolicy", "Effect": "Allow", "Action": [... ], "Resource": ["arn:aws:bedrock-agentcore:{REGION}:{account_id}:memory/{memory_id}"], "Condition": { "StringEquals": { "bedrock-agentcore:actorId": "${aws:PrincipalTag/actorId}" } } }
  51. | 55 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Memory Memoryのテナント分離 - Permission Policy ② Pub lic Long Term Memory へのアクセス許可 bedrock-agentcore:namespaceをconditionで指定する { "Sid": "LongTermMemoryPolicy", "Effect": "Allow", "Action": [... ], "Resource": ["arn:aws:bedrock-agentcore:{REGION}:{account_id}:memory/{memory_id}"], "Condition": { "StringEquals": { "bedrock-agentcore:namespace": "/strategies/${strategy_id}/actor/${aws:PrincipalTag/actorId}" } } }
  52. | 56 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Memory Memoryのテナント分離 - Trust Policy Pub lic IAM RoleにRuntimeに対する実行権限とTag付けの信頼ポリシーをつける AssumeRoleでTagをつけるためにはsts:TagSessionの信頼ポリシーが必要 { "Sid":"AllowAssumeFromRuntime", "Effect": "Allow", "Principal": { "AWS": ${"Arn"} }, "Action": "sts:AssumeRole" } { "Sid": "AllowTagSession", "Effect": "Allow", "Principal": { "AWS": ${"Arn"} }, "Action": "sts:TagSession", "Condition": { "ForAllValues:StringEquals": { "aws:TagKeys": ["actorId"] } } Runtimeに対して実行許可 actorIdのTag付けを許可
  53. | 57 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Memory Memoryのテナント分離 - STS assumeRole Pub lic STSでassumeRoleを実行し、一時クレデンシャルを作成する def assume_tenant_role(tenant_id: str, user_id: str) -> Dict[str, str]: sts = boto3.client("sts", region_name=AWS_REGION) resp = sts.assume_role( RoleArn=TENANT_ROLE_ARN, RoleSessionName="session_name", DurationSeconds=900, Tags=[{"Key": "actorId", "Value": f"{tenant_id}:{user_id}"], ) creds = resp["Credentials"] return { "access_key": creds["AccessKeyId"], "secret_key": creds["SecretAccessKey"], "session_token": creds["SessionToken"], }
  54. | 58 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Memory Memoryのテナント分離 - Memoryへのアクセス Pub lic 一時クレデンシャルを用いてclientを生成、Memoryにアクセスする client = boto3.client( 'bedrock-agentcore', aws_access_key_id=access_key, aws_secret_access_key=secret_key, aws_session_token=session_token ) client.list_events( memoryId=memory_id, sessionId=session_id, actorId=actor_id, maxResults=5 )
  55. | 59 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Memory Memoryのテナント分離 Pub lic Permisson Policy の Condition でテナントの条件をつける STSのassumeRole のタグでテナントコンテキストを指定 assumeRole で取得した一時クレデンシャルでアクセス 上記でテナント分離を実現 テナント A ユーザー A メモリー テナント B ユーザー B メモリー テナント A ユーザー A
  56. | 60 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Memory AgentCore Memoryのテナント分離サンプル Pub lic より詳しく知りたい方や実際に手元で試したい方 amazon-bedrock-agentcore-samplesの 01-tutorials/04-AgentCore-memory/05-memory-security-patterns にAgentCore Memoryのテナント分離サンプルがあります! CognitoのId Poolを使用した方法もあるのでぜひご参照ください!
  57. | 61 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Gateway C.
  58. | 62 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Gateway AgentCore Gateway Pub lic 外部リソースをエージェント互換のツールとして公開するフルマネージドサービス • 複数の API、関数、ツールを単一の MCP エンドポイントに統合 • インバウンドとアウトバウンドの認証のサポート エージェントが利用するツールの出入り口になるので、アクセス制御が重要 https://github.com/awslabs/amazon-bedrock-agentcore-samples/tree/main/01-tutorials/02-AgentCore-gateway
  59. | 63 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Gateway AgentCore Gateway の アクセス制御 Pub lic AgentCore Gatewayのアクセス制御方法は主に3つ Inbound Auth、 AgentCore Policy、 Gateway Interceptor Inbound Auth AgentCore Policy Gateway Interceptor 普通 かなり細かい 細かい 制御の粒度
  60. | 64 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Gateway AgentCore Gateway の アクセス制御 Pub lic AgentCore Gatewayのアクセス制御方法は主に3つ Inbound Auth、 AgentCore Policy、 Gateway Interceptor Inbound Auth AgentCore Policy Gateway Interceptor Gateway Interceptor を 中心に見る 制御の粒度 普通 細かい かなり細かい
  61. | 65 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Gateway AgentCore Gateway Interceptor Pub lic Gatewayのrequestとresponseに対して介入することができる https://aws.amazon.com/jp/blogs/news/apply-fine-grained-access-control-with-bedrock-agentcore-gateway-interceptors/
  62. | 66 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Gateway AgentCore Gateway Interceptor Pub lic 様々なことが可能で細かいアクセス制御なども可能 AWS re:Invent 2025 - Scale agent tools with Amazon Bedrock AgentCore Gateway (AIM3313)
  63. | 67 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Gateway Interceptorにテナントコンテキストを伝える Pub lic AgentCore Gateway Interceptorにテナントコンテキストを伝える 以下の手順で実施する • GatewayのInbound AuthをCUSTOM_JWTで設定する • JWTにテナントコンテキストを含める • GatewayのinterceptorConfigurationsを設定する • Request InterceptorでTokenからテナントコンテキストを取得する
  64. | 68 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Gateway AgentCore Gateway Interceptor の Inbound Auth 設定 Pub lic GatewayでInboundの認可にCUSTOM_JWTを指定する JWTにテナントコンテキストを含める gateway_response = agentcore_client.create_gateway( .... authorizerType="CUSTOM_JWT", authorizerConfiguration={ "customJWTAuthorizer": "discoveryUrl": "DISCOVERY_URL", "allowedClients": ["CLIENT_ID"] } }, ... )
  65. | 69 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Gateway AgentCore Gateway Interceptor の 設定 Pub lic InterceptorConfigurationsでintetrceptorの設定を行う PassRequestHeadersをTrueにすることでAuthorization HeaderをInterceptorで受け取れる gateway_response = agentcore_client.create_gateway( interceptorConfigurations=[{ "interceptor": {"lambda": {"arn": lambda_arn}}, "interceptionPoints": ["REQUEST"], "inputConfiguration": {"passRequestHeaders": True} }], .... roleArn=iam_response['Role']['Arn'] )
  66. | 70 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Gateway Request Interceptor テナントコンテキストの取得 Pub lic HeadersからJWT tokenを取得し、テナントコンテキストを取得する PyJWTパッケージなどでデコードしてクレームからテナントコンテキストを取得する mcp_data = event.get('mcp', {}) gateway_request = mcp_data.get('gatewayRequest', {}) headers = gateway_request.get('headers', {}) auth_header = headers.get('authorization', '') or headers.get('Authorization', '') decoded = "bearer token をdecodeする処理" tenant_id = decoded["tenant_id"]
  67. | 71 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Gateway AgentCore Gateway への mcp リクエスト Pub lic AgentCore Gateway への mcp リクエストは下記 • tools/list o 使用可能なMCP Tool の一覧を取得する • tools/call o 指定したToolの呼び出し
  68. | 72 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Gateway mcpリクエストへのInterceptorでの介入 Pub lic どのタイミングで介入するかを考える • tools/list o 使用して良いToolとして返却される前にFilterしたい -> Response • tools/call o Toolが実行される前に阻止したい -> Request
  69. | 73 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Gateway AgentCore Gateway Interceptor による制御 Pub lic Gateway Interceptorでの制御を以下のように整理する • Request Interceptor o tools/callに対して介入する o テナントでツール実行が許可されているか確認し、実行を制御する • Reponse Interceptor o tools/listに対して介入する o テナントに許可されたツールか確認し、フィルターした結果を返却する
  70. | 74 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Gateway Request Interceptor の ペイロード Pub lic headersやbodyなどのリクエストの中身が取得できる bodyのmethod から呼び出しの種類を判別できる tools/call -> ツールの呼び出し / tools/list -> ツール一覧の取得 { "interceptorInputVersion": "1.0", "mcp": { "gatewayRequest": { "headers": { "Authorization": "Bearer token...", ... }, "body": { "jsonrpc": "2.0", "method": "tools/list", ... } }, "requestContext": { ... } } }
  71. | 75 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Gateway Request Interceptor の返却値 Pub lic transformedGatewayRequestを含めて返却する必要がある なりすましパターンを避けるため Authorization HeaderのJWT Tokenをそのまま流さないことに注意 return { "interceptorOutputVersion": "1.0", "mcp": { "transformedGatewayRequest": { "headers": { "Accept": "application/json", "Content-Type": "application/json" }, "body": extended_body } } }
  72. | 76 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Gateway Request Interceptor でのツール呼び出し制御 Pub lic methodがtools/call(ツール呼び出し)の場合はテナントコンテキストから呼び出し可否を判断する if method == "tools/call": tool_name = params.get("name", "") if not _is_tool_allowed(tenant_id, tool_name): return { "mcp": { "transformedGatewayResponse": { "statusCode": 403, "headers": {"Content-Type": "application/json"}, "body": ..., } } } テナントが Toolの使用 ができるか 確認する def is_tool_allowed(…): DynamoDB等からtenantの情報取得 tenantの使用可能toolを確認 tool_nameが一覧にあるか確認
  73. | 77 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Gateway Response Interceptor の ペイロード Pub lic gatewayResponseにtargetからのresponseが含まれる "interceptorInputVersion": "1.0", "mcp": { "gatewayRequest": { ... }, "requestContext": { ... }, "gatewayResponse": { "statusCode": 200, "headers": { ... }, "body": { "jsonrpc": "2.0", "result": { "tools": [ ... ] } }}}}
  74. | 78 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Gateway Response Interceptor の 返却値 Pub lic transformedGatewayResponseを返却値に含める { "interceptorOutputVersion": "1.0", "mcp": { "transformedGatewayResponse": { "statusCode": 200, "headers": { ... }, "body": { ... } } } }
  75. | 79 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Gateway Response Interceptor でのツール一覧のフィルター Pub lic TargetからのResponseに対してテナントコンテキストから返却するToolをフィルターする tools = gateway_response['body']['result'].get('tools', []) filtered_tools = filter_tools_by_tenant(tools, tenant_id) return { "interceptorOutputVersion": "1.0", "mcp": { "transformedGatewayResponse": { "statusCode": 200, "headers": { ... }, "body": { "result": { "tools": filtered_tools } }}}} テナントが Toolの使用 ができるか 確認する def filter_tools_by_tenant(…): DynamoDB等からtenantの情報取得 tenantの使用可能toolを確認 Toolsからtenantが使用できるtool のみフィルターして返却
  76. | 80 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. AgentCore Gateway AgentCore Gateway Interceptor の 制御 Pub lic 呼び出し制御 • listTools o Response Interceptorにてテナントに許されたツールのフィルターをかける • InvokeTool o Request Interceptorでテナントのツール呼び出し許可を確認し、実行を制御する
  77. | 81 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. 注意事項 - Quotas 04.
  78. | 82 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. 注意事項 Quotas – AgentCore Identity Pub lic AgentCore Identityのquotas Workload identities1,000 Resource OAuth2 credential providers 50 Resource API Key credential providers 50 上記全て Adjustable NO、つまり上限緩和できない https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/bedrock-agentcore-limits.html
  79. | 83 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. 注意事項 AgentCore Identity の quotasが意味すること Pub lic Workload identities は Runtime や Gateway の生成に合わせ1つ自動生成される Runtimeの数 + Gatewayの数 <= 1,000 API Key, OAuth2による連携先1つにつき、credential providersが少なくとも1つ必要 OAuth2 による認可先 <= 50 API Keyによる認可先 <= 50
  80. | 84 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. 注意事項 想定ユースケース Pub lic SaaSで契約しているテナントごとの接続先を考える テナント A: サービスA, サービスB テナント B: サービスA 同じサービスでもテナントごとに Client IdとClient Secretは異なる テナント x サービスの数だけ credential providersが必要 テナントA テナントB サービス A サービス B サービス A
  81. | 85 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. 注意事項 想定ユースケース Pub lic SaaSで契約しているテナントごとの接続先を考える テナント A: サービスA, サービスB テナント B: サービスA 同じサービスに接続するGateway Targetが複数 • 選択肢 ①: Gatewayに関してはサイロを選択する o Gateway内に似たTargetが存在しないようにする • 選択肢 ②: Gateway Interceptors でツール返却を制限する
  82. | 86 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. 注意事項 テナントごとのサードパーティーサービスへのOAuthアクセス Pub lic 選択肢 ①で考えてみる • テナントごとのサイロ Gateway • テナントごと、サービスごとの Credential Provider
  83. | 87 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. 注意事項 テナントごとのサードパーティーサービスへのOAuthアクセス Pub lic テナントごとに、サードパーティーサービス ごとに Client ID, Client Secretが必要 credential providersの必要数 >= テナント数 x サードパーティーサービス数 quotasを考慮すると以下である必要がある... テナント数 x サードパーティーサービス数 <= 50
  84. | 88 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. 注意事項 テナントごとにサービスにOAuthでアクセスする Pub lic Quotasを考慮すると現時点ではテナントそれぞれが、 外部サービスにOAuthで接続することは難しい.... ワークアラウンド 下記どちらも未検証ですが、考えうる選択肢として... • 1 AWS アカウント 1 テナントのフルスタックサイロ構成 o 少数テナントの間は良いが、テナント数が増えると... o クロスアカウントの制約で何か問題が起きないか... • credential providersと同様の機能を自作する o とはいえ、Workload identitiesのquotasは引き続き問題となる...
  85. | 89 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. 注意事項 サービス設計の際には必ずquotasを確認 Pub lic quotasの中には上限緩和できないものもある サービスの設計にクリティカルに響く場合もある サービスを検討する際は、quotas上問題ないか確認しましょう
  86. | 91 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. まとめ Pub lic • サービスの要件に合わせてリソースごとにプール / サイロ どちらにするか決める • マルチテナントの各種の課題にテナントコンテキストを用いて対処する o データパーティショニング o テナント分離 • テナントコンテキストを含めたJWTはそのままSaaS全体に流すことはしない o なりすましパターンではなく代理実行パターンでトークンを流す • AgentCoreのquotasをよく確認し、サービスの要件に適うか判断する • amazon-bedrock-agentcore-samples サンプルがとても参考になる まとめ
  87. | 94 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. 参考資料 re:Invent 2025 Pub lic • Integration patterns for multi-tenant systems (SAS312) • Building multi-tenant SaaS agents with Amazon Bedrock AgentCore (SAS407) • Transforming from SaaS to multi-tenant agentic SaaS (SAS304) • Using GenAI to profile, scale, and optimize your multi-tenant SaaS architecture • sample-saas-multi-agents-workshop • Workshop Next-gen agentic SaaS: Transforming to an agent-powered experience
  88. | 95 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. 参考資料 AgentCore Pub lic • Amazon Bedrock AgentCore Developer Guide • amazon-bedrock-agentcore-samples
  89. | 96 ©︎ Copyright ExaW iz ards Inc. All Right

    s R es erv ed. 参考資料 SaaS Pub lic • Rethinking SaaS in the Agentic Era - Whitepaper • SaaS アーキテクチャの基礎 AWS ホワイトペーパー • Building multi-tenant architectures for agentic AI on AWS • AWS Well-Architected フレームワーク SaaS レンズ