Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
API Gateway 認証・認可詳説 / API Gateway authnz details
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
oracle4engineer
PRO
May 31, 2022
Technology
2.2k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
API Gateway 認証・認可詳説 / API Gateway authnz details
oracle4engineer
PRO
May 31, 2022
More Decks by oracle4engineer
See All by oracle4engineer
Deep Data Security 機能解説
oracle4engineer
PRO
1
45
Oracle Cloud Infrastructure:2026年6月度サービス・アップデート
oracle4engineer
PRO
0
66
Oracle AI Databaseデータベース・サービスのメンテナンス(BaseDB/ExaDB-D/ExaDB-XS)
oracle4engineer
PRO
4
1.6k
Oracle AI Database@Google Cloud:サービス概要のご紹介
oracle4engineer
PRO
6
1.5k
Oracle AI Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
6
2k
Oracle AI Database@AWS:サービス概要のご紹介
oracle4engineer
PRO
4
3k
CrossplaneによるCloud Native Control Plane
oracle4engineer
PRO
0
110
OCI Oracle AI Database Services新機能アップデート(2026/03-2026/05)
oracle4engineer
PRO
0
460
Oracle Cloud Infrastructure IaaS 新機能アップデート 2026/3 - 2026/5
oracle4engineer
PRO
1
310
Other Decks in Technology
See All in Technology
いまさら聞けない「仕様駆動開発入門」 〜AI活用時代の開発プロセスを考える〜
findy_eventslides
2
160
FinOps × AIエージェントで実現する コストインシデントの自動調査
oasis1994liveforever
0
150
自宅LLMの話
jacopen
1
610
Android の公式 Skill / Android skills
yanzm
0
150
ACE-Step-1.5で見る 音楽生成AIのしくみと“破綻だけ直す”Retake機能の開発【zennfes spring 2026 登壇資料】
personabb
1
530
2026TECHFRESH畢業分享會 - Lightning Talk - 資料也要 CI/CD? 用 Airbyte 自動化資料同步
line_developers_tw
PRO
0
1.2k
中期計画、2回作ってみた ~業務委託と正社員、両方の視点から~
demaecan
1
940
日本 Fintech 未来予測レポート 2027〜2028年(手動編集版)
8maki
0
2.4k
自律型AIエージェントは何を破壊するのか
kojira
0
160
AWS Security Hub CSPMの成功・失敗体験
cmusudakeisuke
0
130
10年間のブログ発信を振り返って見えたWebアプリケーションエンジニアとしての軌跡
stefafafan
0
130
エラーバジェットのアラートのタイミングを考える.pdf
kairim0
0
160
Featured
See All Featured
The World Runs on Bad Software
bkeepers
PRO
72
12k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Facilitating Awesome Meetings
lara
57
7k
The Curse of the Amulet
leimatthew05
1
13k
Art, The Web, and Tiny UX
lynnandtonic
304
22k
Utilizing Notion as your number one productivity tool
mfonobong
4
320
Become a Pro
speakerdeck
PRO
31
6k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Making Projects Easy
brettharned
120
6.7k
Efficient Content Optimization with Google Search Console & Apps Script
katarinadahlin
PRO
1
630
BBQ
matthewcrist
89
10k
Context Engineering - Making Every Token Count
addyosmani
9
970
Transcript
API Gateway – 認証・認可詳説 Subhead goes here on one line
Name 日本オラクル株式会社 May, 2022
API Gatewayを活用したWeb APIに対する認証・認可処理 • API Gatewayの機能を活用することで、各アプリケーションに実装していた認証・認可処理をオフロード • バックエンド実行基盤は、よりビジネスロジックに集中できる • API
Gatewayで一元管理することで、認証強度や鍵のライフサイクル管理を統一できる Copyright © 2022, Oracle and/or its affiliates 2 User Functions Functions Functions ビジネスロジック + 認証・認可処理 ビジネスロジック + 認証・認可処理 ビジネスロジック + 認証・認可処理 API Gateway User Functions Functions Functions ビジネスロジック ビジネスロジック ビジネスロジック API Gateway 認証・認可処理を API Gatewayにオフロード
API Gatewayで行われる認証・認可処理の基本的な動き 1. エンドユーザーが認証・認可のために必要な情報(ID/Password, JWT, etc.)含めてリクエストを送信 2. API Gatewayにて、認証やJWTの検証処理が行われる。方法は以下の2通り。 •
Oracle Functionsで実装したロジック(Authorizer Functions)を用いて、認証を行う • 設定値に基づき、JWT(JSON Web Token)の検証を行う 3. 認証結果、検証済みのJWTに含まれるscopeを用いて、各パス単位に認可処理を行う • スキップ(認可処理を実行しない)も可能 Copyright © 2022, Oracle and/or its affiliates 3 User Functions Functions Functions API Gateway 1. 資格情報、JWT 2. 資格情報を用いて認証や JWTの検証処理を行う 3. 各パス単位にscopeを 用いた認可処理 list:greet create:greet update:greet delete:greet list:greet list:greet create:greet create:greet create:greet
Authorizer Function • HTTPリクエスト(ヘッダー or クエリーパラメーター) に含まれる情報を認証処理を行うOracle Functions(Authorizer Functions)へ渡し、検証す る事で認証処理を行う
• (オプション)返却された認証結果に含まれるscope を用いて認可処理を行う JWT Validator • HTTPリクエスト(ヘッダー or クエリーパラメーター) に含まれるJWTをAPI Gatewayで検証する • (オプション)検証済みのJWTに含まれているscope を用いて、認可処理を行う 提供されている認証・認可のための機能 Copyright © 2022, Oracle and/or its affiliates 4 Functions Functions Functions API Gateway Functions Functions Functions API Gateway Functions Identity Provider JWKs Endpoint Public Key 認証依頼 認証結果 (オプション)認証結果に含まれる scopeを用いて認可処理 JWTの検証 - 署名の検証 - Issuerの検証 - Audienceの検証 - 有効期限の検証 - etc. (オプション)検証済みJWTのPayloadに 含まれるscopeを用いて認可処理 Identity Domains/IDCS Auth0 Okta Keycloak etc.
Copyright © 2022, Oracle and/or its affiliates 5 Authorizer Functions
Authorizer Functionsを用いた処理のシーケンス Copyright © 2022, Oracle and/or its affiliates 6
Enduser API Gateway Oracle Functions Backend 資格情報を送信 -H “xxx: <Credential>” or https://xxx?yyy=<Credential> API Gatewayから既定の形式で 認証処理のリクエスト 認証処理 API Gatewayへ既定の形式で 認証結果のレスポンス 認証処理失敗: HTTP 401 検証成功: バックエンドへリクエスト 認可処理失敗: HTTP 404 認可処理
Authorizer Functionsを用いた処理のシーケンス Copyright © 2022, Oracle and/or its affiliates 7
Enduser API Gateway Oracle Functions Backend 資格情報を送信 -H “xxx: <Credential>” or https://xxx?yyy=<Credential> API Gatewayから既定の形式で 認証処理のリクエスト 認証処理 API Gatewayへ既定の形式で 認証結果のレスポンス 認証処理失敗: HTTP 401 I/Fが定められている 検証成功: バックエンドへリクエスト 認可処理失敗: HTTP 404 認可処理
Authorizer FunctionsのI/F Copyright © 2022, Oracle and/or its affiliates 8
User Functions API Gateway -H “xxx: <Credential>” or https://xxx?yyy=<Credential> API Gatewayからの入力形式 { “type”: “TOKEN”, “token”: “<Credential>” } 認証スキームも含められるため、 Functions側でハンドリングする 認証処理に失敗した場合: { “active”: false, “expiresAt”: “<date-time>”, “context”: {“<key>”: “<value>”,…}, “wwwAuthenticate”: “<directive>” } 認証処理に成功した場合: { “active”: true, “principal”: ”<user-principal>”, “scope”: [“<scopes>”], “clientId”: “<clientId>”, “expiresAt”: “<date-time>”, “context”: {“<key>”: “<value>”,…} }
* active: true • 認証処理が正常に終了したことを示す * principal: <user-principal> • ユーザ名、アプリケーション名
* scope: [<scopes>] • コール元が実行を許可されている操作 • 認可処理で使用される clientId: <clientId> • ホスト名、クライアントIP、etc. * expiresAt: <date-time> • 認証結果の有効期限(ISO-8601) • 認証結果のキャッシュ期間の決定に使用される context: {<key>: <value>, …} • APIデプロイメントで使用する任意のデータ(key-value形式) • ${request.auth[<context-key>]}の形式で使用 *: 返却必須項目 例 Oracle FunctionsがAPI Gatewayに返却する結果(正常系) Copyright © 2022, Oracle and/or its affiliates 9 { "active": true, "principal": "https://example.com/users/jdoe", "scope": [ "list:hello", "read:hello", "create:hello", "update:hello", "delete:hello", "someScope" ], "clientId": "host123", "expiresAt": "2019-05-30T10:15:30+01:00", "context": { "email": "
[email protected]
" } }
* active: false • 認証処理が失敗したことを示す * expiresAt: <date-time> • 認証結果の有効期限(ISO-8601)
• 認証結果のキャッシュ期間の決定に使用される context: {<key>: <value>, …} • APIデプロイメントで使用する任意のデータ(key-value形式) • ${request.auth[<context-key>]}の形式で使用 * wwwAuthenticate: <directive> • 検証が失敗した場合に、クライアントに返却される wwwAuthenticateヘッダの値。リソースへのアクセス権を取得す る方法(認証タイプ等)を返却する。 *: 返却必須項目 例 Oracle FunctionsがAPI Gatewayに返却する結果(異常系) Copyright © 2022, Oracle and/or its affiliates 10 { "active": false, "wwwAuthenticate": "Bearer realm=¥"example.com¥"“ "expiresAt": "2019-05-30T10:15:30+01:00", "context": { "email": "
[email protected]
" } }
scopeを用いた認可処理 Copyright © 2022, Oracle and/or its affiliates 11 Functions
Functions Functions API Gateway list: hello create: hello update: hello delete: hello someScope someScope dummyScope Authorizer Functionsから返却された認証結果 各ルーティングパス毎の許可されるscopeの設定 設定されたscopeの内容を 少なくとも一つ含む事を確認
認可タイプ 概要 任意 設定したスコープが少なくとも一つ含まれている場合、認証済みのエンドユーザーに対してアクセス権 を付与する 匿名 認証済みでないエンドユーザーに対してもアクセス権を付与する(※認証ポリシーで匿名アクセスの 有効化オプションが必要) 認証のみ 認可処理を実行しない(認証済みエンドユーザーであればアクセス権を付与する)
認可ポリシー Copyright © 2022, Oracle and/or its affiliates 12
public AuthorizerResponse handleRequest(AuthorizerRequest authorizerRequest) { // request validation if (!TYPE.equals(authorizerRequest.getType())
|| authorizerRequest.getType() == null) { var response = new AuthorizerResponse(); response.setActive(false); response.setWwwAuthenticate("Basic realm=¥"foo¥""); return response; } if ("".equals(authorizerRequest.getToken()) || authorizerRequest.getToken() == null || !authorizerRequest.getToken().startsWith(TOKEN_PREFIX)) { var response = new AuthorizerResponse(); response.setActive(false); response.setWwwAuthenticate("Basic realm=¥"foo¥""); return response; } // token validation var adminCredential = new String(Base64.getUrlEncoder().encode(String.format("%s:%s", ADMIN_USER, ADMIN_PASSWORD) .getBytes(StandardCharsets.UTF_8))); var inputToken = authorizerRequest.getToken().substring(TOKEN_PREFIX.length()); if (!adminCredential.equals(inputToken)) { var response = new AuthorizerResponse(); response.setActive(false); response.setWwwAuthenticate("Basic realm=¥"foo¥""); return response; } var response = createResponse(inputToken); return response; } Authorizer Functionsの実装例 Copyright © 2022, Oracle and/or its affiliates 13 独自の認証ロジックを実装することで、様々な方式 に対応することができる。
参考: 設定の解説 Copyright © 2022, Oracle and/or its affiliates 14
カスタムを選択する 作成済みの認証処理を行う Oracle Functionsを選択する ヘッダー or クエリーパラメーター パラメータ名を指定する 匿名ユーザー(未認証なエンドユーザー)が APIデプロイメント内のパスにアクセス可能かどうかを示す
Copyright © 2022, Oracle and/or its affiliates 15 JWT Validator
JSON Web Token • jot(ジョット) と発音することが RFC 7519 で推奨されている •
スペースに制約のある環境を想定したコンパクトなクレームの表現方法 • JSONをURL-safeな形でコンパクトにエンコードしたもの • コンパクトにするという目的で省略形が使われることが多い (e.g. audience → aud) • JOSE(JavaScript Object Signing and Encryption)と呼ばれる仕様群の一つ • JWS (JSON Web Signature) - RFC 7515 • JWE (JSON Web Encryption) - RFC 7516 • JWK (JSON Web Key) - RFC 7517 • JWA (JSON Web Algorithms) - RFC 7518 • JWT (JSON Web Token) - RFC 7519 JSON Web Token Copyright © 2022, Oracle and/or its affiliates 16
JWT Validator Copyright © 2022, Oracle and/or its affiliates 17
Enduser API Gateway Identity Provider Backend JWTを送信 -H “xxx: eyJ…” or https://xxx?yyy=eyJ... 公開鍵の要求* 公開鍵の返却* 検証失敗: HTTP 401 検証成功: バックエンドへリクエスト 認可処理失敗: HTTP 404 JWTの検証処理 JWKs Endpoint 認可処理 - 署名の検証 - Issuerの検証 - Audienceの検証 - 有効期限の検証 - etc. *: 実行時に動的に公開鍵を取得しない方法も可能
署名とPayloadに含まれるクレームの検証が実行される JWT Validator – JWTの検証処理 Copyright © 2022, Oracle and/or
its affiliates 18 { "user_tz": "Asia/Tokyo", "sub": "
[email protected]
", "iss": "https://identity.oraclecloud.com/", "client_id": "tokenGenerator", "sub_type": "user", "client_tenantname": "idcs-oracle", "region_name": "us-phoenix-idcs-1", "user_lang": "en", "exp": 1651052900, "iat": 1651049300, "user_displayname": "Hoge Hoge", "aud": [ "https://example.com/", "https://console:9245" ], "scope": "list:hello create:hello update:hello delete:hello someScope" ... 省略 ... } JWTのPayload例(※一部抜粋) 発行時刻(iat)と有効期限(exp)を 元にJWTの有効期限の確認
検証済みのJWTのPayloadに含まれるクレーム(scope)とAPI Gatewayに設定済みのスコープを元に認可処理を行う JWT Validator – 認可処理 Copyright © 2022, Oracle
and/or its affiliates 19 { ... 省略 ... "scope": "list:hello create:hello update:hello delete:hello someScope" ... 省略 ... } JWTのPayload例(※一部抜粋) 少なくとも一つ 含まれることを検証
参考: 設定の解説(1/3) Copyright © 2022, Oracle and/or its affiliates 20
JWTを選択する ヘッダー or クエリーパラメーター パラメータ名を指定する 匿名ユーザー(未認証なエンドユーザー)が APIデプロイメント内のパスにアクセス可能かどうかを示す
参考: 設定の解説(2/3) Copyright © 2022, Oracle and/or its affiliates 21
JWTの発行者(Issuer/iss)を指定する(各IdP固有の値) JWTの発行先(audience/aud)を指定する • リモートJWKS: APIの実行時にIdPから公開されているJWKs Endpointを実行し、公開鍵を取得する • 静的キー: 事前発行済みの公開鍵を設定する
参考: 設定の解説(3/3) Copyright © 2022, Oracle and/or its affiliates 22
IdPとAPI Gatewayの間のシステム・クロックに差分が予想される場合に、指定する 指定した値は、JWTの有効期限の算出に考慮される iss/aud以外で、JWT検証に含めたいクレームが存在する場合にその内容を指定する
Identity Provider iss aud JWKs Endpoint IDCS https://identity.oraclecl oud.com/ 顧客固有
https://<tenant-base- url>/admin/v1/Signing Cert/jwk OKTA https://<your-okta- tenant-name>.com 顧客固有 https://<your-okta- tenant- name>.com/oauth2/<a uth-server-id>/v1/keys Auth0 https://<your-account- name>.auth0.com/ 顧客固有 https://<your-account- name>.auth0.com/.well -known/jwks.json 参考: iss, aud, JWKs Endpointの一例 Copyright © 2022, Oracle and/or its affiliates 23
Copyright © 2022, Oracle and/or its affiliates 24 Thank you
None