Control Ingress Traffic task描述如何配置一个ingress gateway来为服务的外部流量暴露一个HTTP端口。这个task拓展那个task,使用普通或者相互TLS认证来开启HTTPS访问。

Before you begin

1.执行 Control Ingress Traffic task中的 Before you begin 和 Determining the ingress IP and ports 小节。完成这几步,你应该部署了Istio、httpbin 服务,设置了环境变量 INGRESS_HOSTSECURE_INGRESS_PORT

2.对于mac系统用户,确保你使用 LibreSSL 库编译的 curl :

curl --version | grep LibreSSL

curl 7.54.0 (x86_64-apple-darwin17.0) libcurl/7.54.0 LibreSSL/2.0.20 zlib/1.2.11 nghttp2/1.24.0

如果 LibreSSL 的版本如上输出那样,你的 curl 应该能在这个task中正确的执行指令。否则,尝试安装其他 curl ,比如在一台Linux机器上。

Generate client and server certificates and keys

这个task你可以使用你最喜欢的工具去生成证书和密钥。我们使用 https://github.com/nicholasjackson/mtls-go-example 库的一个脚本。

1.克隆库:

git clone https://github.com/nicholasjackson/mtls-go-example

2.切换克隆库的目录:

cd mtls-go-example

3.生成证书(使用任何密码):

generate.sh httpbin.example.com <password>

这个命令会生成四个目录: 1_root, 2_intermediate, 3_application4_client ,你将用它们来认证服务端和客户端。

Configure a TLS ingress gateway

这节你配置一个用443端口处理HTTPS流量的 ingress gateway。你用一个证书和私钥创建一个secret。然后创建一个包含443端口的 serverGateway 的定义。

1.创建一个k8s Secret 持有服务端的证书和私钥。使用 kubectl 在命名空间 istio-system 创建secret istio-ingressgateway-certs 。Istio gateway将会自动加载secret。

secret必须在命名空间 istio-system 中命名为 istio-ingressgateway-certs ,否则将不会被Istio gateway安装和使用。

kubectl create -n istio-system secret tls istio-ingressgateway-certs --key 3_application/private/httpbin.example.com.key.pem --cert 3_application/certs/httpbin.example.com.cert.pem

secret “istio-ingressgateway-certs” created

注意:默认命名空间 istio-system 的所有服务账户都可以访问这个secret,因此私钥可能被泄漏。你可以改变 Role-Based Access Control (RBAC) 规则来保护它。

2.定义一个 server 部分端口为443的 Gateway

证书和私钥的位置必须为 /etc/istio/ingressgateway-certs, 否则gateway无法加载。

cat <<EOF | istioctl create -f -
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:name: httpbin-gateway
spec:selector:istio: ingressgateway # use istio default ingress gatewayservers:- port:number: 443name: httpsprotocol: HTTPStls:mode: SIMPLEserverCertificate: /etc/istio/ingressgateway-certs/tls.crtprivateKey: /etc/istio/ingressgateway-certs/tls.keyhosts:- "httpbin.example.com"
EOF

3.配置通过 Gateway 进入流量的路由。定义和 Control Ingress Traffic task 中相同的 VirtualService

cat <<EOF | istioctl create -f -
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:name: httpbin
spec:hosts:- "httpbin.example.com"
  gateways:- httpbin-gateway
  http:- match:
    - uri:
        prefix: /status- uri:
        prefix: /delayroute:- destination:
        port:number: 8000host: httpbin
EOF

4.通过使用 curl 到 SECURE_INGRESS_PORT 发送一个 https 请求来通过HTTPS访问httpbin 服务。
--resolve flag 用来指导 curl 在通过TLS访问gateway IP时提供SNI值 “httpbin.example.com” 。 --cacert 选项指示 curl 使用你生成的证书来验证服务端。
通过发送请求到 /status/418 URL路径,你会得到一个很棒的视觉效果来保证你的 httpbin 服务的确被访问到了。 httpbin 服务将会返回 418 I’m a Teapot code.

