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

AWS_CLIでSSOする裏側を覗いてみた.pdf

Avatar for Yuto Anada Yuto Anada
October 23, 2025
510

 AWS_CLIでSSOする裏側を覗いてみた.pdf

Avatar for Yuto Anada

Yuto Anada

October 23, 2025
Tweet

Transcript

  1. 準備 • AWS Organizations で IAM Identity Center を有効にする •

    IAM Identity Center ユーザを作成(edu-jaws-lt-user) edu-jaws-lt-user 組織
  2. 今回紹介する処理フロー • 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
  3. PKCE(Proof Key for Code Exchange)とは ・OAuth2.0の拡張仕様(基本的なフローは同じ) ・AWS CLI バージョン 2.22.0

    以降では、デフォルトで使用 OAuth2.0: リソースへのアクセス許可を示す、accessTokenの取得フロー PKCE: その取得フローをより安全に行うための仕様
  4. クライアント登録(例) 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)
  5. クライアント登録(例) 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に書き込む
  6. 認可コードの取得 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
  7. 認可コードの取得 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
  8. アクセストークンの取得(例) 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)
  9. 設定ファイルの作成 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に設定内容を 書き込む
  10. 一時クレデンシャルを取得 IAM Identity Centerの リージョナルエンドポイント AWS CLI botocore accountId: xxxxxx

    roleName: AdministratorAccess accessToken: xxxxxx 「一時クレデンシャルをください」
  11. 一時クレデンシャルを取得 AWS CLI botocore accessKeyId: "xxxxxx" secretAccessKey: "xxxxxx" sessionToken: "xxxxxx"

    IAM Identity Centerの リージョナルエンドポイント ~/.aws/cli/cacheに書き込む