集成企业 OpenVPN 配置

集成企业 OpenVPN 配置

集成企业 OpenVPN 配置

我搜索了互联网上的所有地方,试图找到一个可靠的资源,了解如何以安全的方式配置 openvpn,最重要的是,100% 与 Active Directory 集成。我太懒了,不想处理多个系统。我想要:

  • OpenVPN 客户端无需定制(当然,除了配置文件)
  • 与 Active Directory 紧密集成
  • 多重身份验证(MS 证书存储 + 密码)
  • 超级易于管理

这是我的想法。这个解决方案安全吗?它能满足上述需求吗?

此时,我假设某处有一个活动目录服务器,openvpn 服务器可以连接到该服务器,并且客户端机器已加入域。

我还假设您已经部署了 AD CA。

自动注册

这一切都始于一个古老的自动注册过程。我不会在这里详细介绍,因为这张纸条很好地描述了这个过程。这里唯一要注意的是,我自动注册了机器证书,而不是用户证书。

一旦 GPO 推出,所有最终用户都将拥有由域 CA 签名的不可导出的私有机器证书。

现在,我们可以将 AD 自动注册证书与 OpenVPN 结合起来吗?思考所以。

证书颁发机构

在 AD CA 上,导出 CA 公共证书。在我的例子中,我将其命名为与机器名称相同的名称,末尾带有 .crt。

PKI 配置

这些示例假设使用基于 ubuntu 的操作系统。请根据您的发行版调整软件包和 ca-certificates 步骤。

# install our requisite packages
apt-get -y install openvpn openvpn-auth-ldap

# install our ca key as root ca
mkdir /usr/share/ca-certificates/extra/
cat > /usr/share/ca-certificates/extra/contoso-CONAWSDC01-CA.crt << EOM
-----BEGIN CERTIFICATE-----
MIIDBjCCAe6gAwIBAgIQf0VK+i3wuppE8eWGBn525TANBgkqhkiG9w0BAQsFADAc
...
KYTE7h9qTnJ4EQ==
-----END CERTIFICATE-----
EOM

# enable this root ca
dpkg-reconfigure ca-certificates

# go to /etc/openvpn for the remainder of this exercise
cd /etc/openvpn

# create our private key
openssl genrsa -des3 -out server.key 2048

# create a csr for the domain controller to sign. you *should* have the correct CN, but it's not required
openssl req -key server.key -out server.csr 

# then, over on the CA, we need to sign this key (note the webserver cheat)
# certreq.exe -submit -attrib "CertificateTemplate:WebServer" .\bopawsvpn02.txt

# create ta.key, which is used by the tls-auth pragma to prevent DOS attacks
openvpn --genkey --secret /etc/openvpn/ta.key

# symlink to our ca key
ln -s /usr/share/ca-certificates/extra/bop-BOPAWSDC01-CA.crt ca.crt

# enable ip forwarding
sysctl -w net.ipv4.ip_forward=1
# ( update /etc/sysctl.conf )   

# If you are hosting the OpenVPN server on an Amazon Web Services (AWS) EC2 instance make sure "Source/Destination Checking" is disabled on the instance's Elastic Network Interface (enabled by default)

OpenVPN 配置

我从基本的 Road Warrior 配置开始,并根据自己的需求进行了调整。主要是添加了 DNS 设置和路由。

由于 LDAP 身份验证依赖于其他模块,因此我无法使 chroot 正常工作。

服务器配置文件

port 1194
proto udp
dev tun
sndbuf 0
rcvbuf 0
ca ca.crt
cert server.crt
key server.key
dh dh.pem
tls-auth ta.key 0
topology subnet
server 10.22.0.0 255.255.0.0
ifconfig-pool-persist ipp.txt
push "dhcp-option DNS 10.20.1.4"
push "dhcp-option DOMAIN contoso.com"
push "route 10.0.0.0 255.255.0.0"
push "route 192.168.1.0 255.255.255.0"
keepalive 10 120
cipher AES-128-CBC
comp-lzo
user nobody
group nogroup
persist-key
persist-tun
status openvpn-status.log
verb 3
plugin /usr/lib/openvpn/openvpn-auth-ldap.so /etc/openvpn/ldap.conf

LDAP 配置

为了配置 LDAP,您需要绑定服务帐户,然后我们才能请求身份验证。我创建了一个具有长密码和极小权限的帐户。

ldap配置文件

<LDAP>
        # LDAP server URL
        URL             "ldap://10.20.1.4"

        # Bind DN (If your LDAP server doesn't support anonymous binds)
        # BindDN                uid=Manager,ou=People,dc=example,dc=com
        BindDN          "CN=auth,OU=Service Accounts,DC=contoso,DC=com"

        # Bind Password
        Password        areallyreallyreallylongpassword

        # Network timeout (in seconds)
        Timeout         15

        # Enable Start TLS
        TLSEnable       no

        # Follow LDAP Referrals (anonymously)
        FollowReferrals yes

        # TLS CA Certificate File
        TLSCACertFile   /usr/local/etc/ssl/ca.pem

        # TLS CA Certificate Directory
        TLSCACertDir    /etc/ssl/certs

        # Client Certificate and key
        # If TLS client authentication is required
        #TLSCertFile    /usr/local/etc/ssl/client-cert.pem
        #TLSKeyFile     /usr/local/etc/ssl/client-key.pem

        # Cipher Suite
        # The defaults are usually fine here
        # TLSCipherSuite        ALL:!ADH:@STRENGTH
</LDAP>

<Authorization>
        # Base DN
        BaseDN          "OU=local,DC=contoso,DC=com"

        # User Search Filter
        #SearchFilter   "(&(uid=%u)(accountStatus=active))"
        SearchFilter    "(sAMAccountName=%u)"

        # Require Group Membership
        RequireGroup    false

        # Add non-group members to a PF table (disabled)
        #PFTable        ips_vpn_users

</Authorization>

客户端配置

我想要一个可以发送给所有用户的单一配置,该配置无需在 .ovpn 文件中嵌入标识符或证书即可工作。经过一些实验和 cryptoapi 中不太完善的功能,我发现了这个秘诀。通过在对 cryptoapi 的 SUBJ 调用中指定我的域,OpenVPN 将找到具有该名称的第一个证书,即我的机器的证书。

我确实必须嵌入 CA 证书,因为我也不知道该如何从证书存储中将其提取出来。但这是公开信息,所以我并不太担心。

客户端.ovpn

client
dev tun
proto udp
sndbuf 0
rcvbuf 0
remote vpn.contoso.com 1194
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
cipher AES-128-CBC
comp-lzo
key-direction 1
verb 3
auth-user-pass
setenv opt block-outside-dns # block all non-vpn dns queries
# redirect-gateway def1 # route *all* traffic through vpn
# this is my domain fqdn. allows one config for multiple connections
cryptoapicert "SUBJ:.contoso.com" 

<ca>
-----BEGIN CERTIFICATE-----
MIIDBjCCAe6gAwIBAgIQf0VK+i3wuppE8eWGBn525TANBgkqhkiG9w0BAQsFADAc
...
KYTE7h9qTnJ4EQ==
-----END CERTIFICATE-----
</ca>

我是否忽略了任何明显的安全漏洞?

相关内容