LoginSignup
5
0

More than 3 years have passed since last update.

AWS SSOを使ってCodeCommitを利用する

Posted at

はじめに

メモとして残しておきます。

参考

https://docs.aws.amazon.com/ja_jp/codecommit/latest/userguide/setting-up-https-unixes.html
https://docs.aws.amazon.com/ja_jp/codecommit/latest/userguide/temporary-access.html

前提

SSOでログインするときに使用するIAMロールが、CodeCommitへの操作権限を持っていること
AWS CLIとgitコマンドをインストールされていること

手順

認証情報ヘルパーを設定する
Git 認証情報ヘルパーがAWS 認証情報を使用するように設定する

git config --global credential.helper '!aws codecommit credential-helper $@'
git config --global credential.UseHttpPath true

アクセスキー、シークレットアクセスキー、トークンを設定する
SSOの画面で「Commandline or Programatic access」をクリック
image.png

Option1をコピーしてTerminalにペースト
image.png

git cloneしてみる

$ git clone https://git-codecommit.us-west-2.amazonaws.com/v1/repos/my-repo
Cloning into 'my-repo'...
$ 

完了

おまけ

Macの場合、しばら作業しててgit pushしようとしたときに「fatal: unable to access 'https://git-codecommit.us-west-2.amazonaws.com/v1/repos/my-repo/': The requested URL returned error: 403」のようなエラーが発生することがあります。
これは、CodeCommitが発行する認証情報が15分で無効になるが、gitコマンドが使用するkeychainユーティリティが無効になった認証情報を使ってアクセスを試行するために発生します。
AWSマニュアルに対応方法の記載があります。

対策1 gitコマンドがKeychainユーティリティを使わないようにする
1 Keychainユーティリティを開いて、CodeCommitの認証情報を検索する
image.png

2 対象の認証情報をダブルクリックする
3 git-credential-osxkeychainを削除する
image.png

4 gitコマンドを実行すると、keychainを使用するかのダイアログがでるのでDenyをクリックする
image.png
5 gitコマンドが使える

上記だと毎回ダイアログでDenyをクリックしないといけない

対策2 osxkeychainを使わないようにする or 使用する対象をしぼる

sudo emacs /Library/Developer/CommandLineTools/usr/share/git-core/gitconfig

使わないようにする。以下のテキストの行をコメントアウトします。

# helper = osxkeychain

対象をしぼる。この例は、github.comに制限している。

[credential "https://github.com"]
   helper = osxkeychain

参考
https://docs.aws.amazon.com/ja_jp/codecommit/latest/userguide/setting-up-https-unixes.html
https://docs.aws.amazon.com/ja_jp/codecommit/latest/userguide/troubleshooting-ch.html

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