🔖

AWSログイン方法比較

に公開

概要

AWSログイン方法が複数あるので比較。
Identity Center(3番目)が最もセキュアで管理が容易だが、AWS Organizationsの設定が必要。
一方、個人や小規模チームではaws-vaultの採用、CI/CDやアプリケーション連携では従来のIAMユーザーが現実的。

ログイン方法

  • IAMユーザーでのログイン(通常の方法)
  • IAMユーザーでのログイン(aws-vaultを使用)
  • AWS SSO(IAM Identity Center)でのログイン

ログイン方法の比較

機能 通常のIAM aws-vault Identity Center
セキュリティ 基本的 高(暗号化保存) 最高(キー不要)
設定の手間 多(Organizations必要)
複数アカウント管理 困難 容易 最適
CI/CD連携 容易 容易 やや複雑
MFA対応 要追加設定 容易 標準搭載

IAMユーザーでのログイン(通常の方法)

特徴

  • アクセスキーとシークレットキーを直接設定
  • 設定が最もシンプル
  • アクセスキーの漏洩リスクあり
  • 複数アカウントの切り替えが面倒

ユースケース

  • CI/CDパイプライン
  • アプリケーションからのAWS API呼び出し
  • バッチ処理やクローラー

手順

% aws configure --profile user1
AWS Access Key ID [None]: 
AWS Secret Access Key [None]: 
Default region name [None]: 
Default output format [None]:

% aws s3 ls --profile user1

保存入力内容は~/.aws/credentials,~/.aws/configに保存される

IAMユーザーでのログイン(aws-vaultを使用)

特徴

  • https://github.com/99designs/aws-vault を用いた方法
  • アクセスキーをOSのキーチェーン/クレデンシャルストアで暗号化保管
  • MFAの統合が容易
  • 複数アカウントの切り替えが便利
  • 一時的なセッショントークンを使用

ユースケース

  • 個人開発
  • 小規模チーム
  • Organizationsを使わない複数アカウント管理

手順

% brew install aws-vault --cask
% aws-vault add user1
# MFAの設定例
% aws-vault add --mfa-token 123456 user1

% cat ~/.aws/config
[profile user1]
region = us-east-1
output = json

% aws-vault exec user1 -- aws s3 ls

AWS SSO(IAM Identity Center)でのログイン

特徴

  • アクセスキーの保管が不要
  • シングルサインオンで複数アカウント管理
  • ブラウザベースの認証
  • 権限管理が中央化
  • MFAがデフォルトで利用可能

ユースケース

  • 複数アカウントの一元管理
  • セキュリティ要件の厳しい環境
  • ユーザーライフサイクル管理が必要な場合

手順

  • 任意のregionでidentity centerを作成、ユーザーの割り当て
  • identity centerからAWS access portal URLを取得: SSO start URL割り当て時に利用
% aws configure sso
SSO start URL [None]: https://xxx.awsapps.com/start # identity centerから取得したもの
SSO Region [None]: us-east-1 # identity centerのregion
Attempting to automatically open the SSO authorization page in your default browser.
If the browser does not open or you wish to use a different device to authorize this request, open the following URL:

https://device.sso.us-east-1.amazonaws.com/

Then enter the code:

XXXX-XXXX
There are 2 AWS accounts available to you.
Using the account ID XXXX
The only role available to you is: AdministratorAccess
Using the role name "AdministratorAccess"
CLI default client Region [us-east-1]:
CLI default output format [json]:
CLI profile name [AdministratorAccess-XXXX]: user1

To use this profile, specify the profile name using --profile, as shown:

aws s3 ls --profile user1

# 2回目
% aws sso login --profile user1

Discussion