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

Amazon Verified Permissionsをプロダクトにどう組み込むかを考える

Yodeee
November 15, 2023
80

Amazon Verified Permissionsをプロダクトにどう組み込むかを考える

Yodeee

November 15, 2023
Tweet

Transcript

  1. Amazon Verified Permissions (AVP) • 2023/6 GA • アプリケーション上のアクセス許可ルールの管理と 認可の機能を提供

    • 認可ルールをビジネスロジックから切り離し、 責務の分離とルールの一元管理が可能に
  2. Amazon Verified Permissions (AVP) • 2023/6 GA • アプリケーション上のアクセス許可ルールの管理と 認可の機能を提供

    • 認可ルールをビジネスロジックから切り離し、 責務の分離とルールの一元管理が可能に 正直、あまりイメージわかない
  3. Cognito ① 認 証 IDト ー ク ン ② GET

    /users 例としてユーザ管理サービスを考える アイディティティプロバイダーとしてCognitoを使用 Backend Lambda ③Cognito Authorizer トークン検証 EC2 ECS ・・・ AVP登場前のアプリケーション構成 • 認可判定 • 業務ロジック API Gateway ④ Role: Editor カスタム属性情報として、ロール情報を管理
  4. Cognito ① 認 証 IDト ー ク ン ② GET

    /users AVP登場前はバックエンドに細かい認可処理を実装する必要があった Backend ③Cognito Authorizer トークン検証 AVP登場前のアプリケーション構成 • 認可判定 • 業務ロジック API Gateway ④ Role: Editor if (role === "editor") { if (resource === "users") { if (method === ”GET”) { return ”ALLOW"; } . . . } } if (role == "viewer") { . . . } if (role === "admin") { . . . }
  5. API Gateway Cognito Role: Editor • 認可判定 • AVP認可要求 •

    業務ロジック Verified Permissions 1. バックエンド側でAVPを呼び出し認可判定を行うパターン GET /users トークン検証 認可判定 Backend IDト ー ク ン 認 証
  6. API Gateway Cognito Role: Editor • 認可判定 • AVP認可要求 •

    業務ロジック Verified Permissions 1. バックエンド側でAVPを呼び出し認可判定を行うパターン GET /users トークン検証 認可判定 Backend IDト ー ク ン Verified Permissions Cedar言語で認可ルールを定義 認可ロジックはLambdaからAVPのポリシーに移譲 認 証
  7. API Gateway Cognito Role: Editor • 認可判定 • AVP認可要求 •

    業務ロジック Verified Permissions 1. バックエンド側でAVPを呼び出し認可判定を行うパターン 認 証 GET /users トークン検証 認可判定 Backend IDト ー ク ン Verified Permissions Cedar言語で認可ルールを定義 バックエンドでは認可ロジックの実装の代わりに AVP呼出、認可判定結果のハンドリング処理の実装が必要 const client = new VerifiedPermissionsClient(); const result = await client.send( new IsAuthorizedWithTokenCommand({ identityToken: idToken, . . . }) ); return result.decision // ”ALLOW” or “DENY”
  8. API Gateway Cognito Role: Editor Verified Permissions Lambda Authorizer 2.

    Lambda Authorizerに認可処理を集約するパターン Cognito Authorizerが自動で行っていたトークン検証を含めて実装が必要となる 認 証 GET /users IDト ー ク ン Backend ①トークン検証 ②認可判定 try { // トークン検証(Cognito) const verifier = CognitoJwtVerifier.create(...); await verifier.verify(idToken); // 認可判定(Verified Permissions) const client = new VerifiedPermissionsClient(); const result = await client.send( new IsAuthorizedWithTokenCommand({ . . . }) ); if (result === "DENY") { throw new Error("Unauthorized"); } return generatePolicy("user", "Allow” ...); } catch (error) { . . . ※AWS公式から下記のトークン検証用のライブラリが提供 aws-jwt-verify(Node.js用): https://github.com/awslabs/aws-jwt-verify ② ① Lambda Authorizerの実装例(一部抜粋)
  9. 参考 • Amazon Verified Permissions関連 • Amazon Verified Permissions のご紹介

    https://pages.awscloud.com/rs/112-TZM-766/images/20230126_26th_ISV_DiveDeepSeminar_verified_permissions.pdf • Amazon Verified Permissionsを利用した 責務の分割のメリット・デメリット https://speakerdeck.com/kaminashi/advantages-and-disadvantages-of-separation-of-responsibilities-using-amazon-verified-permissionsCognito • Amazon Verified Permissionsで、APIの認可処理を実装する https://catalog.workshops.aws/verified-permissions-in-action/en-US • ハンズオン資料 https://catalog.workshops.aws/verified-permissions-in-action/en-US • 認証・認可関連 • 一番分かりやすいOAuthの説明 https://qiita.com/TakahikoKawasaki/items/e37caf50776e00e733be • 一番分かりやすい OpenID Connect の説明 https://qiita.com/TakahikoKawasaki/items/498ca08bbfcc341691fe • OAuth 2.0/OpenID Connectの2つのトークンの使いみち https://qiita.com/TakahikoKawasaki/items/498ca08bbfcc341691fe