OpenVPN 警告:运行命令失败(--client-connect):无法执行外部程序

OpenVPN 警告:运行命令失败(--client-connect):无法执行外部程序

我刚刚在我的服务器上配置了 OpenVPN,它一直运行良好,直到我将其更改为在 chroot 模式下工作。

这是主要的配置文件vpn.example.com.conf

local w.x.y.z
port 1194
proto udp
proto-force udp
dev tun

ifconfig-ipv6 wwww:xxxx:yyyy:zzzz::1 wwww:xxxx:yyyy:zzzz::2

ca /etc/openvpn/easy-rsa3/easyrsa3/pki/ca.crt
cert /etc/openvpn/easy-rsa3/easyrsa3/pki/issued/vpn.example.com.crt
key /etc/openvpn/easy-rsa3/easyrsa3/pki/private/vpn.example.com.key

dh /etc/openvpn/easy-rsa3/easyrsa3/pki/dh.pem

topology subnet

server 10.8.0.0 255.255.255.0
server-ipv6 wwww:xxxx:yyyy:zzzz::/64

ifconfig-pool-persist ipp.txt


push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS w.x.y.z"
push "dhcp-option DNS z.w.x.y"
push "dhcp-option DNS 8.8.8.8"

push "route-ipv6 wwww:xxxx:yyyy:zzzz::2/64"
push "route-ipv6 wwww::/3"

push "redirect-gateway def1"


tls-crypt /etc/openvpn/easy-rsa3/easyrsa3/ta.key

tls-cipher TLS-ECDHE-RSA-WITH-AES-256-GCM-SHA384

tls-version-min 1.2

auth SHA512

crl-verify /etc/openvpn/easy-rsa3/easyrsa3/pki/crl.pem

cipher AES-256-GCM

compress lz4

user nobody
group nogroup

verify-client-cert require

remote-cert-tls client

username-as-common-name

plugin /usr/lib/openvpn/openvpn-plugin-auth-pam.so openvpn
script-security 2

client-connect /etc/openvpn/scripts/connect_.sh
client-disconnect /etc/openvpn/scripts/disconnect.sh

management /run/openvpn/openvpn.sock unix pw-management-file

keepalive 10 120

persist-key

persist-tun

status /var/log/openvpn/status.log


log-append /var/log/openvpn/openvpn.log

verb 3

explicit-exit-notify 1

max-clients 5

要配置 chroot 我只需:

  1. 通过运行创建 openvpn 用户useradd openvpn -d /etc/openvpn

  2. chown -R openvpn:openvpn /etc/openvpn。

  3. 将配置文件中的所有路径更改为相关路径。

  4. 添加openvpn ALL=(ALL) NOPASSWD: /sbin/ip到 /etc/sudoers

  5. 添加了以下指令chroot /etc/openvpniproute unpriv-ipuser openvpngroup openvpn

  6. cat unpriv-ip

    #!/bin/sh
    /usr/bin/sudo /sbin/ip $*
    
  7. 还编辑了 rsyslog 配置以在 openvpn chroot 目录中创建一个额外的套接字。

最后将 connect_.sh 脚本简化为:

#!/bin/bash
/bin/echo 'a'
exit 0

当我运行 openvpn --config vpn.example.com.conf 并尝试连接时,我看到了,WARNING: Failed running command (--client-connect): could not execute external program但如果你运行,su - openvpn我可以成功运行./scripts/connect_.sh script

以下是从命令行运行 openvpn 时且在任何客户端尝试连接之前的输出:

