无法从带有`openvpn`的容器中获取`ssh`

时间:2019-07-24 15:19:30

标签: containers fedora podman

基本设置

使用:

  • Fedora 30,已完全升级(内核5.1.19)
  • Podman 1.4.4

我有这个Dockerfile:

FROM fedora:30

ENV LANG C.UTF-8

RUN dnf upgrade -y \
    && dnf install -y \
        openssh-clients \
        openvpn \
        slirp4netns \
    && dnf clean all

CMD ["openvpn", "--config", "/vpn/ovpn.config", "--auth-user-pass", "/vpn/ovpn.auth"]

我使用的是哪个版本

podman build -t peque/vpn .

现在,为了能够成功运行它,我必须解决一些SELinux问题(请参阅Connect to VPN with Podman)。

解决SELinux权限问题

sudo dnf install udica

我为VPN容器定义了此ovpn_container.cil自定义策略:

(block ovpn_container
    (blockinherit container)
    (blockinherit restricted_net_container)
    (allow process process (capability (chown dac_override fsetid fowner mknod net_raw setgid setuid setfcap setpcap net_bind_service sys_chroot kill audit_write net_admin)))

    (allow process default_t (dir (open read getattr lock search ioctl add_name remove_name write)))
    (allow process default_t (file (getattr read write append ioctl lock map open create)))
    (allow process default_t (sock_file (getattr read write append open)))

    (allow process tun_tap_device_t (chr_file (ioctl open read write)))
    (allow process self (netlink_route_socket (nlmsg_write)))
    (allow process unreserved_port_t (tcp_socket (name_connect)))
)

我通过以下方式应用该政策

sudo semodule -r ovpn_container
sudo semodule -i ovpn_container.cil /usr/share/udica/templates/{base_container.cil,net_container.cil}

运行容器

现在,我可以使用以下命令成功运行容器了:

podman run -v $(pwd):/vpn:Z --cap-add=NET_ADMIN --device=/dev/net/tun --security-opt label=type:ovpn_container.process -it peque/vpn

问题

容器运行后,我在容器内打开一个终端,我要从该终端ssh到远程服务器:

podman exec -it container_name bash

从容器中,我可以成功ssh到远程服务器,但前提是它们不在VPN内。

当我尝试ssh到VPN中的服务器时,它卡住了一段时间,然后抛出此错误:

$ ssh server.domain.com
ssh: connect to host server.domain.com port 22: Connection refused 
kex_exchange_identification: Connection closed by remote host

我可能会缺少什么?

0 个答案:

没有答案