在Solo.io Gloo中配置服务器端TLS加密通信
2025-06-12 04:15:55作者:田桥桑Industrious
概述
在现代微服务架构中,安全通信是至关重要的环节。Solo.io Gloo作为一款功能强大的API网关,提供了完善的TLS/SSL配置能力,可以轻松实现服务器端加密通信。本文将详细介绍如何在Gloo中配置服务器端TLS,包括基础TLS设置、mTLS双向认证以及多域名SNI支持。
基础TLS配置
准备工作
在开始配置TLS之前,我们需要准备一个示例环境:
- 部署示例应用petstore:
kubectl apply -f https://raw.githubusercontent.com/solo-io/gloo/v1.14.x/example/petstore/petstore.yaml
- 验证Upstream是否创建成功:
glooctl get upstream default-petstore-8080
- 创建基础路由:
glooctl add route \
--path-exact /sample-route-1 \
--dest-name default-petstore-8080 \
--prefix-rewrite /api/pets
生成证书
我们需要为服务器生成TLS证书:
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout tls.key -out tls.crt -subj "/CN=petstore.example.com"
创建Kubernetes Secret
将证书存储为Kubernetes Secret:
kubectl create secret tls upstream-tls --key tls.key \
--cert tls.crt --namespace gloo-system
或者使用glooctl命令:
glooctl create secret tls --name upstream-tls --certchain tls.crt --keyfile tls.key
配置Virtual Service
将TLS配置应用到Virtual Service:
glooctl edit virtualservice --name default --namespace gloo-system \
--ssl-secret-name upstream-tls --ssl-secret-namespace gloo-system
验证配置
验证TLS是否生效:
curl -k $(glooctl proxy url --port https)/sample-route-1
配置mTLS双向认证
生成客户端证书
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout mtls.key -out mtls.crt -subj "/CN=gloo.gloo-system.com"
创建包含CA的Secret
glooctl create secret tls --name downstream-mtls --certchain tls.crt --keyfile tls.key --rootca mtls.crt
更新Virtual Service配置
glooctl edit virtualservice --name default --namespace gloo-system \
--ssl-secret-name downstream-mtls --ssl-secret-namespace gloo-system
测试mTLS连接
不带客户端证书的请求会被拒绝:
curl -k $(glooctl proxy url --port https)/sample-route-1
带客户端证书的请求会成功:
curl --cert mtls.crt --key mtls.key -k $(glooctl proxy url --port https)/sample-route-1
多域名SNI支持
为第二个域名生成证书
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout tls.key -out tls.crt -subj "/CN=animalstore.example.com"
创建第二个Secret
kubectl create secret tls animal-certs --key tls.key \
--cert tls.crt --namespace gloo-system
创建第二个Virtual Service
glooctl create virtualservice --name animal --domains animalstore.example.com
配置SNI域名
glooctl edit virtualservice --name animal --namespace gloo-system \
--ssl-secret-name animal-certs --ssl-secret-namespace gloo-system \
--ssl-sni-domains animalstore.example.com
添加路由
glooctl add route --name animal\
--path-exact /animals \
--dest-name default-petstore-8080 \
--prefix-rewrite /api/pets
测试SNI配置
curl -k --resolve animalstore.example.com:443:$(kubectl get svc -n gloo-system gateway-proxy -o=jsonpath='{.status.loadBalancer.ingress[0].ip}') https://animalstore.example.com/animals
工作原理
Gloo Gateway通过以下机制实现TLS功能:
- 当Virtual Service没有SSL/TLS配置时,默认绑定到HTTP监听器(8080端口)
- 添加SSL/TLS配置后,Virtual Service会自动绑定到HTTPS监听器(8443端口)
- 多个Virtual Service可以共享同一个监听器的SSL配置
- SNI机制确保客户端请求能够匹配正确的证书
可以通过以下命令查看代理配置:
glooctl get proxy -n gloo-system gateway-proxy -o yaml
最佳实践
- 生产环境应使用正规CA签发的证书,而非自签名证书
- 为每个域名配置明确的SNI域,避免证书冲突
- 定期轮换证书和密钥
- 监控证书过期时间
- 考虑使用证书管理器自动管理证书
通过以上步骤,您可以在Gloo Gateway中实现完整的服务器端TLS加密通信,包括基础TLS、mTLS双向认证以及多域名支持,为您的微服务架构提供安全可靠的通信保障。
登录后查看全文
热门项目推荐
GLM-5智谱 AI 正式发布 GLM-5,旨在应对复杂系统工程和长时域智能体任务。Jinja00
GLM-5-w4a8GLM-5-w4a8基于混合专家架构,专为复杂系统工程与长周期智能体任务设计。支持单/多节点部署,适配Atlas 800T A3,采用w4a8量化技术,结合vLLM推理优化,高效平衡性能与精度,助力智能应用开发Jinja00
请把这个活动推给顶尖程序员😎本次活动专为懂行的顶尖程序员量身打造,聚焦AtomGit首发开源模型的实际应用与深度测评,拒绝大众化浅层体验,邀请具备扎实技术功底、开源经验或模型测评能力的顶尖开发者,深度参与模型体验、性能测评,通过发布技术帖子、提交测评报告、上传实践项目成果等形式,挖掘模型核心价值,共建AtomGit开源模型生态,彰显顶尖程序员的技术洞察力与实践能力。00
Kimi-K2.5Kimi K2.5 是一款开源的原生多模态智能体模型,它在 Kimi-K2-Base 的基础上,通过对约 15 万亿混合视觉和文本 tokens 进行持续预训练构建而成。该模型将视觉与语言理解、高级智能体能力、即时模式与思考模式,以及对话式与智能体范式无缝融合。Python00
MiniMax-M2.5MiniMax-M2.5开源模型,经数十万复杂环境强化训练,在代码生成、工具调用、办公自动化等经济价值任务中表现卓越。SWE-Bench Verified得分80.2%,Multi-SWE-Bench达51.3%,BrowseComp获76.3%。推理速度比M2.1快37%,与Claude Opus 4.6相当,每小时仅需0.3-1美元,成本仅为同类模型1/10-1/20,为智能应用开发提供高效经济选择。【此简介由AI生成】Python00
Qwen3.5Qwen3.5 昇腾 vLLM 部署教程。Qwen3.5 是 Qwen 系列最新的旗舰多模态模型,采用 MoE(混合专家)架构,在保持强大模型能力的同时显著降低了推理成本。00- RRing-2.5-1TRing-2.5-1T:全球首个基于混合线性注意力架构的开源万亿参数思考模型。Python00
项目优选
收起
deepin linux kernel
C
27
11
OpenHarmony documentation | OpenHarmony开发者文档
Dockerfile
567
3.83 K
本项目是CANN提供的数学类基础计算算子库,实现网络在NPU上加速计算。
C++
892
667
Ascend Extension for PyTorch
Python
376
446
openEuler内核是openEuler操作系统的核心,既是系统性能与稳定性的基石,也是连接处理器、设备与服务的桥梁。
C
349
200
昇腾LLM分布式训练框架
Python
116
145
🎉 (RuoYi)官方仓库 基于SpringBoot,Spring Security,JWT,Vue3 & Vite、Element Plus 的前后端分离权限管理系统
Vue
1.37 K
778
暂无简介
Dart
798
197
React Native鸿蒙化仓库
JavaScript
308
359
openJiuwen agent-studio提供零码、低码可视化开发和工作流编排,模型、知识库、插件等各资源管理能力
TSX
1.13 K
271