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
AWS_CLIでSSOする裏側を覗いてみた.pdf
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Yuto Anada
October 23, 2025
640
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
AWS_CLIでSSOする裏側を覗いてみた.pdf
Yuto Anada
October 23, 2025
Featured
See All Featured
Prompt Engineering for Job Search
mfonobong
0
350
A Modern Web Designer's Workflow
chriscoyier
698
190k
Being A Developer After 40
akosma
91
590k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.7k
Chasing Engaging Ingredients in Design
codingconduct
0
220
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
390
Bash Introduction
62gerente
615
220k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
170
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
310
Making Projects Easy
brettharned
120
6.7k
Transcript
AWS CLIでSSOする裏側を 覗いてみた 穴田悠人 Education-JAWS #5
自己紹介 ・穴田悠人(あなだゆうと) ・早稲田大学 情報系の修士2年 ・趣味:バドミントン、走る
AWSリソース操作の方法 • マネジメントコンソール • IaC • AWS SDK(プログラム) • AWS
CLI ・・・
AWS CLIからリソース操作する方法 • IAM Identity Centerのユーザを作成して、一時クレデンシャルを使用 ◦ 自動的に取得(推奨) ◦ 手動で取得
• IAMロールを引き受ける • IAMユーザの長期クレデンシャルを使用(非推奨) …
準備 • AWS Organizations で IAM Identity Center を有効にする •
IAM Identity Center ユーザを作成(edu-jaws-lt-user) edu-jaws-lt-user 組織
今回紹介する処理フロー • aws configure sso コマンド ◦ IAM Identity Center
プロファイルを設定 ◦ アクセストークンの取得 • aws s3 ls コマンド ◦ (一時クレデンシャルの取得) ◦ アカウントが所有するS3バケットの一覧を取得 sso_session = edu-jaws-lt sso_account_id = xxxxxx sso_role_name = AdministratorAccess region = ap-northeast-1 output = json
aws configure ssoの流れ • クライアント登録 • 認可コードの取得 • アクセストークンの取得 •
IAM Identity Center プロファイルの作成 PKCEベースのフロー
PKCE(ピクシー)とは
PKCE(Proof Key for Code Exchange)とは ・OAuth2.0の拡張仕様(基本的なフローは同じ) ・AWS CLI バージョン 2.22.0
以降では、デフォルトで使用 OAuth2.0: リソースへのアクセス許可を示す、accessTokenの取得フロー PKCE: その取得フローをより安全に行うための仕様
OAuth2.0の考え方 (実際のフローとは異なる)
誰でも操作できる状態 NG Aさん Bさん Cさん
アクセス トークン 認可サーバが発行 Aさん Bさん Cさん
アクセス トークン 検証 Aさん Bさん Cさん
アクセス トークン 検証 Aさん Bさん Cさん
操作を実行 レスポンス Aさん Bさん Cさん
aws configure ssoコマンドの挙動
クライアント登録 OIDCサーバー AWS CLI botocore 登録します。 clientIdとclientSecretをください。
クライアント登録 AWS CLI botocore clientId: xxxxxx clientSecret: xxxxxx(期限つき) OIDCサーバー
クライアント登録(例) OIDCサーバー AWS CLI botocore POST /client/register { "clientName": "botocore-client-xxxxxx",
"clientType": "public", "grantTypes": [ "authorization_code", "refresh_token" ], "issuerUrl": "https://d-xxxxxx.awsapps.com/start", "redirectUris": [ "http://127.0.0.1/oauth/callback" ], "scopes": [ "sso:account:access" ] } ※赤は必須パラメータ (https://oidc.ap-northeast-1.amazonaws.com)
クライアント登録(例) OIDCサーバー AWS CLI botocore (https://oidc.ap-northeast-1.amazonaws.com) { "authorizationEndpoint": "null", "clientId":
"xxxxxx", "clientIdIssuedAt": xxxxxx, "clientSecret": "xxxxxx", "clientSecretExpiresAt": xxxxxx, "tokenEndpoint": "null" } ~/.aws/sso/cacheに書き込む
認可コードの取得 OIDCサーバー AWS CLI ブラウザ 立ち上げる ブラウザ AWS CLI botocore
ローカル サーバー http://127.0.0.1:54321
認可コードの取得 OIDCサーバー AWS CLI ブラウザ 立ち上げる ブラウザ OIDCサーバー client_id: xxxxxx
認可コード返送先:http://127.0.0.1:1234/oauth/callback アクセススコープ: sso:account:access code_challenge_method: S256 code_challenge: xxxxxx 「認可コードを取得したいです」 AWS CLI botocore ローカル サーバー http://127.0.0.1:54321
認可コードの取得 OIDCサーバー AWS CLI ブラウザ 立ち上げる ブラウザ OIDCサーバー client_id: xxxxxx
認可コード返送先:http://127.0.0.1:1234/oauth/callback アクセススコープ: sso:account:access code_challenge_method: S256 code_challenge: xxxxxx PKCE特有の合言葉 AWS CLI botocore ローカル サーバー http://127.0.0.1:54321
認可コードの取得 OIDCサーバー AWS CLI ブラウザ 「認証画面」 AWS CLI botocore ローカル
サーバー http://127.0.0.1:54321
認可コードの取得 OIDCサーバー AWS CLI ブラウザ 検証 AWS CLI botocore ローカル
サーバー http://127.0.0.1:54321
認可コードの取得 OIDCサーバー AWS CLI ブラウザ 「OK」 AWS CLI botocore ローカル
サーバー http://127.0.0.1:54321
認可コードの取得 OIDCサーバー AWS CLI ブラウザ 「許可してください」 AWS CLI botocore ローカル
サーバー http://127.0.0.1:54321
認可コードの取得 OIDCサーバー AWS CLI ブラウザ AWS CLI botocore ローカル サーバー
http://127.0.0.1:54321
認可コードの取得 OIDCサーバー AWS CLI ブラウザ 「http://127.0.0.1:1234にリダイレクトして」 「認可コードはxxxxxx」 AWS CLI botocore
ローカル サーバー http://127.0.0.1:54321
認可コードの取得 OIDCサーバー AWS CLI botocore ブラウザ 「認可コードはxxxxxx」 ローカル サーバー http://127.0.0.1:54321
認可コードの取得 OIDCサーバー AWS CLI ブラウザ 「画面閉じてOK」 AWS CLI botocore ローカル
サーバー http://127.0.0.1:54321
アクセストークンの取得 OIDCサーバー AWS CLI botocore 認可コードはxxxxxxです。 合言葉はxxxxxxです。 「アクセストークンをください」
アクセストークンの取得 OIDCサーバー AWS CLI botocore 認可コードはxxxxxxです。 合言葉はxxxxxxです。 認可コードのリクエスト元と 同じである証明 「アクセストークンをください」
アクセストークンの取得 AWS CLI botocore accessToken: xxxxxx refreshToken: xxxxxx OIDCサーバー
アクセストークンの取得 AWS CLI botocore accessToken: xxxxxx refreshToken: xxxxxx OIDCサーバー 有効期限の短いaccessTokenの
再発行に必要 ~/.aws/sso/cacheに書き込む
アクセストークンの取得(例) OIDCサーバー AWS CLI botocore POST /token { "clientId": "xxxxxx",
"clientSecret": "xxxxxx", "code": "xxxxxx”, "codeVerifier": "xxxxxx”, "grantType": "authorization_code", "redirectUri": "http://127.0.0.1:57342/oauth/callback", } ※赤は必須パラメータ (https://oidc.ap-northeast-1.amazonaws.com)
アクセストークンの取得(例) OIDCサーバー AWS CLI botocore (https://oidc.ap-northeast-1.amazonaws.com) { "accessToken": "xxxxxx", "expiresIn":
3600, "idToken": null, "refreshToken": "xxxxxx", "tokenType": "Bearer" }
利用可能なアカウント一覧 IAM Identity Centerの リージョナルエンドポイント AWS CLI botocore アクセストークンはxxxxxxです。 利用可能なアカウントを教えて。
GET /assignment/accounts
利用可能なアカウント一覧 AWS CLI botocore Aアカウント、Bアカウントが 使えます IAM Identity Centerの リージョナルエンドポイント
利用可能なロール一覧 IAM Identity Centerの リージョナルエンドポイント AWS CLI botocore アクセストークンはxxxxxxです。 Aアカウントで利用可能なロールを教
えて。 GET /assignment/roles
利用可能なロール一覧 AWS CLI botocore AdministratorAccessと ReadOnlyAccess です IAM Identity Centerの
リージョナルエンドポイント
設定ファイルの作成 AWS CLI botocore [profile edu-jaws-lt] sso_session = edu-jaws-lt sso_account_id
= xxxxxx sso_role_name = AdministratorAccess region = ap-northeast-1 output = json [sso-session edu-jaws-lt] sso_start_url = https://d-xxxxxx.awsapps.com/start sso_region = ap-northeast-1 sso_registration_scopes = sso:account:access ~/.aws/configに設定内容を 書き込む
aws s3 ls(S3バケットの一覧)
一時クレデンシャルを取得 IAM Identity Centerの リージョナルエンドポイント AWS CLI botocore accountId: xxxxxx
roleName: AdministratorAccess accessToken: xxxxxx 「一時クレデンシャルをください」
一時クレデンシャルを取得 AWS CLI botocore accessKeyId: "xxxxxx" secretAccessKey: "xxxxxx" sessionToken: "xxxxxx"
IAM Identity Centerの リージョナルエンドポイント ~/.aws/cli/cacheに書き込む
S3バケット一覧を取得 AWS CLI botocore secretAccessKeyなど SigV4による 署名値の計算 署名
S3バケット一覧を取得 S3のリージョナル エンドポイント AWS CLI botocore 「S3バケット一覧をください」 署名 リクエスト accessKeyId、
sessionToken含む
S3バケット一覧を取得 AWS CLI botocore Bucket 1、Bucket 2 です S3のリージョナル エンドポイント
まとめ • AWS CLIのSSOでは、PKCE(OAuth2.0の拡張仕様)を使用 • リソース操作では、SigV4による署名つきリクエストを行う • 今日紹介した流れは、aws configure sso
--debug でぜひお手元で確認してみてく ださい!
[参考]API仕様 ・RegisterClient(クライアント登録) https://docs.aws.amazon.com/ja_jp/singlesignon/latest/OIDCAPIReference/API_RegisterClient.html ・CreateToken(アクセストークン発行) https://docs.aws.amazon.com/ja_jp/singlesignon/latest/OIDCAPIReference/API_CreateToken.html ・ListAccounts(利用可能なアカウント一覧) https://docs.aws.amazon.com/ja_jp/singlesignon/latest/PortalAPIReference/API_ListAccounts.html ・ListAccountRoles(利用可能なロール一覧) https://docs.aws.amazon.com/ja_jp/singlesignon/latest/PortalAPIReference/API_ListAccountRoles.html ・GetRoleCredentials(一時クレデンシャル発行)
https://docs.aws.amazon.com/ja_jp/singlesignon/latest/PortalAPIReference/API_GetRoleCredentials.html