curl -v --resolve httpbin.example.com:$SECURE_INGRESS_PORT:$INGRESS_HOST --cacert 2_intermediate/certs/ca-chain.cert.pem https://httpbin.example.com:$SECURE_INGRESS_PORT/status/418
...
Server certificate:subject: C=US; ST=Denial; L=Springfield; O=Dis; CN=httpbin.example.comstart date: Jun 24 18:45:18 2018 GMTexpire date: Jul  4 18:45:18 2019 GMTcommon name: httpbin.example.com (matched)issuer: C=US; ST=Denial; O=Dis; CN=httpbin.example.com
SSL certificate verify ok.
...
HTTP/2 418
...
-=[ teapot ]=-_...._.'  _ _ `.
| ."` ^ `". _,
\_;`"---"`|//|       ;/\_     _/`"""`

注意:gateway定义可能需要一段时间传播,你可能会收到如下错误: Failed to connect to httpbin.example.com port <your secure port>: Connection refused. 等几分钟再使用curl调用。

观察 Server certificate 部分 curl 的输出,注意到匹配 common name 的那行: common name: httpbin.example.com (matched). 根据curl输出的 SSL certificate verify ok 这行,你能确定服务端验证成功。注意返回的418状态以及一个非常棒的茶壶画像。

如果你需要支持 mutual TLS ,继续进行下节。

Configure a mutual TLS ingress gateway

这节你将扩展你上节的gateway定义来支持外部客户和gateway之间的 mutual TLS .

1.对于Istio 0.8.0,重新部署一个带有服务端用来验证它的客户端 CA 证书的 volume 的 istio-ingressgateway

kubectl apply -f <(helm template install/kubernetes/helm/istio --name istio --namespace istio-system -x charts/ingressgateway/templates/deployment.yaml --set ingressgateway.deployment.secretVolumes[0].name=ingressgateway-certs,ingressgateway.deployment.secretVolumes[0].secretName=istio-ingressgateway-certs,ingressgateway.deployment.secretVolumes[0].mountPath=/etc/istio/ingressgateway-certs,ingressgateway.deployment.secretVolumes[1].name=ingressgateway-ca-certs,ingressgateway.deployment.secretVolumes[1].secretName=istio-ingressgateway-ca-certs,ingressgateway.deployment.secretVolumes[1].mountPath=/etc/istio/ingressgateway-ca-certs)

deployment “istio-ingressgateway” configured

2.创建一个k8s Secret 来持有 CA 证书,在命名空间istio-system 命名为 istio-ingressgateway-ca-certs 。Istio gateway将自动加载secret。

secret必须在命名空间 istio-system 中命名为 istio-ingressgateway-certs ,否则将不会被Istio gateway安装和使用。

kubectl create -n istio-system secret generic istio-ingressgateway-ca-certs --from-file=2_intermediate/certs/ca-chain.cert.pem

secret “istio-ingressgateway-ca-certs” created

3.重定义你之前的Gateway ,并更改 tls modeMUTUAL 并指定 caCertificates:

证书和私钥的位置必须为 /etc/istio/ingressgateway-certs, 否则gateway无法加载。证书的名字必须和你创建secret的文件名相同,这里是 ca-chain.cert.pem.

cat <<EOF | istioctl replace -f -
apiVersion: networking.istio.io/v1alpha3
kind: Gateway
metadata:name: httpbin-gateway
spec:selector:istio: ingressgateway # use istio default ingress gatewayservers:- port:number: 443name: httpsprotocol: HTTPStls:mode: MUTUALserverCertificate: /etc/istio/ingressgateway-certs/tls.crtprivateKey: /etc/istio/ingressgateway-certs/tls.keycaCertificates: /etc/istio/ingressgateway-ca-certs/ca-chain.cert.pemhosts:- "httpbin.example.com"
EOF

4.像上一节那样通过HTTPS访问httpbin 服务:

curl --resolve httpbin.example.com:$SECURE_INGRESS_PORT:$INGRESS_HOST  --cacert 2_intermediate/certs/ca-chain.cert.pem https://httpbin.example.com:$SECURE_INGRESS_PORT/status/418

curl: (35) error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure


