特定服务器上的docker容器内的SSL证书验证失败

时间:2016-06-22 14:26:36

标签: ssl docker

我遇到了一个奇怪的问题,我无法弄清楚如何调试证书。当我在一个特定服务器上的docker容器内运行wget时,它无法验证证书。同样的wget在服务器机器本身(在docker之外)上工作正常,并且它在不同服务器上的同一个docker容器内工作。

这是docker容器的设置:

docker run --rm -ti debian:jessie bash
apt-get update
apt-get install wget
wget https://google.com

回复是:

converted 'https://google.com' (ANSI_X3.4-1968) -> 'https://google.com' (UTF-8)
--2016-06-22 14:22:02--  https://google.com/
Resolving google.com (google.com)... 216.58.217.142, 2607:f8b0:4004:807::200e
Connecting to google.com (google.com)|216.58.217.142|:443... connected.
ERROR: The certificate of 'google.com' is not trusted.
ERROR: The certificate of 'google.com' hasn't got a known issuer.
The certificate's owner does not match hostname 'google.com'

由于此相同的过程适用于其他服务器,因此问题似乎只是该服务器本身的某些证书​​问题。但我必须感到困惑:为什么服务器上的证书本身与docker容器内发生的事情有关?

我真的很感激对此的任何见解,特别是我可以采取的任何调试步骤来更好地理解问题。

4 个答案:

答案 0 :(得分:9)

似乎证书在jessie图像中已经过时了。

在wget之前尝试apt-get install ca-certificates

答案 1 :(得分:2)

这对我来说很好,但为了安全起见,请确保您的" ca-certificates"包是最新的。最有可能的是,您在网络上有某种检查流量的安全设备,并使用它自己的证书进行解密和加密。这是我从自己的测试中获得的证书:

bash$ openssl s_client -showcerts -connect www.google.com:443
CONNECTED(00000003)
depth=3 C = US, O = Equifax, OU = Equifax Secure Certificate Authority
verify return:1
depth=2 C = US, O = GeoTrust Inc., CN = GeoTrust Global CA
verify return:1
depth=1 C = US, O = Google Inc, CN = Google Internet Authority G2
verify return:1
depth=0 C = US, ST = California, L = Mountain View, O = Google Inc, CN = www.google.com
verify return:1
---
Certificate chain
 0 s:/C=US/ST=California/L=Mountain View/O=Google Inc/CN=www.google.com
   i:/C=US/O=Google Inc/CN=Google Internet Authority G2
-----BEGIN CERTIFICATE-----
MIIEgDCCA2igAwIBAgIIdnEF+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AYKKwYBBAHW
eQIFATAIBgZngQwBAgIwMAYDVR0fBCkwJzAloCOgIYYfaHR0cDovL3BraS5nb29n
bGUuY29tL0dJQUcyLmNybDANBgkqhkiG9w0BAQsFAAOCAQEAK1BpCyAbID8gpwWI
bQReJv81H/qvYvaaOFa7PLnqHhaAZmzjV1tkCsVB60IgsBDoNuPdtJ5klpxV+njs
VhDnxneaHL21zwUCuZvNVyYL9VCSYGWV1iNe6PtYYtbWt7of6bEiwZsSuPWaRuRp
YcvJH+mpv/EIDw1shU5UK3FpvnSHEH2jrs2psnC4BYSovT3pH2nxTCpiLiya1UNn
+qtqiCJyDKhEV6f1j+Awg/Fr+tVCZLjHcSmGqL3DNcHbCUalXrq4EwVK3Pg8lghU
Dm3e0J3EcjgMacIg+RP+2pOM5GvIwQ6BrKbmcnTjqsjcG1tQEV0ZSb6hx2bGYhc2
3TG+rQ==
-----END CERTIFICATE-----
 1 s:/C=US/O=Google Inc/CN=Google Internet Authority G2
   i:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
