fix(agent): 自愈 HTTPS 直连地址并发布 v1.4.3
CI / verify (push) Canceled after 0s

This commit is contained in:
2026-09-28 14:30:35 +08:00
parent 4a29bcb249
commit 8c07e64e87
9 changed files with 100 additions and 19 deletions
+15
View File
@@ -2,6 +2,21 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
## [v1.4.3] - 2026-09-28
### 修复
- **HTTPS 直连旧地址自愈**:从 SSH 隧道切换到「HTTPS + 证书固定」后,历史实例的 `agent_url` 可能仍为已失效的 `http://127.0.0.1:17701`,隧道关闭后直接报 `connection refused`。现在读取 HTTPS transport 时会依据 `ssh_host` 与 `agent_listen_addr` 自动重建 `https://<host>:<port>`,并在地址变化时回写数据库;切回 SSH 隧道也使用同一重建逻辑,无需手工修改地址
### 变更
- 版本号提升到 1.4.3;`web/package.json` 与 `web/package-lock.json` 同步对齐
- `AgentVersion` 保持 0.13.0
### 测试
- `internal/frp`:新增 `TestAgentHTTPSBaseURL`,覆盖旧隧道地址重建、已是 HTTPS 地址保持、默认端口回退与缺少 SSH 主机的情况
## [v1.4.2] - 2026-09-28 ## [v1.4.2] - 2026-09-28
### 修复 ### 修复
+1 -1
View File
@@ -1 +1 @@
1.4.2 1.4.3
+1 -1
View File
@@ -1,7 +1,7 @@
# Fonu 文档索引 # Fonu 文档索引
> 维护约定:新增方案 / 审查文档时在下方登记;方案落地后在「状态」列标注实施结果,并给已被推翻的描述加时效说明。 > 维护约定:新增方案 / 审查文档时在下方登记;方案落地后在「状态」列标注实施结果,并给已被推翻的描述加时效说明。
> 最近更新:2026-09-28(v1.4.2) > 最近更新:2026-09-28(v1.4.3)
## 方案与设计(本目录) ## 方案与设计(本目录)
+4 -4
View File
@@ -238,16 +238,16 @@ FONU_VERSION=<旧版本> docker compose up -d --no-deps --force-recreate fonu
## 10. 在线升级验证 ## 10. 在线升级验证
示例页面用于验证升级结果。v1.4.2 的验证流程: 示例页面用于验证升级结果。v1.4.3 的验证流程:
1. 确认当前线上实例为 v1.3.0,且 `fonu-updater` sidecar 已运行。 1. 确认当前线上实例为 v1.3.0,且 `fonu-updater` sidecar 已运行。
2. 确认远端 `main` 分支的 `VERSION` 为 `1.4.2`。 2. 确认远端 `main` 分支的 `VERSION` 为 `1.4.3`。
3. 在侧栏看到「一键升级」后点击并确认。 3. 在侧栏看到「一键升级」后点击并确认。
4. 等待升级弹窗显示成功,页面自动刷新。 4. 等待升级弹窗显示成功,页面自动刷新。
5. 打开侧栏「示例页面」,确认: 5. 打开侧栏「示例页面」,确认:
- 页面路由为 `/example`; - 页面路由为 `/example`;
- 页面显示的版本为 `1.4.2`; - 页面显示的版本为 `1.4.3`;
- 页面显示验证标识 `v1.4.2-example-page`; - 页面显示验证标识 `v1.4.3-example-page`;
- 页面显示独立的「本次升级验证」区块; - 页面显示独立的「本次升级验证」区块;
- 「升级验证」显示为「通过」。 - 「升级验证」显示为「通过」。
+36
View File
@@ -46,3 +46,39 @@ func TestPinTLSConfigVerification(t *testing.T) {
t.Fatal("错误 pin 应校验失败") t.Fatal("错误 pin 应校验失败")
} }
} }
func TestAgentHTTPSBaseURL(t *testing.T) {
cases := []struct {
name string
server Server
want string
}{
{
name: "旧隧道地址按监听端口重建",
server: Server{AgentURL: "http://127.0.0.1:17701", SSHHost: "agent.example.com", AgentListenAddr: "0.0.0.0:7443"},
want: "https://agent.example.com:7443",
},
{
name: "已是 HTTPS 地址保持不变",
server: Server{AgentURL: "https://agent.example.com:8443", SSHHost: "agent.example.com", AgentListenAddr: "0.0.0.0:7443"},
want: "https://agent.example.com:8443",
},
{
name: "监听地址缺少端口时使用默认端口",
server: Server{AgentURL: "http://127.0.0.1:17701", SSHHost: "agent.example.com"},
want: "https://agent.example.com:7443",
},
{
name: "缺少 SSH 主机时保留原地址",
server: Server{AgentURL: "http://127.0.0.1:17701"},
want: "http://127.0.0.1:17701",
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
if got := agentHTTPSBaseURL(tc.server); got != tc.want {
t.Fatalf("agentHTTPSBaseURL() = %q, 期望 %q", got, tc.want)
}
})
}
}
+32 -2
View File
@@ -8,6 +8,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"sort" "sort"
"strconv"
"strings" "strings"
"sync" "sync"
"time" "time"
@@ -1009,7 +1010,7 @@ func (s *Service) SwitchAgentToTunnel(ctx context.Context, serverID int64) (Serv
if err != nil { if err != nil {
return Server{}, err return Server{}, err
} }
client := NewAgentClientWithPin(server.AgentURL, token, server.AgentTLSPin) client := NewAgentClientWithPin(agentHTTPSBaseURL(server), token, server.AgentTLSPin)
if err := client.DisableHTTPS(ctx); err != nil { if err := client.DisableHTTPS(ctx); err != nil {
return Server{}, fmt.Errorf("关闭 HTTPS 直连失败: %w", err) return Server{}, fmt.Errorf("关闭 HTTPS 直连失败: %w", err)
} }
@@ -1595,6 +1596,24 @@ func (s *Service) invalidateAgentClient(serverID int64) {
s.agentMu.Unlock() s.agentMu.Unlock()
} }
func agentHTTPSBaseURL(server Server) string {
current := strings.TrimRight(strings.TrimSpace(server.AgentURL), "/")
if strings.HasPrefix(strings.ToLower(current), "https://") {
return current
}
host := strings.TrimSpace(server.SSHHost)
if host == "" {
return current
}
port := 7443
if _, rawPort, err := net.SplitHostPort(strings.TrimSpace(server.AgentListenAddr)); err == nil {
if parsed, err := strconv.Atoi(rawPort); err == nil && parsed > 0 {
port = parsed
}
}
return fmt.Sprintf("https://%s:%d", host, port)
}
func (s *Service) agentClient(ctx context.Context, serverID int64) (*AgentClient, bool) { func (s *Service) agentClient(ctx context.Context, serverID int64) (*AgentClient, bool) {
server, err := s.store.GetServer(ctx, serverID) server, err := s.store.GetServer(ctx, serverID)
if err != nil || !server.MgmtEnabled || !server.AgentConfigured { if err != nil || !server.MgmtEnabled || !server.AgentConfigured {
@@ -1618,9 +1637,20 @@ func (s *Service) agentClient(ctx context.Context, serverID int64) (*AgentClient
baseURL = fmt.Sprintf("http://127.0.0.1:%d", tunnel.localPort) baseURL = fmt.Sprintf("http://127.0.0.1:%d", tunnel.localPort)
} else if server.AgentTransport == "https-pin" { } else if server.AgentTransport == "https-pin" {
pin = strings.TrimSpace(server.AgentTLSPin) pin = strings.TrimSpace(server.AgentTLSPin)
if baseURL == "" || pin == "" { if pin == "" {
return nil, false return nil, false
} }
baseURL = agentHTTPSBaseURL(server)
if !strings.HasPrefix(strings.ToLower(baseURL), "https://") {
return nil, false
}
if baseURL != strings.TrimRight(strings.TrimSpace(server.AgentURL), "/") {
err := s.store.SetAgentTransport(ctx, serverID, baseURL, "https-pin", server.AgentLocalPort,
pin, server.AgentListenAddr, server.AgentTransportState, server.AgentTransportError)
if err != nil {
s.logger.Warn("agent https url repair failed", "server_id", serverID, "error", err)
}
}
} else if baseURL == "" { } else if baseURL == "" {
return nil, false return nil, false
} }
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "fonu-web", "name": "fonu-web",
"version": "1.4.2", "version": "1.4.3",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "fonu-web", "name": "fonu-web",
"version": "1.4.2", "version": "1.4.3",
"dependencies": { "dependencies": {
"@codemirror/commands": "^6.11.1", "@codemirror/commands": "^6.11.1",
"@codemirror/lang-javascript": "^6.2.5", "@codemirror/lang-javascript": "^6.2.5",
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "fonu-web", "name": "fonu-web",
"private": true, "private": true,
"version": "1.4.2", "version": "1.4.3",
"packageManager": "npm@10.9.4", "packageManager": "npm@10.9.4",
"type": "module", "type": "module",
"scripts": { "scripts": {
+8 -8
View File
@@ -8,7 +8,7 @@
</template> </template>
</PageHeader> </PageHeader>
<n-alert type="success" :bordered="false" class="example-alert" title="v1.4.2 示例页面验证标识已生效"> <n-alert type="success" :bordered="false" class="example-alert" title="v1.4.3 示例页面验证标识已生效">
当前页面由 v{{ version }} 提供,验证标识为 <span class="mono">{{ verificationMarker }}</span>。 当前页面由 v{{ version }} 提供,验证标识为 <span class="mono">{{ verificationMarker }}</span>。
如果你是在升级后首次看到这行内容,说明前端构建、镜像重建和服务重启均已成功。 如果你是在升级后首次看到这行内容,说明前端构建、镜像重建和服务重启均已成功。
</n-alert> </n-alert>
@@ -19,7 +19,7 @@
<strong class="example-proof__value">{{ verificationRound }}</strong> <strong class="example-proof__value">{{ verificationRound }}</strong>
</div> </div>
<div class="example-proof__hint"> <div class="example-proof__hint">
看到这个新区块,说明前端资源已经从旧版本切换到 v1.4.2。 看到这个新区块,说明前端资源已经从旧版本切换到 v1.4.3。
</div> </div>
</div> </div>
@@ -33,16 +33,16 @@
<StatCard label="本次验证标识" :value="verificationMarker" sub="用于区分升级前后的前端资源" tone="blue" value-small> <StatCard label="本次验证标识" :value="verificationMarker" sub="用于区分升级前后的前端资源" tone="blue" value-small>
<template #icon><n-icon :component="FlashOutline" /></template> <template #icon><n-icon :component="FlashOutline" /></template>
</StatCard> </StatCard>
<StatCard label="页面状态" value="已更新" sub="v1.4.2 前端资源已加载" tone="teal"> <StatCard label="页面状态" value="已更新" sub="v1.4.3 前端资源已加载" tone="teal">
<template #icon><n-icon :component="CheckmarkCircleOutline" /></template> <template #icon><n-icon :component="CheckmarkCircleOutline" /></template>
</StatCard> </StatCard>
</div> </div>
<FonuCard title="本次示例页变化" subtitle="用于确认升级后的页面内容确实发生变化"> <FonuCard title="本次示例页变化" subtitle="用于确认升级后的页面内容确实发生变化">
<ul class="example-changes"> <ul class="example-changes">
<li>页面版本提示更新为 v1.4.2。</li> <li>页面版本提示更新为 v1.4.3。</li>
<li>「本次升级验证」区块和页面状态同步更新为 v1.4.2。</li> <li>「本次升级验证」区块和页面状态同步更新为 v1.4.3。</li>
<li>验证标识更新为 <span class="mono">v1.4.2-example-page</span>。</li> <li>验证标识更新为 <span class="mono">v1.4.3-example-page</span>。</li>
</ul> </ul>
</FonuCard> </FonuCard>
@@ -87,8 +87,8 @@ const message = useMessage()
const version = ref(__APP_VERSION__) const version = ref(__APP_VERSION__)
const checkedAt = ref('') const checkedAt = ref('')
const refreshing = ref(false) const refreshing = ref(false)
const verificationRound = 'v1.4.2' const verificationRound = 'v1.4.3'
const verificationMarker = 'v1.4.2-example-page' const verificationMarker = 'v1.4.3-example-page'
async function refreshVersion() { async function refreshVersion() {
refreshing.value = true refreshing.value = true