From cf68147d08352ef27c336fc7ee3e962e8050cff2 Mon Sep 17 00:00:00 2001 From: luqingjie <544309509@qq.com> Date: Fri, 6 Nov 2026 21:18:56 -0500 Subject: [PATCH] =?UTF-8?q?=E9=82=A3=E6=89=A7=E8=A1=8C=E5=99=A8=E6=94=B9?= =?UTF-8?q?=E6=88=90http=EF=BC=8C=E6=94=AF=E4=BB=98=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E6=8C=87=E5=AE=9Ahttp=E8=B0=83=E7=94=A8=E5=92=8Chttps=E8=B0=83?= =?UTF-8?q?=E7=94=A8=EF=BC=8C=E5=A6=82=E6=9E=9Chttps=EF=BC=8C=E4=BD=BF?= =?UTF-8?q?=E7=94=A8nginx=E8=BD=AC=E5=8F=91=EF=BC=8C=E6=8F=90=E4=BE=9Bngin?= =?UTF-8?q?x=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/chain-executor.md | 27 ++++++++----- .../system/chain/ChainExecutorClient.java | 6 +-- usdt-chain-executor/env | 4 +- usdt-chain-executor/env.sh | 2 - .../nginx/usdt-chain-executor.conf | 33 +++++++++++++++ usdt-chain-executor/rent-truststore.p12 | Bin 1130 -> 0 bytes .../executor/IntranetExecutionServer.java | 38 +++--------------- 7 files changed, 60 insertions(+), 50 deletions(-) create mode 100644 usdt-chain-executor/nginx/usdt-chain-executor.conf delete mode 100644 usdt-chain-executor/rent-truststore.p12 diff --git a/docs/chain-executor.md b/docs/chain-executor.md index 78c4737..6a302a2 100644 --- a/docs/chain-executor.md +++ b/docs/chain-executor.md @@ -8,7 +8,7 @@ 支付后端 `CHAIN_EXECUTOR_ENABLED` 默认 `false`,此时直接执行原密码代码,既不访问内网服务,也不依赖新增表。 -启用后,支付后端启动时先调用 `GET /internal/v1/connectivity` 验证 TLS、来源白名单和服务令牌, +启用后,支付后端启动时先调用 `GET /internal/v1/connectivity` 验证传输链路、来源白名单和服务令牌, 再调用 `GET /internal/v1/readiness` 验证数据库钱包网络和配置密码。两项必须同时通过,否则支付后端拒绝启动并输出受控诊断日志。 启用后,用户输入密码时本地执行,未输入密码时仅允许交给已就绪的内网服务。两种方式共用执行记录和受控交易构造, 执行前实时校验余额、资源和链上费率。`RESOURCE_ONLY` 缺口拒绝;`DIRECT` 检查燃烧预算及全局 `trx_num` 保留量。 @@ -19,7 +19,7 @@ 1. 备份并执行 `sql/chain_executor.sql`,只新增执行记录表,不重建原表。 2. 使用 JDK 8 构建:`mvn -pl usdt-chain-executor -am package -DskipTests`。 3. 给独立执行器配置下表环境变量,再启动 `java -jar usdt-chain-executor/target/usdt-chain-executor-3.4.0.jar`。 -4. 验证监听地址、来源白名单、TLS 和服务认证后,再配置支付后端环境变量并部署前端。 +4. 验证监听地址、来源白名单和服务认证;HTTPS 部署还需验证 Nginx 与证书,再配置支付后端。 5. 首次在 NILE 验证。没有执行过真实交易的构建/隔离测试不能替代实际部署验收。 禁止把真实配置密码写在脚本、命令行参数、Git 文件或支付后端配置中。通过进程管理器的受控环境注入。 @@ -29,7 +29,7 @@ | 变量 | 含义 | | --- | --- | | `CHAIN_EXECUTOR_BIND_ADDRESS` | 必填,本机明确 IPv4;只接受 `10/8`、`172.16/12`、`192.168/16` 或 `127/8` | -| `CHAIN_EXECUTOR_PORT` | 必填,独立监听端口,例如 `9088` | +| `CHAIN_EXECUTOR_PORT` | 必填,HTTP 监听端口;Nginx 模式建议使用回环端口 `9089` | | `CHAIN_EXECUTOR_ALLOWED_IPS` | 必填,支付后端实际 TCP 来源 IPv4,逗号分隔,逐个精确匹配;不支持通配/CIDR | | `CHAIN_EXECUTOR_TOKEN` | 必填,至少 32 位的独立随机服务凭据;与后端配置相同,不是钱包密码 | | `CHAIN_EXECUTOR_CONFIGURATION_PASSWORD` | 必填,当前全局钱包配置密码,仅在执行器进程内存中使用 | @@ -37,8 +37,6 @@ | `CHAIN_EXECUTOR_BROADCAST_ENABLED` | 必填,只有明确为 `true` 才启动 | | `CHAIN_EXECUTOR_DB_URL` | 与支付后端相同数据库;使用 `connectionTimeZone=LOCAL&forceConnectionTimeZoneToSession=true` | | `CHAIN_EXECUTOR_DB_USER` / `CHAIN_EXECUTOR_DB_PASSWORD` | 独立最小权限数据库账号及密码 | -| `CHAIN_EXECUTOR_TLS_KEYSTORE` | 非回环监听必填,PKCS12 证书库的绝对路径 | -| `CHAIN_EXECUTOR_TLS_PASSWORD` | 证书库密码 | | `TRON_GRID_API_KEY` / `TRON_SCAN_API_KEY` | 按实际节点配置,沿用共享 TRON 客户端 | 独立执行器数据库权限:`usdt_config`、`wallet_address`、`usdt_payout_order`、 @@ -50,17 +48,27 @@ | 变量 | 含义 | | --- | --- | | `CHAIN_EXECUTOR_ENABLED` | 启用双通道时设 `true` | -| `CHAIN_EXECUTOR_BASE_URL` | 无尾斜杠/路径的根地址,例如 `https://192.168.10.20:9088` | +| `CHAIN_EXECUTOR_BASE_URL` | 无尾斜杠/路径的 HTTP 或 HTTPS 根地址,例如 `http://192.168.10.20:9088` 或 `https://192.168.10.20:9088` | | `CHAIN_EXECUTOR_TOKEN` | 独立服务凭据,与执行器一致 | -仅回环地址允许 HTTP;跨机器强制 HTTPS。证书 SAN 必须包含配置的内网 IP,支付后端 JVM 需信任签发 CA。 -使用 JVM trustStore 配置受信 CA,禁止关闭证书校验。只支持 IPv4 字面地址,不接受域名,避免 DNS 重绑定和意外公网解析。 +执行器自身只提供 HTTP。支付后端可使用 HTTP 直连,或使用 HTTPS 调用同机 Nginx,由 Nginx 转发到回环 HTTP。 +生产跨机器调用推荐 HTTPS;证书 SAN 必须包含配置的内网 IP,支付后端 JVM 需信任签发 CA,禁止关闭证书校验。 +只支持 IPv4 字面地址,不接受域名,避免 DNS 重绑定和意外公网解析。Nginx 示例见 +`usdt-chain-executor/nginx/usdt-chain-executor.conf`。 + +### HTTPS + Nginx 推荐配置 + +执行器配置为 `CHAIN_EXECUTOR_BIND_ADDRESS=127.0.0.1`、`CHAIN_EXECUTOR_PORT=9089`、 +`CHAIN_EXECUTOR_ALLOWED_IPS=127.0.0.1`。Nginx 使用内网 IP 的 `9088` 端口终止 TLS并转发到 +`http://127.0.0.1:9089`。支付后端配置 `CHAIN_EXECUTOR_BASE_URL=https://内网IP:9088`。 +执行器不读取证书或私钥;`CHAIN_EXECUTOR_TLS_KEYSTORE` 和 `CHAIN_EXECUTOR_TLS_PASSWORD` 已废弃。 ## 仅内网访问 - 服务拒绝 `0.0.0.0`、公网、域名、IPv6 和未配置白名单的启动方式。 - 所有 HTTP 路径统一检查真实 TCP 对端 IP 和独立 Bearer 凭据;健康检查也不例外。 -- 不信任 `X-Forwarded-For` 或其他代理头。默认直接从支付后端调用,不经过反向代理。 +- 不信任 `X-Forwarded-For` 或其他代理头。经 Nginx 转发时执行器白名单应配置为 `127.0.0.1`, + Nginx 自身再用 `allow/deny` 限制支付后端真实来源 IP。 - 防火墙/安全组仅允许支付后端指定内网 IP 访问执行端口,其他来源全部拒绝。 - 禁止配置公网 NAT、端口转发、公网反向代理和公网 Ingress;容器部署只发布到宿主机指定内网地址。 - 前端只访问现有支付后端;执行器地址、凭据、密码、信封和签名交易不返回浏览器。 @@ -69,6 +77,7 @@ ## 协议与执行流程 +- `GET /internal/v1/connectivity`:鉴权后验证传输链路,成功返回纯文本 `CONNECTED`。 - `GET /internal/v1/readiness`:鉴权后验证当前配置密码和网络,成功返回纯文本 `READY`,未就绪返回 503。 - `POST /internal/v1/executions`:鉴权后接收空正文通知,返回 202;只唤醒数据库扫描,不接收任意交易参数。 - `GET /system/chainExecutor/status`:现有后端登录鉴权入口,返回可用性和当前操作人最近 5 条公开执行记录。 diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/chain/ChainExecutorClient.java b/ruoyi-system/src/main/java/com/ruoyi/system/chain/ChainExecutorClient.java index 9a45597..2e26ee2 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/chain/ChainExecutorClient.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/chain/ChainExecutorClient.java @@ -49,11 +49,11 @@ public class ChainExecutorClient { java.net.InetAddress address = IntranetAddress.parse(target.getHost()); if (target.getRawUserInfo() != null || target.getRawQuery() != null || target.getRawFragment() != null || target.getPath() != null && !target.getPath().isEmpty() - || !("https".equals(target.getScheme()) || address.isLoopbackAddress() && "http".equals(target.getScheme())) + || !("https".equals(target.getScheme()) || "http".equals(target.getScheme())) || token == null || token.length() < 32) { - throw new IllegalArgumentException("内网执行服务需配置内网 HTTPS 根地址和至少32位服务凭据;仅回环允许 HTTP"); + throw new IllegalArgumentException("内网执行服务需配置内网 HTTP/HTTPS 根地址和至少32位服务凭据"); } - log.info("内网链上执行通道已启用,开始验证执行器服务"); + log.info("内网链上执行通道已启用,开始验证执行器服务,传输协议={}", target.getScheme().toUpperCase()); requireResponse("/internal/v1/connectivity", "CONNECTED", "联通测试"); requireResponse("/internal/v1/readiness", "READY", "业务就绪检查"); log.info("内网链上执行器服务验证通过,联通状态=CONNECTED,业务状态=READY"); diff --git a/usdt-chain-executor/env b/usdt-chain-executor/env index dc5cb49..06dbfa1 100644 --- a/usdt-chain-executor/env +++ b/usdt-chain-executor/env @@ -9,6 +9,4 @@ CHAIN_EXECUTOR_PORT=9088 CHAIN_EXECUTOR_ALLOWED_IPS=192.168.3.103,192.168.3.106 CHAIN_EXECUTOR_CONFIGURATION_PASSWORD=lqj7667213.520 CHAIN_EXECUTOR_ALLOWED_NETWORK=NILE -CHAIN_EXECUTOR_BROADCAST_ENABLED=true -CHAIN_EXECUTOR_TLS_KEYSTORE=/etc/nginx/certs/rent-truststore.p12 -CHAIN_EXECUTOR_TLS_PASSWORD=lqj7667213 \ No newline at end of file +CHAIN_EXECUTOR_BROADCAST_ENABLED=true \ No newline at end of file diff --git a/usdt-chain-executor/env.sh b/usdt-chain-executor/env.sh index dc5d512..acf66b6 100644 --- a/usdt-chain-executor/env.sh +++ b/usdt-chain-executor/env.sh @@ -10,5 +10,3 @@ export CHAIN_EXECUTOR_ALLOWED_IPS=192.168.3.103,192.168.3.106 export CHAIN_EXECUTOR_CONFIGURATION_PASSWORD=lqj7667213.520 export CHAIN_EXECUTOR_ALLOWED_NETWORK=NILE export CHAIN_EXECUTOR_BROADCAST_ENABLED=true -export CHAIN_EXECUTOR_TLS_KEYSTORE=/etc/nginx/certs/rent-truststore.p12 -export CHAIN_EXECUTOR_TLS_PASSWORD=lqj7667213 diff --git a/usdt-chain-executor/nginx/usdt-chain-executor.conf b/usdt-chain-executor/nginx/usdt-chain-executor.conf new file mode 100644 index 0000000..8897225 --- /dev/null +++ b/usdt-chain-executor/nginx/usdt-chain-executor.conf @@ -0,0 +1,33 @@ +# usdt-chain-executor HTTPS 反向代理。 +# 执行器应监听 127.0.0.1:9089;Nginx 在内网地址 192.168.3.106:9088 提供 HTTPS。 +# 上线前按实际部署修改 listen、allow、证书路径,并确保防火墙不向公网开放 9088。 +server { + listen 192.168.3.106:9088 ssl; + server_name 192.168.3.106; + + ssl_certificate /etc/nginx/certs/rent-cert.pem; + ssl_certificate_key /etc/nginx/certs/rent-private.key; + ssl_protocols TLSv1.2 TLSv1.3; + ssl_session_cache shared:chain_executor_tls:10m; + ssl_session_timeout 10m; + + # 示例为支付系统所在内网地址;部署时必须改成实际来源IP。 + allow 192.168.3.106; + deny all; + + location /internal/v1/ { + proxy_pass http://127.0.0.1:9089; + proxy_http_version 1.1; + proxy_set_header Connection ""; + proxy_set_header Authorization $http_authorization; + proxy_set_header Host $host; + proxy_connect_timeout 2s; + proxy_read_timeout 5s; + proxy_send_timeout 5s; + proxy_buffering off; + } + + location / { + return 404; + } +} diff --git a/usdt-chain-executor/rent-truststore.p12 b/usdt-chain-executor/rent-truststore.p12 deleted file mode 100644 index e493ba608490490260b8e356190608dc46cd3135..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1130 zcmV-w1eNIxIjw zP1*~F!z{G6$>eom>a|7d6O1UyE8{QxwzbKU6*&4| zesoC~;Yd-xIEF_?`^Mr~sC*QTpk>1H6vkY(eV{%O&RB_771Ks(GfG+>C$7G=BR+Eq zf-Qq6qX)WGnl)0&>5ruVvOEpIT+;ybaeb}?a}gf--jtQt#rm7jlEB`)4}V}U|CG72 z@&`ODSrY-&t$&c%TK?_(rHRTHI;~k3$D`y$k<7?KwADOB!vMMi3STu>)^o zq*Co2+MBdW+P1LBNmHf=Fg+(WUTG9keBa)?_mQNq%x|}ky@GaaH<=M(%iO;qCW$=r zds^up;_EEK2^@BD6FSzBKSLivc5GS zM?f_%YSo1hN3cPeP7-(LSz_7^Y3KdKwhUesf&_$a>h%|&l> z420)<1Ljc^RAYMor#I4_{*&}<;$M5utQPC9oQrPIlAgtM`51Q8al56P09F*~3D7?x zmm6Z}a;bkEPJ+MVt}e^1=aL>X=iG;S3BsyejM89w?AdRK3rS5b(Dyn<;eHcLfoJ6~ z{O_3OnK<*o0 zu!=c-Qu{jydwER0!3TlLY{iI`AgX}>=Lp@bk5&cICL|@jm%T$VxqaSIc=Nwy-?9LS zvY1B^CtDKQoPOa0Q}>