LoginSignup
0
1

More than 1 year has passed since last update.

API Gateway - Lambda構成でのアクセス制御方法 メモ

Last updated at Posted at 2022-04-17
  • API Gateway - Lambda構成のサーバーレスアプリケーションにおけるアクセス制御方法についてメモする。

IAMアクセス権限パターン

api_gc_iam.png

  1. IAM Credential sigv4 を作成し、sigv4を含めてAPIリクエスト
  2. sigv4の権限を検証する。
  3. 問題ない場合はLambdaをコールする。

Amazon Cognito UserPoolを利用する

api_gc_cognito.png

  1. ユーザーサインアップ(トークン取得)する。
  2. トークンを含めてAPIリクエストする。
  3. トークン検証し、Lambdaコールする。

Lambda Authorizer

api_gc_auth.png

  1. クライアントから認証トーク ンやパラメータ付きのリクエストを行う。

  2. Authorizer 関数をコールする。

    • Authorizer 関数内で認証認可ロジックを評価

    • 評価結果ポリシーを返却

      • 成功例

        {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Action": "execute-api:Invoke",
              "Effect": "Allow",
              "Resource": "arn:aws:execute-api:us-east-1:123456789012:ivdtdhp7b5/ESTestInvoke-stage/GET/"
            }
          ]
        }
        
      • 失敗例

        {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Action": "execute-api:Invoke",
              "Effect": "Deny",
              "Resource": "arn:aws:execute-api:us-east-1:123456789012:ivdtdhp7b5/ESTestInvoke-stage/GET/"
            }
          ]
        }
        
  3. API Gateway が返却されたポ リシーを評価し、APIロジック用Lambdaをコールする。

Private API

api_gc_private.png

  • 特定VPCからのリクエストのみを受け付ける場合、VPCエンドポイント経由アクセスする。

    • API Gatewayのリソースポリシーで制御する。

      {
          "Version": "2012-10-17",
          "Statement": [
              {
                  "Effect": "Allow",
                  "Principal": "*",
                  "Action": "execute-api:Invoke",
                  "Resource": [
                      "execute-api:/*"
                  ]
              },
              {
                  "Effect": "Deny",
                  "Principal": "*",
                  "Action": "execute-api:Invoke",
                  "Resource": [
                      "execute-api:/*"
                  ],
                  "Condition" : {
                      "StringNotEquals": {
                         "aws:SourceVpc": "vpc-1a2b3c4d"
                      }
                  }
              }
          ]
      }
      

参考情報

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1