getaway定义需要时间传播,你可能还会得到418.等几分钟再试curl调用。

这次你得到了错误信息,因为服务端拒绝接受未认证的请求。你不得不发送客户端证书,通过curl你的私钥来签署请求。

5.通过curl再次发送上一个请求,这次作为参数传递你的客户端证书(--cert选项)和私钥(--key选项)

curl --resolve httpbin.example.com:$SECURE_INGRESS_PORT:$INGRESS_HOST  --cacert 2_intermediate/certs/ca-chain.cert.pem --cert 4_client/certs/httpbin.example.com.cert.pem --key 4_client/private/httpbin.example.com.key.pem https://httpbin.example.com:$SECURE_INGRESS_PORT/status/418
-=[ teapot ]=-_...._.'  _ _ `.
| ."` ^ `". _,
\_;`"---"`|//|       ;/\_     _/`"""`

这次服务端成功认证客户端,你也再次受到漂亮的茶壶画。

Troubleshooting

1.检查环境变量 INGRESS_HOSTSECURE_INGRESS_PORT 的值。确保它们值有效,通过命令输出:

kubectl get svc -n istio-system
echo INGRESS_HOST=$INGRESS_HOST, SECURE_INGRESS_PORT=$SECURE_INGRESS_PORT

2.验证key和证书在 istio-ingressgateway pod中成功装载:

kubectl exec -it -n istio-system $(kubectl -n istio-system get pods -l istio=ingressgateway -o jsonpath='{.items[0].metadata.name}') -- ls -al /etc/istio/ingressgateway-certs

tls.crttls.key 应该存在于目录内容中。

3.检查 istio-ingressgateway 日志的错误信息:

kubectl logs -n istio-system -l istio=ingressgateway

4.对于相互TLS认证,确认CA证书在 istio-ingressgateway pod中成功装载:

kubectl exec -it -n istio-system $(kubectl -n istio-system get pods -l istio=ingressgateway -o jsonpath='{.items[0].metadata.name}') -- ls -al /etc/istio/ingressgateway-ca-certs

ca-chain.cert.pem 应该存在于目录内容中。

5.对于mac系统用户,确保你使用 LibreSSL 库编译的 curl ,如 Before you begin 小节中描述的那样。

Cleanup

1.删除 Gateway 配置, VirtualService 及secrets:

istioctl delete gateway httpbin-gateway
istioctl delete virtualservice httpbin
kubectl delete --ignore-not-found=true -n istio-system secret istio-ingressgateway-certs istio-ingressgateway-ca-certs

2.关闭 httpbin 服务:

kubectl delete --ignore-not-found=true -f samples/httpbin/httpbin.yaml

