Kubernets 集羣,使用 ingress-nginx 做爲 ingress-controller,使用的是 Let's Encrypt 證書。
由於國內網絡緣由,ocsp.int-x3.letsencrypt.org
被DNS污染了,直接解析出來的主機沒法經過國內網絡直接訪問。iOS
系統回強制https的在線證書校驗邏輯,致使會常常鏈接超時或初次鏈接速度很慢,影響用戶體驗。nginx
解決辦法有兩個:git
在線證書校驗
,找到個現成的庫:https://github.com/zymxxxs/YM... OCSP Stapling
能夠代替客戶端作 在線證書校驗
,將驗證結果直接返回客戶端經過客戶端的方式解決,在用瀏覽器直接訪問時仍是會慢,這裏主要介紹服務端解決方案:github
nginx
是支持 OCSP Stapling
配置也很簡單api
server { ssl_stapling on; }
集羣使用的是 ingress-nginx
,使用helm部署這樣配置values (只展現了關鍵配置)瀏覽器
controller: config: enable-ocsp: "true"
可是還有一個問題,服務端也須要訪問 ocsp.int-x3.letsencrypt.org
來獲取證書驗證信息
在這裏,找到個解決辦法:https://blog.csdn.net/qq_3458...
只須要將 ocsp.int-x3.letsencrypt.org
解析到這個IP 23.32.3.72
便可bash
在集羣內實現這一點有以下幾個方法:服務器
參考配置文檔:https://coredns.io/plugins/ho...
注意,配置中 fallthrough
必須添加,不然會致使集羣網絡異常網絡
apiVersion: v1 kind: ConfigMap metadata: name: coredns namespace: kube-system data: Corefile: | .:53 { ... # 原配置省略,在後面追加便可 hosts { 23.32.3.72 ocsp.int-x3.letsencrypt.org fallthrough } }
ingress-nginx
的Pod配置,添加dnsConfig添加dnsConfig指向自部署DNS服務器,自部署的DNS服務器添加A記錄 ocsp.int-x3.letsencrypt.org
--> 23.32.3.72
oop
這裏使用helm經過部署coredns部署DNS服務器 https://hub.helm.sh/charts/st... 我當前使用的版本:1.10.1
values配置以下:測試
service: # 必須指定集羣IP,能夠自行修改,注意集羣支持的service網段 clusterIP: 10.96.88.88 servers: - zones: - zone: . port: 53 plugins: - name: errors # Serves a /health endpoint on :8080, required for livenessProbe - name: health configBlock: |- lameduck 5s # Serves a /ready endpoint on :8181, required for readinessProbe - name: ready # Required to query kubernetes API for data - name: kubernetes parameters: cluster.local in-addr.arpa ip6.arpa configBlock: |- pods insecure fallthrough in-addr.arpa ip6.arpa ttl 30 - name: forward parameters: . /etc/resolv.conf - name: cache parameters: 30 - name: loop - name: reload - name: loadbalance # 此處爲關鍵配置 - name: hosts configBlock: |- 23.32.3.72 ocsp.int-x3.letsencrypt.org fallthrough
ingress-nginx
安裝使用的是官方提供的 helm chart:https://kubernetes.github.io/...
values關鍵配置以下:
controller: ... # 修改dns配置 dnsConfig: nameservers: # 與上面DNS服務器指定的集羣IP對應 - 10.96.88.88 searches: - ocsp.int-x3.letsencrypt.org ...
ingress-nginx
的Pod配置,添加hostAliases(此方法無效,僅提供思路給你們測試)添加hostAliases將域名從新指向
經測試此方法雖然可讓ingress-nginx
容器內網絡按預期走,可是nginx作OCSP時並無成功按預期解析域名
須要先修改ingress-nginx
的chart,添加設置hostAliases支持
# 拉去chart helm pull ingress-nginx/ingress-nginx --version 2.1.0
配置文件較長僅列出關鍵修改,全部修改都是添加,參照修下面添加到對應位置便可:
# values.yaml controller: ... # Optionally customize the pod hostAliases. hostAliases: {} ...
# templates/controller-deployment.yaml spec: template: metadata: spec: ... {{- if .Values.controller.hostAliases }} hostAliases: {{ toYaml .Values.controller.hostAliases | nindent 8 }} {{- end }} ...
# templates/controller-daemonset.yaml spec: template: metadata: spec: ... {{- if .Values.controller.hostAliases }} hostAliases: {{ toYaml .Values.controller.hostAliases | nindent 8 }} {{- end }} ...
至此chart修改完成,修改部署時的 values
controller: ... hostAliases: - ip: 23.32.3.72 hostnames: - ocsp.int-x3.letsencrypt.org ...
echo QUIT | openssl s_client -connect xxxxxxxxx.com:443 -servername xxxxxxxxx.com -status 2> /dev/null | grep -A 17 'OCSP response:'
輸出如下內容說明開啓並獲取 OCSP Stapling 成功
OCSP response: ====================================== OCSP Response Data: OCSP Response Status: successful (0x0) Response Type: Basic OCSP Response Version: 1 (0x0) Responder Id: C = US, O = Let's Encrypt, CN = Let's Encrypt Authority X3 Produced At: May 19 11:26:00 2020 GMT Responses: Certificate ID: Hash Algorithm: sha1 Issuer Name Hash: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Issuer Key Hash: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Serial Number: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Cert Status: good This Update: May 19 11:00:00 2020 GMT Next Update: May 26 11:00:00 2020 GMT
輸出如下內容說明開啓並獲取 OCSP Stapling 失敗
OCSP response: no response sent --- Certificate chain 0 s:/CN=xxxxxxx.com i:/C=US/O=Let's Encrypt/CN=Let's Encrypt Authority X3 1 s:/C=US/O=Let's Encrypt/CN=Let's Encrypt Authority X3 i:/O=Digital Signature Trust Co./CN=DST Root CA X3 --- Server certificate