
如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。
只需在 AI 对话中先发送下面这句话即可:
请先完整阅读并严格遵守以下文档中的全部规则与要求:
https://xuanyuan.cloud/agents.md
在未充分阅读并理解该文档前,不要生成任何命令、配置、修改建议、故障排查方案或技术回答。后续所有输出都必须严格以该文档中的规范为最高优先级执行。查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。
Ghostunnel是一个轻量级TLS代理工具,支持双向认证,用于保护非TLS后端应用。它提供客户端和服务器两种运行模式,可替代stunnel,实现安全的网络通信代理。
支持平台:Linux(x86-64推荐)、Darwin(macOS)、FreeBSD、OpenBSD、NetBSD及Windows(功能受限)。
bash# 查看帮助 ghostunnel --help ghostunnel server --help ghostunnel client --help
需准备以下证书文件(可通过certstrap或OpenSSL生成):
cacert.pem)功能说明
监听TLS连接,解密后转发至后端服务。
基本参数
| 参数 | 说明 |
|---|---|
--listen | 监听TLS连接的地址(格式:host:port或UNIX域套接字路径) |
--target | 后端服务地址(格式:host:port或UNIX域套接字路径) |
--keystore | 服务器证书密钥库(PKCS#12或PEM格式,自动检测) |
--cert/--key | 分离的证书链和私钥文件(PEM格式,替代--keystore) |
--cacert | 信任的CA证书文件(PEM格式) |
--allow-all | 允许所有有效证书的客户端连接 |
--allow-cn | 允许指定CN的客户端证书(可多次指定) |
--allow-ou | 允许指定OU的客户端证书(可多次指定) |
--allow-dns | 允许指定DNS SAN的客户端证书(可多次指定) |
--allow-uri | 允许指定URI SAN的客户端证书(可多次指定) |
--status | 状态监控端口(格式:host:port或UNIX域套接字路径) |
--timed-reload | 证书定时重载间隔(如300s) |
--quiet | 抑制指定类型日志(conns/conn-errs/handshake-errs/all) |
使用示例
启动后端服务(如netcat):
bashnc -l localhost 8080
启动Ghostunnel服务器模式:
bashghostunnel server \ --listen localhost:8443 \ --target localhost:8080 \ --keystore server-keystore.p12 \ --cacert cacert.pem \ --allow-cn client \ --status localhost:8081 \ --timed-reload 300s
客户端连接测试:
bashopenssl s_client \ -connect localhost:8443 \ -cert client-combined.pem \ -key client-combined.pem \ -CAfile cacert.pem
功能说明
监听不安全连接,加密后转发至TLS服务。
基本参数
| 参数 | 说明 |
|---|---|
--listen | 监听本地连接的地址(格式:host:port或UNIX域套接字路径) |
--target | 远程TLS服务地址(格式:host:port) |
--keystore | 客户端证书密钥库(PKCS#12或PEM格式,自动检测) |
--cert/--key | 分离的证书链和私钥文件(PEM格式,替代--keystore) |
--cacert | 信任的CA证书文件(PEM格式) |
--server-cn | 验证服务器证书的CN(可选) |
--status | 状态监控端口(格式:host:port或UNIX域套接字路径) |
--timed-reload | 证书定时重载间隔(如300s) |
使用示例
启动TLS后端服务:
bashopenssl s_server \ -accept 8443 \ -cert server-combined.pem \ -key server-combined.pem \ -CAfile cacert.pem
启动Ghostunnel客户端模式:
bashghostunnel client \ --listen localhost:8080 \ --target localhost:8443 \ --keystore client-keystore.p12 \ --cacert cacert.pem \ --status localhost:8081
测试连接:
bashnc -v localhost 8080
功能说明
组合客户端和服务器模式,实现端到端加密隧道。
部署步骤
启动最终后端服务:
bashnc -l localhost 8001
启动服务器端Ghostunnel:
bashghostunnel server \ --listen localhost:8002 \ --target localhost:8001 \ --keystore server-combined.pem \ --cacert cacert.pem \ --allow-cn client
启动客户端Ghostunnel:
bashghostunnel client \ --listen localhost:8003 \ --target localhost:8002 \ --keystore client-keystore.p12 \ --cacert cacert.pem
测试端到端连接:
bashnc -v localhost 8003
ghostunnel/ghostunnelbashdocker run -d \ --name ghostunnel-server \ -p 8443:8443 \ -p 8081:8081 \ -v $(pwd)/test-keys:/etc/ghostunnel/keys \ docker.xuanyuan.run/ghostunnel/ghostunnel \ server \ --listen 0.0.0.0:8443 \ --target backend-service:8080 \ --keystore /etc/ghostunnel/keys/server-keystore.p12 \ --cacert /etc/ghostunnel/keys/cacert.pem \ --allow-cn client \ --status 0.0.0.0:8081 \ --timed-reload 300s
bashdocker run -d \ --name ghostunnel-client \ -p 8080:8080 \ -v $(pwd)/test-keys:/etc/ghostunnel/keys \ docker.xuanyuan.run/ghostunnel/ghostunnel \ client \ --listen 0.0.0.0:8080 \ --target tls-service.example.com:443 \ --keystore /etc/ghostunnel/keys/client-keystore.p12 \ --cacert /etc/ghostunnel/keys/cacert.pem \ --server-cn tls-service.example.com
yamlversion: '3' services: ghostunnel-server: image: docker.xuanyuan.run/ghostunnel/ghostunnel ports: - "8443:8443" - "8081:8081" volumes: - ./test-keys:/etc/ghostunnel/keys command: > server --listen 0.0.0.0:8443 --target backend:8080 --keystore /etc/ghostunnel/keys/server-keystore.p12 --cacert /etc/ghostunnel/keys/cacert.pem --allow-cn client --status 0.0.0.0:8081 --timed-reload 300s depends_on: - backend backend: image: docker.xuanyuan.run/alpine command: nc -l -p 8080 ghostunnel-client: image: docker.xuanyuan.run/ghostunnel/ghostunnel ports: - "8080:8080" volumes: - ./test-keys:/etc/ghostunnel/keys command: > client --listen 0.0.0.0:8080 --target ghostunnel-server:8443 --keystore /etc/ghostunnel/keys/client-keystore.p12 --cacert /etc/ghostunnel/keys/cacert.pem
SIGUSR1信号至进程触发证书重载
bashkill -USR1 <ghostunnel-pid>
--timed-reload <interval>设置自动重载间隔(如--timed-reload 5m)--status <host:port>启用指标端点,支持以下路径:
/metrics:Prometheus格式指标/health:健康检查端点/debug/pprof:性能分析接口(需--enable-pprof)支持多种证书验证规则(逻辑OR关系,满足其一即可):
--allow-all:允许所有有效证书--allow-cn <cn>:验证客户端证书CN--allow-ou <ou>:验证客户端证书OU--allow-dns <dns>:验证客户端证书DNS SAN--allow-uri <uri>:验证客户端证书URI SAN(支持SPIFFE SVID)通过--quiet参数抑制特定类型日志:
--quiet=conns:抑制连接建立/关闭日志--quiet=conn-errs:抑制连接错误日志(握手后)--quiet=handshake-errs:抑制握手错误日志(适用于K8s健康检查场景)--quiet=all:抑制所有日志通过PKCS#11接口使用硬件安全模块保护私钥,需指定PKCS#11模块路径和槽信息:
bashghostunnel server \ --listen :8443 \ --target :8080 \ --pkcs11-module /usr/lib/pkcs11.so \ --pkcs11-token-label "MyToken" \ --pkcs11-pin "1234" \ --cacert cacert.pem \ --allow-cn client
支持从SPIFFE Workload API获取动态证书和CA:
bashghostunnel server \ --listen :8443 \ --target :8080 \ --spiffe-svid-path /run/spire/sockets/agent.sock \ --spiffe-allow-uri spiffe://example.org/service \ --cacert /run/spire/bundle/bundle.pem
您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
来自真实用户的反馈,见证轩辕镜像的优质服务