赞
踩
《OpenShift 4.x HOL教程汇总》
说明:本文已经在OpenShift 4.6环境中验证
在Service Mesh中,两个微服务之间双向传输安全是由Sidecar完成的。如下图,运行微服务的容器和Sidecar容器之间是网络互信的,因此是通过通过一般网络连接的,而Service A和Service B之间的网络安全传输是通过在与它们相对应的Sidecar之间的Mutual TLS实现的。本文演示如何为访问Preference微服务配置双向传输安全Mutual TLS。
在开始配置前需要根据《OpenShift 4 之Istio-Tutorial (2) 部署三个微服务》准备微服务环境即可。
$ oc apply -f curl/Deployment.yaml -n ${ISTIO_SYSTEM}
$ ./scripts/run_mTLS.sh
Executing curl in curl pod
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 61 100 61 0 0 4692 0 --:--:-- --:--:-- --:--:-- 0preference => recommendation v1 from '67976848-4l4s7': 4602
----------------------------------------------------------------------------
Executing curl in customer pod
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0preference => recommendation v1 from '67976848-4l4s7': 4603
100 61 100 61 0 0 10166 0 --:--:-- --:--:-- --:--:-- 10166
----------------------------------------------------------------------------
apiVersion: "authentication.istio.io/v1alpha1"
kind: "Policy"
metadata:
name: "preference-mutualtls"
spec:
targets:
- name: preference
peers:
- mtls:
mode: STRICT
执行命令创建policy。
$ oc apply -f istiofiles/authentication-enable-tls.yml -n ${ISTIO_SYSTEM}
policy.authentication.istio.io/preference-mutualtls created
$ oc get policy -n ${ISTIO_SYSTEM}
NAME AGE
preference-mutualtls 21s
Executing curl in curl pod
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
curl: (56) Recv failure: Connection reset by peer
command terminated with exit code 56
----------------------------------------------------------------------------
Executing curl in customer pod
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 95 100 95 0 0 47500 0 --:--:-- --:--:-- --:--:-- 47500upstream connect error or disconnect/reset before headers. reset reason: connection termination
----------------------------------------------------------------------------
apiVersion: "networking.istio.io/v1alpha3"
kind: "DestinationRule"
metadata:
name: "preference-destination-rule"
spec:
host: "preference"
trafficPolicy:
tls:
mode: ISTIO_MUTUAL
执行命令创建DestinationRule对象:
$ oc apply -f istiofiles/destination-rule-tls.yml -n ${ISTIO_SYSTEM}
Executing curl in curl pod
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
curl: (56) Recv failure: Connection reset by peer
command terminated with exit code 56
----------------------------------------------------------------------------
Executing curl in customer pod
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0preference => recommendation v1 from '67976848-4l4s7': 5858
100 61 100 61 0 0 12200 0 --:--:-- --:--:-- --:--:-- 12200
----------------------------------------------------------------------------
apiVersion: "authentication.istio.io/v1alpha1"
kind: "Policy"
metadata:
name: "preference-mutualtls"
spec:
targets:
- name: preference
peers:
- mtls:
mode: PERMISSIVE
执行命令更新Policy对象:
$ oc apply -f istiofiles/authentication-enable-tls-permissive.yml -n ${ISTIO_SYSTEM}
Executing curl in customer pod
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0preference => recommendation v1 from '67976848-4l4s7': 6937
100 61 100 61 0 0 8714 0 --:--:-- --:--:-- --:--:-- 8714
----------------------------------------------------------------------------
Executing curl in curl pod
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0preference => recommendation v1 from '67976848-4l4s7': 6938
100 61 100 61 0 0 4692 0 --:--:-- --:--:-- --:--:-- 4692
----------------------------------------------------------------------------
$ oc delete -f istiofiles/authentication-enable-tls.yml -n ${ISTIO_SYSTEM}
$ oc delete -f istiofiles/destination-rule-tls.yml -n ${ISTIO_SYSTEM}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。