権限のないLXCゲストからsshdに接続できません。何をすべきか?

権限のないLXCゲストからsshdに接続できません。何をすべきか?

したがって、以下を定義して、許可されていないLXCゲストを設定しました。

lxc.id_map = u 0 1000000000 10000
lxc.id_map = g 0 1000000000 10000

もちろん、これらの子UID / GID範囲を既存のユーザー(usermod --add-sub-uids ...)に割り当てます。

しかし、次のようなssh host結果が出るたびに:

Read from socket failed: Connection reset by peer

ただし、ゲストの内部では、sshd実行中の項目をはっきりと見ることができます(例:を使用してlsof -i :22)。

何が間違っている可能性がありますか?

ベストアンサー1

OpenSSHに関する一般的なトラブルシューティングのアドバイス

まずは皆さんにおすすめですこの短いトラブルシューティングガイドsshd私はそれをレシピに何度も使用します。

プロットが厚くなる

この場合の唯一の違いは、lxc-consoleゲストに接続してログインして実行を停止し、デフォルトのsshdポート22でインスタンスを起動したことです。次に、より詳細な方法でホストからゲストに接続します。

$ ssh -vvvvvvvv host.lan
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /home/joe/.ssh/config
debug1: /home/joe/.ssh/config line 2: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to host.lan [10.0.3.223] port 22.
debug1: Connection established.
debug1: identity file /home/joe/.ssh/id_rsa type -1
debug1: identity file /home/joe/.ssh/id_rsa-cert type -1
debug1: identity file /home/joe/.ssh/id_dsa type -1
debug1: identity file /home/joe/.ssh/id_dsa-cert type -1
debug1: identity file /home/joe/.ssh/id_ecdsa type -1
debug1: identity file /home/joe/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/joe/.ssh/id_ed25519 type -1
debug1: identity file /home/joe/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2 pat OpenSSH_6.6.1* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug3: load_hostkeys: loading entries for host "host.lan" from file "/home/joe/.ssh/known_hosts"
debug3: load_hostkeys: found key type ED25519 in file /home/joe/.ssh/known_hosts:7
debug3: load_hostkeys: loaded 1 keys
debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],ssh-ed25519
debug1: SSH2_MSG_KEXINIT sent
Read from socket failed: Connection reset by peer

まあ、この出力には何も判明していません。接続試行のサーバー側出力を見てみましょう。