cd /etc/openvpn/
root@we:/etc/openvpn# /usr/sbin/openvpn --config conf.d/vpn.example.com\[easy-rsa3+chroot\].conf --verb 3
Fri Dec  8 19:45:01 2017 OpenVPN 2.4.0 x86_64-pc-linux-gnu [SSL (OpenSSL)] [LZO] [LZ4] [EPOLL] [PKCS11] [MH/PKTINFO] [AEAD] built on Jun 22 2017
Fri Dec  8 19:45:01 2017 library versions: OpenSSL 1.0.2g  1 Mar 2016, LZO 2.08
Fri Dec  8 19:45:01 2017 MANAGEMENT: unix domain socket listening on /run/openvpn/openvpn.sock
Fri Dec  8 19:45:01 2017 NOTE: the current --script-security setting may allow this configuration to call user-defined scripts
Fri Dec  8 19:45:01 2017 PLUGIN_INIT: POST /usr/lib/openvpn/openvpn-plugin-auth-pam.so '[/usr/lib/openvpn/openvpn-plugin-auth-pam.so] [openvpn]' intercepted=PLUGIN_AUTH_USER_PASS_VERIFY 
Fri Dec  8 19:45:01 2017 Diffie-Hellman initialized with 4096 bit key
Fri Dec  8 19:45:01 2017 Outgoing Control Channel Encryption: Cipher 'AES-256-CTR' initialized with 256 bit key
Fri Dec  8 19:45:01 2017 Outgoing Control Channel Encryption: Using 256 bit message hash 'SHA256' for HMAC authentication
Fri Dec  8 19:45:01 2017 Incoming Control Channel Encryption: Cipher 'AES-256-CTR' initialized with 256 bit key
Fri Dec  8 19:45:01 2017 Incoming Control Channel Encryption: Using 256 bit message hash 'SHA256' for HMAC authentication
Fri Dec  8 19:45:01 2017 TUN/TAP device tun0 opened
Fri Dec  8 19:45:01 2017 TUN/TAP TX queue length set to 100
Fri Dec  8 19:45:01 2017 do_ifconfig, tt->did_ifconfig_ipv6_setup=1
Fri Dec  8 19:45:01 2017 unpriv-ip link set dev tun0 up mtu 1500
Fri Dec  8 19:45:01 2017 unpriv-ip addr add dev tun0 10.8.0.1/24 broadcast 10.8.0.255
Fri Dec  8 19:45:01 2017 unpriv-ip -6 addr add wwww:xxxx:yyyy:zzzz::1/64 dev tun0
Fri Dec  8 19:45:01 2017 Could not determine IPv4/IPv6 protocol. Using AF_INET
Fri Dec  8 19:45:01 2017 Socket Buffers: R=[8388608->8388608] S=[212992->212992]
Fri Dec  8 19:45:01 2017 UDPv4 link local (bound): [AF_INET]w.x.y.z:1194
Fri Dec  8 19:45:01 2017 UDPv4 link remote: [AF_UNSPEC]
Fri Dec  8 18:45:01 2017 chroot to '/etc/openvpn' and cd to '/' succeeded
Fri Dec  8 18:45:01 2017 GID set to openvpn
Fri Dec  8 18:45:01 2017 UID set to openvpn
Fri Dec  8 18:45:01 2017 MULTI: multi_init called, r=256 v=256
Fri Dec  8 18:45:01 2017 IFCONFIG POOL IPv6: (IPv4) size=252, size_ipv6=65536, netbits=64, base_ipv6=wwww:xxxx:yyyy:zzzz::1000
Fri Dec  8 18:45:01 2017 IFCONFIG POOL: base=10.8.0.2 size=252, ipv6=1
Fri Dec  8 18:45:01 2017 ifconfig_pool_read(), in='client1,10.8.0.2,wwww:xxxx:yyyy:zzzz::1000', TODO: IPv6
Fri Dec  8 18:45:01 2017 succeeded -> ifconfig_pool_set()
Fri Dec  8 18:45:01 2017 IFCONFIG POOL LIST
Fri Dec  8 18:45:01 2017 client1,10.8.0.2,wwww:xxxx:yyyy:zzzz::1000
Fri Dec  8 18:45:01 2017 Initialization Sequence Completed    

这是客户端尝试连接时的输出:

