1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

これは何?

AWS-CLIを使って認証する方式をまとめたもの


この記事について

noai_small.png


前提

AWS CLIのインストールは完了している前提。


🙅非推奨: IAM Userでアクセスする場合

  1. AWSのコンソールからIAMユーザを作成する。この際にアクセスキーとシークレットキーをメモっておく
  2. クレデンシャルを設定する
aws configure
# regionはデフォルトは最も近い場所,outputはjsonにしておく
~/.aws/config
[hoge1] # 任意の値
region = ap-northeast-1
output = json
~/.awx/credentials
[hoge1] # ~/.awx/configにあわせる
aws_access_key_id = AKxxxxxxxxxxxxxxxxxx
aws_secret_access_key = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  1. 疎通確認
aws sts get-caller-identity --profile hoge1

補足: スイッチロールしたい場合

  1. スイッチロール元のクレデンシャルと同じものを使う。~/.aws/credentialsはそのままで良い。
  2. AWSコンソールからスイッチロール元のアカウントにログインしてIAMユーザの設定を行う。
  3. 新しいprofileを~/.aws/configに追加する
~/.aws/config
[profile hoge1]
region = ap-northeast-1
output = json
# 追加したプロファイル
[profile fuga] # 好きな名前をつける
region = ap-northeast-1
role_arn = arn:aws:iam::<スイッチロール後のAWSアカウントID>:role/<Role名>
mfa_serial = arn:aws:iam::<スイッチロール元のAWSアカウントID>:mfa/<MFAのdevice name> # 必要な場合のみ
source_profile = hoge1 # hoge1で設定されてる ~/.aws/credentialsを使う
  1. 疎通確認
aws sts get-caller-identitiy --profile fuga

🙆推奨: アクセスキーを使わずにIAM Identity Centerを使う

  1. AWSコンソールからブラウザにアクセスし、IAM Identity Centerの設定ページから「AWS access portal URL」
  2. SSOを使用した設定を行う。設定すると~/.aws/configに追加される
aws configure sso
SSO session name (Recommended): test
SSO start URL [None]: https://xxxxxxxxx.awsapps.com/start
SSO region [None]: ap-northeast-1
SSO registration scopes [sso:account:access]:
  1. ~/.aws/configからプロファイル名を調べる
~/.aws/config
[profile AdministratorAccess-xxxxxxxxxx]
sso_session = test
sso_account_id = xxxxxxxxxx
sso_role_name = AdministratoAccess
[sso-session test]
sso_start_url = https://xxxxxxxx.awsapps.com/start
sso_region = ap-northeast-1
sso_registration_scopes = sso:account:access
  1. 疎通確認
aws sts get-caller-identitiy --profile AdministratorAccess-xxxxxxxxxx

補足: 上記を試した環境について

いわゆるおひとりさまOrganizationsというやつ。SSOするならついでにOrganizationsにしてもいいじゃないという発想。無料だし

以下は作業内容(抜粋)

  1. Organizationsを有効にする
  2. IAM Identity Centerのセットアップ
    • コンソールから有効にする
    • ユーザの作成 --> aws configure ssoした際やブラウザ経由でコンソールにログインする時に使うユーザ
    • groupの作成
    • 許可セットの作成(Administorator Accessをとりあえずつけた。あまり良くないかも)
    • 許可セットをAWSのアカウントに紐付ける(許可セットの画面から行える)
      • この際に作成したgroupに紐づけする
    • MFAを有効化する
    • IAM Identity Centerの設定ページからAWS access portal URLをメモしておく。

aws configure ssoした

参考: GitHub ActionsでSSOしたい場合

TODO: SSO + スイッチロール

使ったことがないので後で書く


後書き

結構いろんなパターンがありそうなので網羅してかくの大変そうなので一旦こんなもんで

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?