# $(which sshd) -Dddddddp22
debug2: load_server_config: filename /etc/ssh/sshd_config
debug2: load_server_config: done config len = 724
debug2: parse_server_config: config /etc/ssh/sshd_config len 724
debug3: /etc/ssh/sshd_config:5 setting Port 22
debug3: /etc/ssh/sshd_config:9 setting Protocol 2
debug3: /etc/ssh/sshd_config:11 setting HostKey /etc/ssh/ssh_host_rsa_key
debug3: /etc/ssh/sshd_config:12 setting HostKey /etc/ssh/ssh_host_dsa_key
debug3: /etc/ssh/sshd_config:13 setting HostKey /etc/ssh/ssh_host_ed25519_key
debug3: /etc/ssh/sshd_config:15 setting UsePrivilegeSeparation yes
debug3: /etc/ssh/sshd_config:18 setting KeyRegenerationInterval 3600
debug3: /etc/ssh/sshd_config:19 setting ServerKeyBits 1024
debug3: /etc/ssh/sshd_config:22 setting SyslogFacility AUTH
debug3: /etc/ssh/sshd_config:23 setting LogLevel INFO
debug3: /etc/ssh/sshd_config:26 setting LoginGraceTime 120
debug3: /etc/ssh/sshd_config:27 setting PermitRootLogin without-password
debug3: /etc/ssh/sshd_config:28 setting StrictModes yes
debug3: /etc/ssh/sshd_config:30 setting RSAAuthentication yes
debug3: /etc/ssh/sshd_config:31 setting PubkeyAuthentication yes
debug3: /etc/ssh/sshd_config:35 setting IgnoreRhosts yes
debug3: /etc/ssh/sshd_config:37 setting RhostsRSAAuthentication no
debug3: /etc/ssh/sshd_config:39 setting HostbasedAuthentication no
debug3: /etc/ssh/sshd_config:44 setting PermitEmptyPasswords no
debug3: /etc/ssh/sshd_config:48 setting ChallengeResponseAuthentication no
debug3: /etc/ssh/sshd_config:51 setting PasswordAuthentication no
debug3: /etc/ssh/sshd_config:63 setting X11Forwarding yes
debug3: /etc/ssh/sshd_config:64 setting X11DisplayOffset 10
debug3: /etc/ssh/sshd_config:65 setting PrintMotd no
debug3: /etc/ssh/sshd_config:66 setting PrintLastLog yes
debug3: /etc/ssh/sshd_config:67 setting TCPKeepAlive yes
debug3: /etc/ssh/sshd_config:74 setting AcceptEnv LANG LC_*
debug3: /etc/ssh/sshd_config:76 setting Subsystem sftp /usr/lib/openssh/sftp-server
debug3: /etc/ssh/sshd_config:87 setting UsePAM yes
debug1: sshd version OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug3: Incorrect RSA1 identifier
debug3: Incorrect RSA1 identifier
debug3: Could not load "/etc/ssh/ssh_host_rsa_key" as a RSA1 public key
debug1: private host key: #0 type 1 RSA
debug3: Incorrect RSA1 identifier
debug3: Incorrect RSA1 identifier
debug3: Could not load "/etc/ssh/ssh_host_dsa_key" as a RSA1 public key
debug1: private host key: #0 type 1 RSA
debug3: Incorrect RSA1 identifier
debug3: Incorrect RSA1 identifier
debug3: Could not load "/etc/ssh/ssh_host_dsa_key" as a RSA1 public key
debug1: private host key: #1 type 2 DSA
debug3: Incorrect RSA1 identifier
debug3: Incorrect RSA1 identifier
debug3: Could not load "/etc/ssh/ssh_host_ed25519_key" as a RSA1 public key
debug1: private host key: #2 type 4 ED25519
debug1: rexec_argv[0]='/usr/sbin/sshd'
debug1: rexec_argv[1]='-Dddddddp22'
debug3: oom_adjust_setup
Set /proc/self/oom_score_adj from 0 to -1000
debug2: fd 3 setting O_NONBLOCK
debug1: Bind to port 22 on 0.0.0.0.
Server listening on 0.0.0.0 port 22.
debug2: fd 4 setting O_NONBLOCK
debug3: sock_set_v6only: set socket 4 IPV6_V6ONLY
debug1: Bind to port 22 on ::.
Server listening on :: port 22.
debug3: fd 5 is not O_NONBLOCK
debug1: Server will not fork when running in debugging mode.
debug3: send_rexec_state: entering fd = 8 config len 724
debug3: ssh_msg_send: type 0
debug3: send_rexec_state: done
debug1: rexec start in 5 out 5 newsock 5 pipe -1 sock 8
debug1: inetd sockets after dupping: 3, 3
Connection from 10.0.3.1 port 51448 on 10.0.3.223 port 22
debug1: Client protocol version 2.0; client software version OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
debug1: match: OpenSSH_6.6.1p1 Ubuntu-2ubuntu2 pat OpenSSH_6.6.1* compat 0x04000000
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
debug2: fd 3 setting O_NONBLOCK
debug2: Network child is on pid 558
debug3: preauth child monitor started
debug3: privsep user:group 101:65534 [preauth]
setgroups: Invalid argument [preauth]
debug1: do_cleanup [preauth]
debug3: PAM: sshpam_thread_cleanup entering [preauth]
debug1: monitor_read_log: child log fd closed
debug3: mm_request_receive entering
debug1: do_cleanup
debug3: PAM: sshpam_thread_cleanup entering
debug1: Killing privsep child 558

上記の出力で次の行に特に注意してください。

debug1: Killing privsep child 558

UsePrivilegeSeparation yesOpenSSHの権限分離機能(設定ディレクティブ)にいくつかの問題があることを示します。

debug3: privsep user:group 101:65534 [preauth]
setgroups: Invalid argument [preauth]

プロセスの有効 GID を 65534 に変更しようとする試みを示します。

コンテナ構成の確認

次に、コンテナ構成ファイルのスタンザをもう一度見てください。

lxc.id_map = u 0 1000000000 10000
lxc.id_map = g 0 1000000000 10000

これはLXCへのユーザーネームスペース()、グループID、ユーザーIDは1000000000から始まり、それぞれ10000個のIDです。この名前空間内で、UID 1000000000はスーパーユーザーである0になります。

解決策

実際、この問題には2つの解決策があります。

  1. コンテナ構成を変更し、マップ範囲で少なくとも65535のスレーブIDを許可します。または
  2. UsePrivilegeSeparation no構成オプションの設定sshd_config

背景

スクリプトcontainer-userns-convertLaunchpadでホスト(表示bzr branch lp:~serge-hallyn/+junk/nsexec)LXCの主な貢献者の1人であるSerge Hallynによって作成され、uidmapshift同じリポジトリ内のマッピングにはデフォルトで10,000個のスレーブIDのみが割り当てられます。

これは私を倒した。通常、私は100000個のID(読みやすいので)または65535個のIDブロックに割り当てます。

おすすめ記事