LoginSignup
6
3

[AWS IAM Identity Center] SSO環境下でAWS CodeCommitの認証を行う

Last updated at Posted at 2023-07-24

※この記事は自分のブログから持ってきたものです。Qiitaにも残しておきたいため投稿しています。

会社などでAWS IAM Identity Center + SSOを使用しているときにちょっと躓いたのでメモ。
AWS Cliなどはインストールしてある前提とする。

環境

Windows + Git for Windows + AWS Cli

1. SSOの設定

コマンドプロンプトで以下を実行
※aws configure sso はGit Bashでは実行できないので注意

aws configure sso

質問にいくつか聞かれるので入力していく。
SSO Start URLなどはAWS IAM Identity Centerポータルページで「Command line or programmatic access」を押すと表示される。

SSO session name (Recommended): <適当な名前>
SSO start URL [None]: <ポータルページで入手したURL>
SSO region [None]: <ポータルページで入手したSSO start URLの次に記載されているリージョンコード>
SSO registration scopes [sso:account:access]: <何も入力せずEnter>

この後、認証ページに飛ばされるので許可する。
許可後、再びいくつか質問されるので入力していく。

CLI default client Region [None]: <デフォルトのリージョンコード 例: ap-northeast-1>
CLI default output format [None]: <何も入力せずEnter>
CLI profile name [<アカウントID>]: <分かりやすいプロファイル名を入力してEnter(後で使います。)>

2. .gitconfigファイルの編集

続いて、ホームフォルダの.gitconfigファイルをテキストエディタなどで開き、以下を追記する。

[credential "https://git-codecommit.<リージョンコード>.amazonaws.com"]
    helper = !aws --profile <CLI profile nameで入力した名前> codecommit credential-helper $@
    UseHttpPath = true

3. 通常通りCloneなどする

あとは通常通りgit cloneを行うことができる。途中、Git Credential Managerというウィンドウが表示されるが×を押して閉じてOK。

トークンの有効期限が切れたら

トークンは永続的ではないので、有効期限を迎えると以下のエラーが表示されることがある。

Error when retrieving token from sso: Token has expired and refresh failed

そのため、コマンドプロンプトで以下のコマンドで実行・再ログインしトークンを更新する。

aws sso login --profile <CLI profile nameで入力した名前>
6
3
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
6
3