LoginSignup
2
3

More than 3 years have passed since last update.

CodeCommit でfatal: not foundと表示される場合の対処法

Last updated at Posted at 2020-12-19

結論から言うと認証情報がおかしく設定されていたことが原因でしたので、調査方法と対応法を共有します。
下記の記事を参考にして解決することができましたが、この記事ではもう少し調査方法等を詳しく書いてみます。
@izanariさんありがとうございます。
https://qiita.com/izanari/items/8094612d7de7b9b172ef

やろうとしたこと

CodeCommitでリポジトリを作ってhttpsでアクセスしようとしました。詳しくは下記を参照下さい。
https://docs.aws.amazon.com/ja_jp/codecommit/latest/userguide/setting-up-git-remote-codecommit.html

今回はmac OS Catalina (10.15.6)で検証しております。

事象:CodeCommitで作成したRepositoryにアクセスできない

リポジトリの作成は完了していざcloneをしようとしたところ、下記のエラーに直面しました。

codecommit_error.log
$ git clone https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/hogehoge

Cloning into 'AWSBasicTrainingCourse'...
fatal: repository 'https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/hogehoge' not found

やっていることはgit cloneしているだけですが、not foundのエラーが帰ってきています。

原因:以前別のリポジトリにアクセスした際の認証情報が意図せず読み込まれている。

osxkeychainに記録されている情報が勝手に読み込まれていました。
このソフトはmacプリインストールのユーティリティソフトです。
gitの設定でこれが読み込まれる設定となっていたため、別のアカウントにあるリポジトリの情報が読み込まれた状態でアクセスされていました。

その結果、
 1. 別のアカウント用の認証情報で認証される
 2. 別のアカウントにアクセスする
 3. アカウント内でhogehogeリポジトリを探す
 4. 存在しないためnot foundを返す
という挙動になっていたようです。

osxkeychain.png

調査

aws cliの情報を疑う

本来であれば、httpsでgit cloneすると下記のように対話型でuserとpasswordを聞かれるはずですが、今回は聞かれないままnot foundが返ってきました。

git_clone_by_https
$ git clone https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/hogehoge

Cloning into 'hogehoge'...
Username for 'https://git-codecommit.ap-northeast-1.amazonaws.com': 
Password for 'https://[Username]@git-codecommit.ap-northeast-1.amazonaws.com':

そのため認証情報がおかしいというアイディアがありましたが、gitの認証情報がどこかから読み込まれているとは思わず、まずはaws cliの情報を確認してみます。aws configure listで今使わているデフォルトの認証情報が見れます。

aws_configure
user $ aws configure list

      Name                    Value             Type    Location
      ----                    -----             ----    --------
   profile                <not set>             None    None
access_key                <not set>             None    None
secret_key                <not set>             None    None
    region                <not set>             None    None

Noneになっているので問題ないと判断しました。

git cloneの詳細なエラーを確認してみる。

git cloneの詳細なエラーを確認するためには、GIT_CURL_VERBOSE=1をコマンド冒頭に加えれば良いです。
かなり長いログになりますが、401を見つけたのでこの部分を追ってみます。

detail_log
GIT_CURL_VERBOSE=1 git clone https://git-codecommit.ap-northeast-1.amazonaws.com/v1/repos/hogehoge

~~~~~中略~~~~~~
< HTTP/1.1 401
< x-amzn-RequestId: 132ferenu-hogehoge
< WWW-Authenticate: Basic realm=""
< Content-Type: text/xml
< Content-Length: 95
< Date: Sat, 1 Jan 2020 00:00:00 GMT

~~~~~中略~~~~~~
* Server auth using Basic with user 'username'

ということでusernameの情報で接続されていることがわかりましたが、これは意図していないものでした。

gitの認証情報を確認する。

ここからは記事にしたがって調べて行きました。
user.nameとcredential.helperが怪しいということで確認。

$git config user.name
shoheihosaka

$git config credential.helper
osxkeychain

user.nameにも値が設定されていましたが、上記エラーで確認したusernameとは違っていたため一旦無視。
credential.helperにはosxkeychainに設定されていたためこいつの値を確認してみることにしました。

解決:キーチェーンアクセスを使って、osxkeychainの値を削除する。

osxkeychainの値の確認はキーチェーンアクセスでGUIから確認できます。
こちらを確認したところついにエラーで出力されたusernameを発見したため、この情報を削除したところ正しく動きました。

参考

今回のリポジトリはシンプルに下記のコマンドで作成しております。

aws codecommit create-repository --repository-name MyDemoRepo --repository-description "My demonstration repository" --tags Team=Saanvi

2
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
2
3