0
0

AWS SSOの設定

Last updated at Posted at 2024-07-24

AWS ECR(Elastic Container Registry)のプライベートリポジトリにDockerイメージをプッシュするまでの手順を記録します。手順はAWS CLIのインストール、AWSアカウントの作成、IAM Identity Centerでユーザーの追加・設定、AWS SSOの設定、Amazon ECRでDockerイメージのプッシュに分けます。無料枠での利用を想定しています。

環境

  • CentOS7
  • Dockerはインストール済み

手順

1. AWS CLIのインストール 
2. AWSアカウントの作成
3. IAM Identity Centerでユーザーの追加・設定
4. AWS SSOの設定(本記事)
5. Amazon ECRでDockerイメージのプッシュ

AWS SSOの設定

SSO(シングルサインオン)とは

ユーザーが 1 回限りのユーザー認証で複数のアプリケーションやウェブサイトにログインできるようにする認証ソリューション

AWS IAM Identity Center credentialsを取得

  • AWSアクセスポータルにログインする
    • AWSアクセスポータルのURLはパスワード設定で受け取るメール本文中に記載がある
  • トップ画面から「Access keys」をクリックする
  • 「Get Credentials for <許可セット名>」の画面が表示されるので、現在使用しているOSの種類をタブから選択する。本記事は「macOS and Linux」を選択

SSO認証情報の登録

  • 下記コマンドを実行し、任意の「SSO session name」、「SSO start URL」、「SSO region」、「SSO registration scopes」を入力する
    • 「SSO start URL」と「SSO Region」は「Get Credentials for <許可セット名>」の「AWS IAM Identity Center credentials (Recommended)」配下の記載内容を写す
    • 「SSO registration Scopes」は本記事内容に該当する「Access IAM Identity Center managed accounts and permission sets」は「sso:account:access」を入力する。その他は記事下部「参考」の「Access Scope」のリンク先で調べる
$ aws configure sso
SSO session name (Recommended): <セッション名>
SSO start URL [None]: https://my-sso-portal.awsapps.com/start # 「Get Credentials for PowerUserAccess」の「SSO start URL」の内容を入力
SSO region [None]: us-east-1  # 「Get Credentials for PowerUserAccess」の「SSO Region」の内容を入力
SSO registration scopes [None]: sso:account:access
  • デフォルトのブラウザが開くので、表示されているコードを確認
  • ターミナルで出力されたコードと同じことを確認し、「confirm and continue」をクリックする
...
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.ap-northeast-1.amazonaws.com/

Then enter the code:

ZMJR-GFFB
  • 下記の画面が表示されるので「Allow access」をクリックする
  • 下記の画面で「Request approved」のメッセージを確認し、画面を閉じる
  • ターミナルの出力に従い、「client Region」、「output format」、任意の「profile name」を入力する
    • 「client Region」:コマンド実行の対象とするリージョン
    • 「output format」:コマンド実行結果の出力形式(AWS CLIはjson/yaml/YAMLストリーム形式/text/tableをサポート)
CLI default client Region [None]: ap-northeast-1 
CLI default output format [None]: json
CLI profile name [PowerUserAccess-XXXXXXXX]: <任意のプロフィール名>
  • 下記の出力が確認できれば、設定が完了したことが確認できる
To use this profile, specify the profile name using --profile, as shown:

aws s3 ls --profile <設定したプロフィール名>
  • 入力した内容でconfigファイルが作成されているので、下記のコマンドで内容を確認する
$ cat ~/.aws/config
[profile <設定したプロフィール名>]
sso_session = <設定したssoセッション名>
sso_account_id = 123456789011
sso_role_name = readOnly
region = ap-northeast-1
output = json

[sso-session <設定したssoセッション名>]
sso_region = us-east-1
sso_start_url = https://my-sso-portal.awsapps.com/start
sso_registration_scopes = sso:account:access

ログインとログアウトを確認

  • 下記のコマンドを実行し、ログインに進む
$ aws sso login --profile <設定したプロフィール名>
  • デフォルトのブラウザが開き、コードが表示されるのでターミナルで出力されたコードと同じかを確認して「Confirm and continue」をクリックする
  • ターミナルで「Successfully logged into Start URL」の表示が確認できればログイン完了
Successfully logged into Start URL: https:XXXXXXX.awsapps.com/start/#
  • 下記のコマンドを実行し、ログアウトする
$ aws sso logout

参考

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