Fri Dec  8 18:47:44 2017 66.666.66.66:64191 TLS: Initial packet from [AF_INET]66.666.66.66:64191, sid=1c8b367d eb08e85e
Fri Dec  8 18:47:47 2017 66.666.66.66:64191 VERIFY OK: depth=1, C=FF, ST=ZZZ, L=SomeCity, O=Some Text, OU=String, CN=String CA, [email protected]
Fri Dec  8 18:47:47 2017 66.666.66.66:64191 Validating certificate key usage
Fri Dec  8 18:47:47 2017 66.666.66.66:64191 ++ Certificate has key usage  0080, expects 0080
Fri Dec  8 18:47:47 2017 66.666.66.66:64191 VERIFY KU OK
Fri Dec  8 18:47:47 2017 66.666.66.66:64191 Validating certificate extended key usage
Fri Dec  8 18:47:47 2017 66.666.66.66:64191 ++ Certificate has EKU (str) TLS Web Client Authentication, expects TLS Web Client Authentication
Fri Dec  8 18:47:47 2017 66.666.66.66:64191 VERIFY EKU OK
Fri Dec  8 18:47:47 2017 66.666.66.66:64191 VERIFY OK: depth=1, C=FF, ST=ZZZ, L=SomeCity, O=Some Text, OU=String, CN=String CA, [email protected]
Fri Dec  8 18:47:47 2017 66.666.66.66:64191 peer info: IV_VER=2.4.4
Fri Dec  8 18:47:47 2017 66.666.66.66:64191 peer info: IV_PLAT=mac
Fri Dec  8 18:47:47 2017 66.666.66.66:64191 peer info: IV_PROTO=2
Fri Dec  8 18:47:47 2017 66.666.66.66:64191 peer info: IV_NCP=2
Fri Dec  8 18:47:47 2017 66.666.66.66:64191 peer info: IV_LZ4=1
Fri Dec  8 18:47:47 2017 66.666.66.66:64191 peer info: IV_LZ4v2=1
Fri Dec  8 18:47:47 2017 66.666.66.66:64191 peer info: IV_LZO=1
Fri Dec  8 18:47:47 2017 66.666.66.66:64191 peer info: IV_COMP_STUB=1
Fri Dec  8 18:47:47 2017 66.666.66.66:64191 peer info: IV_COMP_STUBv2=1
Fri Dec  8 18:47:47 2017 66.666.66.66:64191 peer info: IV_TCPNL=1
Fri Dec  8 18:47:47 2017 66.666.66.66:64191 peer info: IV_GUI_VER="net.tunnelblick.tunnelblick_4920_3.7.4a__build_4920)"
Fri Dec  8 18:47:47 2017 66.666.66.66:64191 PLUGIN_CALL: POST /usr/lib/openvpn/openvpn-plugin-auth-pam.so/PLUGIN_AUTH_USER_PASS_VERIFY status=0
Fri Dec  8 18:47:47 2017 66.666.66.66:64191 TLS: Username/Password authentication succeeded for username 'client' [CN SET]
Fri Dec  8 18:47:47 2017 66.666.66.66:64191 Control Channel: TLSv1.2, cipher TLSv1/SSLv3 ECDHE-RSA-AES256-GCM-SHA384, 4096 bit RSA
Fri Dec  8 18:47:47 2017 66.666.66.66:64191 [client1] Peer Connection Initiated with [AF_INET]66.666.66.66:64191
Fri Dec  8 18:47:47 2017 client1/66.666.66.66:64191 MULTI_sva: pool returned IPv4=10.8.0.2, IPv6=wwww:xxxx:y:zzzz::1000
Fri Dec  8 18:47:47 2017 client1/66.666.66.66:64191 WARNING: Failed running command (--client-connect): could not execute external program
Fri Dec  8 18:47:48 2017 client1/66.666.66.66:64191 PUSH: Received control message: 'PUSH_REQUEST'
Fri Dec  8 18:47:48 2017 client1/66.666.66.66:64191 Delayed exit in 5 seconds
Fri Dec  8 18:47:48 2017 client1/66.666.66.66:64191 SENT CONTROL [client1]: 'AUTH_FAILED' (status=1)
Fri Dec  8 18:47:53 2017 client1/66.666.66.66:64191 SIGTERM[soft,delayed-exit] received, client-instance exiting

答案1

由于我的脚本正在使用,所以bash我需要进入bash and all dependencieschroot:

cp -v /bin/bash /etc/openvpn/bin

因此运行ldd /bin/bash并将所有依赖项移动到 chroot 目录中:

linux-vdso.so.1 =>  (0x00007fff1fbe5000)
libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007f86fcbbc000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f86fc9b8000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f86fc5f1000)
/lib64/ld-linux-x86-64.so.2 (0x000055a1be46b000)

答案2

就我而言,问题很简单:我的脚本中没有shebang:

#~/bin/bash

相关内容