という名前の Docker コンテナーで実行される Drone から SSH コマンドを機能させるために、私はあまりにも長い間試みてきましたbb
。RUN echo " IdentityFile /root/.ssh/id_rsa" >> /etc/ssh/ssh_config
他のスレッドのいくつかの推奨事項に従って、Dockerfile に追加しました。
以前はdocker run -it bb /bin/bash
SSH キーが存在することを確認していましたが、そのインタラクティブ ターミナルを使用してリモート ホストに SSH で正常に接続できました。
.drone.yml
ただし、次のようなビルド スクリプトを使用して同じコマンドを実行しようとすると、次のようになります。
image: bb
script:
- whoami
- ssh -vvv -t -t 192.0.2.1 "whoami"
...パスワードベースの識別にぶつかった後、「許可が拒否されました」というエラーが表示されます。(whoami
はコンテナー内で実行され、 が出力root
され、コマンドに進みssh
ます。)
詳細な出力を次の関連する部分に要約しました。
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /root/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug2: input_userauth_pk_ok: fp f2:...
debug3: sign_and_send_pubkey: RSA f2:...
debug1: key_parse_private2: missing begin marker
debug1: read PEM private key done: type RSA
debug1: Authentications that can continue: publickey,password
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
...「パケットを送信しなかったため、メソッドを無効にします」と明確に記載されています。キーのフィンガープリントを確認したssh-keygen -lf /root/.ssh/id_rsa
ところ、出力のフィンガープリントと一致しました。
次に、リモート ホストで認証ログ ( /var/log/auth.log
) を監視し、テストが成功したことを確認できますが、Drone がコンテナーを実行すると、ログに「RSA_public_decrypt が失敗しました」と報告されます。ここにログがあります。
成功した (対話型コンテナー) ログイン:
Accepted publickey for root from 192.0.2.1 port 59472 ssh2: RSA f2:...
pam_unix(sshd:session): session opened for user root by (uid=0)
Received disconnect from 192.0.2.1: 11: disconnected by user
pam_unix(sshd:session): session closed for user root
失敗した (ドローン コンテナー) ログイン:
error: RSA_public_decrypt failed: error:04067084:lib(4):func(103):reason(132)
Failed password for root from 192.0.2.1 port 54172 ssh2
Failed password for root from 192.0.2.1 port 54172 ssh2
Connection closed by 192.0.2.1 [preauth]
したがって、私のキーは Drone コンテナから送信されていないようです。ビルド スクリプトを実行whoami
したところ、 として実行されていると報告されましたroot
。
どうすればこれを機能させることができますか?