Securing Gateways with HTTPS(0.8)相关推荐

  1. opencv 九点标定_精度与HALCON结果仅差(±0.2mm)

    很多初学者,都对标定概念模糊不清,分不清坐标系之间的关系,搞不清相机标定和机械手相机标定有什么关系,想当初自己也是一个人摸索了很久,本文将尽量给大家解释. 我们通常所说的相机标定分为两种,一种是相机参 ...

  2. 为什么在Java 6上Math.round(0.499999999999999917)舍入为1

    总览 错误表示错误和算术舍入错误有两种类型,它们在浮点计算中很常见. 在此简单示例中,这两个错误组合在一起,在Java 6中Math.round(0.4999999999999999999917)舍入 ...

  3. 键盘录入一个正整数,把它的各个位上的数字倒着排列形成一个新的整数并输出。 例如:12345 数出54321 78760 输出6787(0省去)

    package com.coffn.demos; /*** 4.键盘录入一个正整数,把它的各个位上的数字倒着排列形成一个新的整数并输出.例如:12345 数出54321 78760 输出6787(0省 ...

  4. 字符转换 提取一个字符串中的所有数字字符('0'……'9'),将其转换为一个整数输出。 首位不能是0

    7-3 字符转换 (13分) 本题要求提取一个字符串中的所有数字字符('0'--'9'),将其转换为一个整数输出. 输入格式: 输入在一行中给出一个不超过80个字符且以回车结束的字符串. 输出格式: ...

  5. 本题要求提取一个字符串中的所有数字字符(‘0‘……‘9‘),将其转换为一个整数输出。

    本题要求提取一个字符串中的所有数字字符('0'--'9'),将其转换为一个整数输出. 输入格式: 输入在一行中给出一个不超过80个字符且以回车结束的字符串. 输出格式: 在一行中输出转换后的整数.题目 ...

  6. JAVA记录从键盘输入的正数和负数的个数(0结束)

    JAVA记录从键盘输入的正数和负数的个数(0结束) 从键盘输入的个数不确定的整数,并判断正数和负数的个数,输入为0时结束 代码 Scanner scan=new Scanner(System.in); ...

  7. OKR测试试卷模板(0基础)

    此试卷适合0基础测试. 满分为100分,测试时间15-20min左右,具体题型设置为:判断题.单选题.多选题. OKR测试试卷模板(0基础) 一.判断题(共6题,每题5分,总分30分) OKR 是英文 ...

  8. python笔记4:数据归一化(0,1),归至(-1,1)

    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 python笔记4:数据归一化(0,1),归至(-1,1) 一.pytorch里tensor数据归一化 1.tensor数组全局归一化 ...

  9. 5.从键盘接收一百分制成绩 (0~100)

    完整题目:从键盘接收一百分制成绩 (0~100), 要求输出其对应的成绩等级 A~E. 其中,90 分以上为 'A' , 80~89分为 'B' , 70~79 分为'C' , 60~69 分为 'D ...

  10. 从键盘接收一百分制成绩( 0~100),要求输出其对应的成绩等级 A~E。其中,90 分以上为'A',80~89 分为'B', 70~79分为'C', 60~69分为'D', 60 分以下为'E'。

    从键盘接收一百分制成绩( 0~100),要求输出其对应的成绩等级 A~E. 其中,90 分以上为 'A',80~89 分为 'B', 70~79分为 'C', 60~69分为 'D', 60 分以下为 ...

最新文章

  1. php中创建关联数组,以及遍历数组
  2. MVC+Ninject+三层架构+代码生成 -- 总结(一、數據庫)
  3. linux 无响应_系统加固之Linux安全加固
  4. 利用事件进行窗体间传值
  5. 文献学习(part20)--Sparse Subspace Clustering: Algorithm, Theory, and Applications
  6. 锁表的进程和语句,并杀掉
  7. 记录一下使用vue/vuex+SSR框架遇到的bug
  8. 备份自己的myeclipse快捷键到需要的环境
  9. 移动开发框架,第【三】弹:Zepto.js
  10. 推荐给大家一个恶搞代码,让你的好友电脑关机----关机代码
  11. 杯具了~湖北省浠水县国家税务局局长叫作「操高潮」 (豆瓣 我们爱讲冷笑话小组)...
  12. Win7蓝牙标志不见了, 如何找回?
  13. 做了三年数据分析,给你的几点建议
  14. java base是什么文件_JavaBase 面向对象
  15. 学计算机的怎样提升打字速度,想提高打字速度吗?
  16. Service Principal 介绍
  17. python opencv单目测距 小孔成像原理
  18. sio.savemat得到空struct解决方法
  19. 正则表达式——匹配规则
  20. 码云的一些总结(普通用户版本仓库大于500M上传受限制)

热门文章

  1. 电驴服务器图标显示叉叉,2012年6月最新电驴服务器列表及设置方法
  2. 换电脑了怎么迁移旧电脑数据?教你一招,轻松搞定!
  3. ubuntu下怎样安装星际译王stardict和下载本地词典
  4. ndows优化大师 免费版,Windows7优化大师
  5. wordpress php幻灯片代码,WordPress无需插件实现幻灯片效果
  6. 计算机显示发送报告,Word文档打不开提示发送错误报告的解决方法
  7. 【新冠疫苗预约】Fiddler抓包新冠疫苗预约接口及脚本实现
  8. 富士通Fujitsu DPK1180K 打印机驱动
  9. ads设计Doherty功放(2)
  10. CSF2020大作业