LoginSignup
22
23

More than 1 year has passed since last update.

saml2awsでSAML認証を用いたaws cliの利用を簡単にした

Last updated at Posted at 2018-07-13

はじめに

皆さんはAWS マネジメントコンソールへのログインどうされていますか?
弊社では最近GSuite SAML認証を使ってコンソールへログインしています。

GSuiteにログインしているだけでAWSにもログインできて大変便利なんですが一つだけ大きなデメリットがあり、それが… aws cliがとても使いづらい!という問題でした。
(AWS STSの一時的認証情報の期限が切れるたびにGSuiteとごにょごにょして一時的認証情報を取得し直す必要があるorz)

ですが、いろいろ探してみるとsaml2awsという便利ツールがあったので紹介です。golangで実装されています。

saml2awsが対応しているIDプロバイダー

  • One of the supported Identity Providers
    • ADFS (2.x or 3.x)
    • PingFederate + PingId
    • Okta
    • KeyCloak + (TOTP)
    • Google Apps
  • AWS SAML Provider configured

インストール方法

OSXインストール方法
brew tap versent/homebrew-taps
brew install saml2aws
Windowsインストール方法
choco install saml2aws
saml2aws --version

設定手順

まずはsaml認証の設定です。

項目名 設定値
provider GoogleApps
AWS Profile awsコマンドで利用するprofile名
URL https://accounts.google.com/o/saml2/initsso?idpid=XXXXXXX&spid=YYYYY&forceauthn=false
※ saml認証用のURL
Username GSuiteユーザー名
Password GSuiteパスワード
Confirm パスワード確認

今回は上記内容を対話式で設定します。

% saml2aws configure -a test_idp_account
? Please choose a provider: GoogleApps
? AWS Profile test_profile

? URL https://accounts.google.com/o/saml2/initsso?idpid=XXXXXXX&spid=YYYYY&forceauthn=false
? Username test_user@example.com

? Password ****
? Confirm ****

account {
  URL: https://accounts.google.com/o/saml2/initsso?idpid=XXXXXXX&spid=YYYYY&forceauthn=false
  Username: test_user@example.com
  Provider: GoogleApps
  MFA: Auto
  SkipVerify: false
  AmazonWebservicesURN: urn:amazon:webservices
  SessionDuration: 3600
  Profile: test_profile
}

Configuration saved for IDP account: test_idp_account

次に先程設定した認証情報でログインしてみます。


% saml2aws login -a test_idp_account
Using IDP Account test_idp_account to access GoogleApps https://accounts.google.com/o/saml2/initsso?idpid=XXXXXXX&spid=YYYYY
To use saved password just hit enter.
? Username test_user@example.com
? Password ****

Authenticating as test_user@example.com ...
? Security Token [000000] 000000
Selected role: arn:aws:iam::000000000000:role/GSuite
Requesting AWS credentials using SAML assertion
Logged in as: arn:aws:sts::000000000000:assumed-role/GSuite/test_user@example.com

Your new access key pair has been stored in the AWS configuration
Note that it will expire at 2018-07-13 19:03:14 +0900 JST
To use this credential, call the AWS CLI with the --profile option (e.g. aws --profile test_profile ec2 describe-instances).

これで無事プロファイルが作成されました!
(ちなみに2018/7/13現在、GSuiteでMFA(2段階認証)を設定してると日本環境ではエラーになってしまいます。。ですが、私の方でworkaroundではありますが日本環境で動くように修正してプルリクエスト送ってます。続報をまて! 2018/7/14にマージされました)

aws cliで使ってみる


aws --profile test_profile ec2 describe-instances --region ap-northeast-1                                  
{
    "Reservations": [
        {
            "Groups": [],
            "Instances": [
                {

                .
                .
                .

簡単にコマンド使えるようになりました。便利!

22
23
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
22
23