Open9

privateリポジトリに変更したらcapistranoのデプロイでこけるようになった

ダン@HyperFormダン@HyperForm

エラーメッセージ

git:check
      01 git ls-remote https://[my_personal_api_token]:@github.com/my-organization/ssr.git HEAD
      01 remote: Invalid username or password.
      01 fatal: Authentication failed for 'https://[my_personal_api_token]:@github.com/my-organization/ssr.git/'
#<Thread:0x000055c59e5a1270 /usr/local/bundle/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:10 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
        13: from /usr/local/bundle/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
        12: from /usr/local/bundle/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:31:in `run'
        11: from /usr/local/bundle/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:31:in `instance_exec'
        10: from /usr/local/bundle/gems/capistrano-3.14.1/lib/capistrano/scm/tasks/git.rake:18:in `block (3 levels) in eval_rakefile'
         9: from /usr/local/bundle/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:100:in `with'
         8: from /usr/local/bundle/gems/capistrano-3.14.1/lib/capistrano/scm/tasks/git.rake:19:in `block (4 levels) in eval_rakefile'
         7: from /usr/local/bundle/gems/capistrano-3.14.1/lib/capistrano/scm/git.rb:40:in `check_repo_is_reachable'
         6: from /usr/local/bundle/gems/capistrano-3.14.1/lib/capistrano/scm/git.rb:79:in `git'
         5: from /usr/local/bundle/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:80:in `execute'
         4: from /usr/local/bundle/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:148:in `create_command_and_execute'
         3: from /usr/local/bundle/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:148:in `tap'
         2: from /usr/local/bundle/gems/sshkit-1.21.0/lib/sshkit/backends/abstract.rb:148:in `block in create_command_and_execute'
         1: from /usr/local/bundle/gems/sshkit-1.21.0/lib/sshkit/backends/netssh.rb:170:in `execute_command'
/usr/local/bundle/gems/sshkit-1.21.0/lib/sshkit/command.rb:97:in `exit_status=': git exit status: 128 (SSHKit::Command::Failed)
git stdout: Nothing written
git stderr: remote: Invalid username or password.
fatal: Authentication failed for 'https://[my_personal_api_token]:@github.com/my-organization/ssr.git/'
        1: from /usr/local/bundle/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:11:in `block (2 levels) in execute'
/usr/local/bundle/gems/sshkit-1.21.0/lib/sshkit/runners/parallel.rb:15:in `rescue in block (2 levels) in execute': Exception while executing as vpsuser@order.ssr-makasero.co.jp: git exit status: 128 (SSHKit::Runner::ExecuteError)
git stdout: Nothing written
git stderr: remote: Invalid username or password.
fatal: Authentication failed for 'https://[my_personal_api_token]:@github.com/my-organization/ssr.git/'
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as vpsuser@order.ssr-makasero.co.jp: git exit status: 128
git stdout: Nothing written
git stderr: remote: Invalid username or password.
fatal: Authentication failed for 'https://[my_personal_api_token]:@github.com/my-organization/ssr.git/'


Caused by:
SSHKit::Command::Failed: git exit status: 128
git stdout: Nothing written
git stderr: remote: Invalid username or password.
fatal: Authentication failed for 'https://[my_personal_api_token]:@github.com/my-organization/ssr.git/'

Tasks: TOP => deploy:check => git:check
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as vpsuser@order.ssr-makasero.co.jp: git exit status: 128
git stdout: Nothing written
git stderr: remote: Invalid username or password.
fatal: Authentication failed for 'https://[my_personal_api_token]:@github.com/my-organization/ssr.git/'


** DEPLOY FAILED
** Refer to log/capistrano.log for details. Here are the last 20 lines:

Invalid username or passwordでgithubへの接続が拒否されていることが分かる。

ダン@HyperFormダン@HyperForm

GitHub上でprivate→publicに戻したら、今まで通りデプロイできるようになった。

privateにしたらcapistranoからgithubに接続できなくなる

ダン@HyperFormダン@HyperForm
  • 自分のリポジトリではなく、organization上のリポジトリ
  • 開発当初は自分のリポジトリで管理していたものを、途中からorganizationに移動した
  • 自分の個人アカウントで発行したPersonal API Tokenをデプロイ時に利用している
ダン@HyperFormダン@HyperForm

懸念ポイント1

organizationを使うと、個人アカウントで発行したPersonal API Tokenを使ったデプロイはできなくなる?

→別プロジェクト(他の人がデプロイ周りの設定をした)でPersonal API Tokenを使ったデプロイを普通にしている。Personalっていうくらいだからorganization単位で発行できるものではなさそう。だからここに原因がある可能性は低そう。

ダン@HyperFormダン@HyperForm

懸念ポイント2

シンプルにprivateリポジトリにした場合のGitHubへの接続自体できていない?

→ pullとかして試せば分かる。
→ pullは普通にできた
→ Pushもできたっぽい(Everything up-to-date)

じゃあこれも違うか

ダン@HyperFormダン@HyperForm

あーPushとPullできるのは、PushとPullはhttpでやってて、デプロイはSSHで接続してるからっぽいな

ダン@HyperFormダン@HyperForm

organizationのSettings > Deploy keys > Add deploy key
に公開鍵をセットしようとしたら

Key is already in useというエラーが表示された