焊接型球头杆端关节轴承鱼眼接头缺陷检测数据集VOC+YOLO格式3205张4类别
2026/5/22 19:37:04
mTLS(Mutual TLS)是一种双向认证机制,服务之间相互验证身份,确保通信安全。
┌─────────────────┐ ┌─────────────────┐ │ Service A │ │ Service B │ │ (客户端) │ │ (服务端) │ └────────┬────────┘ └────────┬────────┘ │ │ │ 1. ClientHello (支持的加密套件) │ │─────────────────────────────────────>│ │ │ │ 2. ServerHello + 服务端证书 │ │<─────────────────────────────────────│ │ │ │ 3. 客户端证书 + ClientKeyExchange │ │─────────────────────────────────────>│ │ │ │ 4. 服务端验证客户端证书 │ │ │ │ 5. 双方计算会话密钥 │ │ │ │ 6. 加密通信开始 │ │<─────────────────────────────────────>│ │ │ └───────────────────────────────────────┘┌─────────────────────────────────────────────────────────────┐ │ Istio Control Plane │ │ ┌─────────────────┐ ┌─────────────────┐ │ │ │ Citadel │ │ Pilot │ │ │ │ (证书管理) │ │ (配置下发) │ │ │ └────────┬────────┘ └────────┬────────┘ │ └───────────┼─────────────────────┼─────────────────────────┘ │ │ ▼ ▼ ┌─────────────────────────────────────────────────────────────┐ │ Data Plane │ │ ┌─────────────────┐ ┌─────────────────┐ │ │ │ Envoy Proxy │────────────>│ Envoy Proxy │ │ │ │ (sidecar) │ mTLS通信 │ (sidecar) │ │ │ │ Service A │ │ Service B │ │ │ └─────────────────┘ └─────────────────┘ │ └─────────────────────────────────────────────────────────────┘apiVersion: security.istio.io/v1beta1 kind: PeerAuthentication metadata: name: default namespace: istio-system spec: mtls: mode: STRICTapiVersion: security.istio.io/v1beta1 kind: PeerAuthentication metadata: name: default namespace: my-namespace spec: mtls: mode: PERMISSIVEapiVersion: security.istio.io/v1beta1 kind: PeerAuthentication metadata: name: my-service-policy namespace: my-namespace spec: selector: matchLabels: app: my-service mtls: mode: STRICTapiVersion: networking.istio.io/v1alpha3 kind: DestinationRule metadata: name: my-service-dr namespace: my-namespace spec: host: my-service.my-namespace.svc.cluster.local trafficPolicy: tls: mode: ISTIO_MUTUALapiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: my-service-vs namespace: my-namespace spec: hosts: - my-service.my-namespace.svc.cluster.local http: - route: - destination: host: my-service.my-namespace.svc.cluster.local subset: v1apiVersion: security.istio.io/v1beta1 kind: PeerAuthentication metadata: name: default namespace: istio-system spec: mtls: mode: STRICT --- apiVersion: networking.istio.io/v1alpha3 kind: DestinationRule metadata: name: default namespace: istio-system spec: host: "*.local" trafficPolicy: tls: mode: ISTIO_MUTUAL# 查看Pod的证书 kubectl exec -it my-pod -c istio-proxy -- cat /etc/certs/cert-chain.pem # 查看证书有效期 kubectl exec -it my-pod -c istio-proxy -- openssl x509 -in /etc/certs/cert-chain.pem -text -nooutapiVersion: "security.istio.io/v1beta1" kind: "MeshPolicy" metadata: name: "default" spec: peers: - mtls: credentialName: "my-cert" mode: STRICTapiVersion: v1 kind: Secret metadata: name: custom-ca namespace: istio-system data: root-cert.pem: <base64-encoded-root-cert> cert-chain.pem: <base64-encoded-cert-chain> key.pem: <base64-encoded-key># 全局策略 - 允许mTLS apiVersion: security.istio.io/v1beta1 kind: PeerAuthentication metadata: name: default namespace: istio-system spec: mtls: mode: PERMISSIVE # 命名空间策略 - 强制mTLS apiVersion: security.istio.io/v1beta1 kind: PeerAuthentication metadata: name: default namespace: sensitive spec: mtls: mode: STRICT # 工作负载策略 - 禁用mTLS apiVersion: security.istio.io/v1beta1 kind: PeerAuthentication metadata: name: legacy-service namespace: sensitive spec: selector: matchLabels: app: legacy mtls: mode: DISABLE# 检查mTLS配置 istioctl experimental analyze # 检查特定服务 istioctl pc secret my-pod -n my-namespace # 检查认证策略 istioctl get peerauthentication# 在Pod中测试mTLS连接 kubectl exec -it my-pod -c istio-proxy -- curl -v https://my-service.my-namespace.svc.cluster.local:8080# 查看Envoy配置 istioctl pc routes my-pod -n my-namespace # 查看Envoy TLS配置 kubectl exec -it my-pod -c istio-proxy -- curl localhost:15000/config_dump | jq '.configs[].dynamic_active_secrets'apiVersion: networking.istio.io/v1alpha3 kind: DestinationRule metadata: name: my-service namespace: my-namespace spec: host: my-service.my-namespace.svc.cluster.local trafficPolicy: connectionPool: http: maxRequestsPerConnection: 100 tls: mode: ISTIO_MUTUALapiVersion: networking.istio.io/v1alpha3 kind: DestinationRule metadata: name: my-service namespace: my-namespace spec: host: my-service.my-namespace.svc.cluster.local trafficPolicy: tls: mode: ISTIO_MUTUAL maxSessionAge: 300s maxSessionAgeGrace: 50sapiVersion: v1 kind: ConfigMap metadata: name: istio namespace: istio-system data: mesh: | accessLogFile: /dev/stdout defaultConfig: proxyMetadata: ISTIO_META_CERT_SDS_CACHE_SIZE: "1024"| 问题 | 原因 | 解决方案 |
|---|---|---|
| 连接拒绝 | mTLS模式不匹配 | 检查PeerAuthentication和DestinationRule配置 |
| 证书过期 | 证书轮换失败 | 检查Citadel日志,手动轮换证书 |
| 性能下降 | TLS握手开销 | 启用连接复用和会话缓存 |
| 证书验证失败 | CA配置错误 | 检查Secret中的证书链 |
# 查看Envoy日志 kubectl logs my-pod -c istio-proxy | grep -i tls # 查看Citadel日志 kubectl logs -n istio-system -l app=citadel # 查看Pilot日志 kubectl logs -n istio-system -l app=pilot | grep -i mTLS# 使用istioctl诊断 istioctl diagnose # 检查Pod的Envoy配置 istioctl proxy-config secret my-pod -n my-namespace # 测试mTLS连接 kubectl exec -it my-pod -- istioctl experimental mTLS-check my-service.my-namespace.svc.cluster.localapiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: name: istio-mtls namespace: istio-system spec: selector: matchLabels: app: istio-pilot endpoints: - port: http-monitoring path: /metrics interval: 30s通过合理配置Istio mTLS,可以为服务间通信提供强大的安全保障,同时保持良好的性能表现。