TLS 1.2 支持
由于 WinRM 通过 HTTP 协议运行,使用 HTTPS 意味着使用 TLS 协议来加密 WinRM 消息。TLS 将自动尝试协商客户端和服务器都可用的最佳协议和密码套件。如果找不到匹配项,则 Ansible 将报错,并显示类似于以下内容的消息:
HTTPSConnectionPool(host='server', port=5986): Max retries exceeded with url: /wsman (Caused by SSLError(SSLError(1, '[SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1056)')))
通常,这是因为 Windows 主机尚未配置为支持 TLS v1.2,但也可能意味着 Ansible 控制节点安装了较旧的 OpenSSL 版本。
Windows 8 和 Windows Server 2012 默认安装并启用了 TLS v1.2,但较旧的主机(如 Server 2008 R2 和 Windows 7)必须手动启用。
注意
Server 2008 的 TLS 1.2 补丁存在一个错误,这将阻止 Ansible 连接到 Windows 主机。这意味着 Server 2008 不能配置为使用 TLS 1.2。Server 2008 R2 和 Windows 7 不受此问题的影响,可以使用 TLS 1.2。
要验证 Windows 主机支持的协议,可以在 Ansible 控制节点上运行以下命令:
openssl s_client -connect
输出将包含有关 TLS 会话的信息,并且 Protocol 行将显示协商的版本。
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES256-SHA
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1
Cipher : ECDHE-RSA-AES256-SHA
Session-ID: 962A00001C95D2A601BE1CCFA7831B85A7EEE897AECDBF3D9ECD4A3BE4F6AC9B
Session-ID-ctx:
Master-Key: ....
Start Time: 1552976474
Timeout : 7200 (sec)
Verify return code: 21 (unable to verify the first certificate)
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES256-GCM-SHA384
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1.2
Cipher : ECDHE-RSA-AES256-GCM-SHA384
Session-ID: AE16000050DA9FD44D03BB8839B64449805D9E43DBD670346D3D9E05D1AEEA84
Session-ID-ctx:
Master-Key: ....
Start Time: 1552976538
Timeout : 7200 (sec)
Verify return code: 21 (unable to verify the first certificate)
如果主机返回 TLSv1,则应将其配置为启用 TLS v1.2。您可以通过运行以下 PowerShell 脚本来实现此目的:
Function Enable-TLS12 {
param(
[ValidateSet("Server", "Client")]
[String]$Component = "Server"
)
$protocols_path = 'HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols'
New-Item -Path "$protocols_path\TLS 1.2\$Component" -Force
New-ItemProperty -Path "$protocols_path\TLS 1.2\$Component" -Name Enabled -Value 1 -Type DWORD -Force
New-ItemProperty -Path "$protocols_path\TLS 1.2\$Component" -Name DisabledByDefault -Value 0 -Type DWORD -Force
}
Enable-TLS12 -Component Server
# Not required but highly recommended to enable the Client side TLS 1.2 components
Enable-TLS12 -Component Client
Restart-Computer
以下 Ansible 任务也可用于启用 TLS v1.2:
- name: enable TLSv1.2 support
win_regedit:
path: HKLM:\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\{{ item.type }}
name: '{{ item.property }}'
data: '{{ item.value }}'
type: dword
state: present
register: enable_tls12
loop:
- type: Server
property: Enabled
value: 1
- type: Server
property: DisabledByDefault
value: 0
- type: Client
property: Enabled
value: 1
- type: Client
property: DisabledByDefault
value: 0
- name: reboot if TLS config was applied
win_reboot:
when: enable_tls12 is changed
还有其他方法可以配置 TLS 协议以及 Windows 主机提供的密码套件。Nartac Software 提供的 IIS Crypto 工具可以为您提供一个 GUI 来管理这些设置。