-----BEGIN CERTIFICATE-----
MIID8DCCAtigAwIBAgIDAjqDMA0GCSqGSIb3DQEBCwUAMEIxCzAJBgNVBAYTAlVT
MRYwFAYDVQQKEw1HZW9UcnVzdCBJbmMuMRswGQYDVQQDExJHZW9UcnVzdCBHbG9i
YWwgQ0EwHhcNMTMwNDA1MTUxNTU2WhcNMTYxMjMxMjM1OTU5WjBJMQswCQYDVQQG
EwJVUzETMBEGA1UEChMKR29vZ2xlIEluYzElMCMGA1UEAxMcR29vZ2xlIEludGVy
bmV0IEF1dGhvcml0eSBHMjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB
AJwqBHdc2FCROgajguDYUEi8iT/xGXAaiEZ+4I/F8YnOIe5a/mENtzJEiaB0C1NP
VaTOgmKV7utZX8bhBYASxF6UP7xbSDj0U/ck5vuR6RXEz/RTDfRK/J9U3n2+oGtv
h8DQUB8oMANA2ghzUWx//zo8pzcGjr1LEQTrfSTe5vn8MXH7lNVg8y5Kr0LSy+rE
ahqyzFPdFUuLH8gZYR/Nnag+YyuENWllhMgZxUYi+FOVvuOAShDGKuy6lyARxzmZ
EASg8GF6lSWMTlJ14rbtCMoU/M4iarNOz0YDl5cDfsCx3nuvRTPPuj5xt970JSXC
DTWJnZ37DhF5iR43xa+OcmkCAwEAAaOB5zCB5DAfBgNVHSMEGDAWgBTAephojYn7
qwVkDBF9qn1luMrMTjAdBgNVHQ4EFgQUSt0GFhu89mi1dvWBtrtiGrpagS8wDgYD
VR0PAQH/BAQDAgEGMC4GCCsGAQUFBwEBBCIwIDAeBggrBgEFBQcwAYYSaHR0cDov
L2cuc3ltY2QuY29tMBIGA1UdEwEB/wQIMAYBAf8CAQAwNQYDVR0fBC4wLDAqoCig
JoYkaHR0cDovL2cuc3ltY2IuY29tL2NybHMvZ3RnbG9iYWwuY3JsMBcGA1UdIAQQ
MA4wDAYKKwYBBAHWeQIFATANBgkqhkiG9w0BAQsFAAOCAQEAqvqpIM1qZ4PtXtR+
3h3Ef+AlBgDFJPupyC1tft6dgmUsgWM0Zj7pUsIItMsv91+ZOmqcUHqFBYx90SpI
hNMJbHzCzTWf84LuUt5oX+QAihcglvcpjZpNy6jehsgNb1aHA30DP9z6eX0hGfnI
Oi9RdozHQZJxjyXON/hKTAAj78Q1EK7gI4BzfE00LshukNYQHpmEcxpw8u1VDu4X
Bupn7jLrLN1nBz/2i8Jw3lsA5rsb0zYaImxssDVCbJAJPZPpZAkiDoUGn8JzIdPm
X4DkjYUiOnMDsWCOrmji9D6X52ASCWg23jrW4kOVWzeBkoEfu43XrVJkFleW2V40
fsg12A==
-----END CERTIFICATE-----
 2 s:/C=US/O=GeoTrust Inc./CN=GeoTrust Global CA
   i:/C=US/O=Equifax/OU=Equifax Secure Certificate Authority
-----BEGIN CERTIFICATE-----
MIIDfTCCAuagAwIBAgIDErvmMA0GCSqGSIb3DQEBBQUAME4xCzAJBgNVBAYTAlVT
MRAwDgYDVQQKEwdFc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ltLroxwUCEm2u+WR74M26x1W
b8ravHNjkOR/ez4iyz0H7V84dJzjA1BOoa+Y7mHyhD8S
-----END CERTIFICATE-----
---
Server certificate
subject=/C=US/ST=California/L=Mountain View/O=Google Inc/CN=www.google.com
issuer=/C=US/O=Google Inc/CN=Google Internet Authority G2
---
No client certificate CA names sent
---
SSL handshake has read 3727 bytes and written 415 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES128-GCM-SHA256
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : ECDHE-RSA-AES128-GCM-SHA256
    Session-ID: 09AF6D01D3E3059EA0E4543E880035C34D74CEFCBB9D20F34F8CC1789D2485B2
    Session-ID-ctx: 
    Master-Key: 575CCE0D8562480D591DE3983B2B6709D1FF5F0FCF219FFF66C30B90A5A906E5A8BD6688DED22EDFE6F7DC9702915E5B
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    TLS session ticket lifetime hint: 100800 (seconds)
    TLS session ticket:
    0000 - 3e 73 9d 09 9a 16 a9 a2-70 64 76 b4 16 b1 ca d0   >s......pdv.....
    0010 - 70 37 62 e2 d3 e6 ac b3-31 31 4d 4b 1c 9b 2b 6c   p7b.....11MK..+l
    0020 - cc 1c 0d 3d ae dc ce c2-d4 36 41 4c 04 54 f0 e3   ...=.....6AL.T..
    0030 - 15 03 04 b5 32 0d 8b c0-5b c0 d6 03 8d df d8 bf   ....2...[.......
    0040 - 74 7c ae ac da 3b 1a 8d-d7 56 3d 3a ee dd 69 d3   t|...;...V=:..i.
    0050 - fb 2d 34 4a c4 51 0c e6-39 18 20 f1 cc 5d ab 66   .-4J.Q..9. ..].f
    0060 - 9f f9 47 6f b4 09 6f 4f-42 6c 72 42 fd 92 a3 3b   ..Go..oOBlrB...;
    0070 - 95 3d a1 14 e5 33 b8 b4-8a de 0f f4 4b b6 08 2b   .=...3......K..+
    0080 - bb f6 18 3c 51 90 c8 ce-8c 9d 84 37 de be 07 72   ...<Q......7...r
    0090 - 5d 5a fa 6a 28 70 95 29-28 5e 0d 26 0f 59 c7 d2   ]Z.j(p.)(^.&.Y..
    00a0 - b5 86 1e 99                                       ....

    Start Time: 1466605956
    Timeout   : 300 (sec)
    Verify return code: 0 (ok)
---

要在自己的网络上运行此功能,您需要将本地安全设备中的CA添加到容器中:

sudo cp ca.pem /usr/local/share/ca-certificates/my-ca.crt
sudo update-ca-certificates

答案 2 :(得分:2)

Docker使用iptables。

如果您设置了iptable规则,则可以将每个https请求定向到您自己正在运行的服务器。

例如,如果您在本地运行jenkins并使用iptables将443重定向到默认的8080端口,那么到端口443端口的所有容器流量将被重定向到将无法验证您的证书的本地jenkins服务器。 我们在使用Jenkins构建docker镜像时遇到了这个问题。我们的jenkins使用iptables以root身份运行jenkins。

答案 3 :(得分:0)

我的问题还与iptables有关。我最终通过更改我的iptables端口转发规则来解决该问题,以使源自0.0.0.0/0的所有流量都具有例外:

sudo iptables -t nat -A PREROUTING -p tcp ! -s 0.0.0.0/0 --dport 80 -j REDIRECT --to-port 8000
sudo iptables -t nat -A PREROUTING -p tcp ! -s 0.0.0.0/0 --dport 443 -j REDIRECT --to-port 8080

其中! -s 0.0.0.0/0的意思是“来源不是 0.0.0.0/0(来自此计算机的流量)”

在添加这些新规则之前,您可能必须删除现有规则。

编辑:事实证明,由于我不明白的原因,该方法也不起作用。我终于开始使用! -s 172.18.0.0/24,它似乎是docker的默认(?)掩码。