feat(binding): 连接四态验证、密钥尾号与私网 http 放行
build / build (push) Successful in 1m45s

在既有 kbbinding(迁移 000081)上补齐任务要求,不另建表、不另起路由:
- 测试连接区分 401/403(密钥无效 / 无权限)与不可达、成功四态;
- 视图回显密钥尾 4 位(服务端不存、不回读明文);
- key_action=clear 作为独立动作,清除后解析失败关闭、不回落文件旧 Key;
- 内外库留空 = 取消绑定,回报回退来源(测试侧部署默认库 / 生产侧同 ID 语义);
- 生产绑定回报在飞执行的冻结/仍可改指向条数,已冻结目标不被改写;
- 新增 WEKNORA_ALLOW_PRIVATE_HTTP:客户端/探活/连接页共用 HTTPAllowed,
  只放行 RFC1918/回环/链路本地 http,生产 18093 同网段反代因此可用。
This commit is contained in:
狐友 GXXP & Miku
2026-11-22 15:46:13 +08:00
committed by 姚章浩
parent cb026e8dd1
commit 7d91343e5f
21 changed files with 528 additions and 73 deletions
+13 -6
View File
@@ -128,6 +128,10 @@ func run(ctx context.Context, getenv func(string) string) error {
kbbinding.EnvTest: config.TestWeKnoraAllowDockerHTTP,
kbbinding.EnvProduction: config.ProductionWeKnoraAllowDockerHTTP,
},
AllowPrivateHTTP: map[string]bool{
kbbinding.EnvTest: config.WeKnoraAllowPrivateHTTP,
kbbinding.EnvProduction: config.WeKnoraAllowPrivateHTTP,
},
LegacyBaseURL: func(resolveCtx context.Context, env string) string {
settings, err := actionStore.GetActiveUISettings(resolveCtx)
if err != nil {
@@ -194,9 +198,10 @@ func run(ctx context.Context, getenv func(string) string) error {
return target, nil
}
readinessProber := readiness.Prober{
Resolve: readinessResolver,
Timeout: config.TestWeKnoraHTTPTimeout,
AllowDockerHTTP: config.TestWeKnoraAllowDockerHTTP,
Resolve: readinessResolver,
Timeout: config.TestWeKnoraHTTPTimeout,
AllowDockerHTTP: config.TestWeKnoraAllowDockerHTTP,
AllowPrivateHTTP: config.WeKnoraAllowPrivateHTTP,
}
weknoraProbe := func(probeCtx context.Context) (string, error) {
result := readinessProber.Check(probeCtx)
@@ -207,10 +212,11 @@ func run(ctx context.Context, getenv func(string) string) error {
connection, err := kbBindings.Resolve(resolveCtx, kbbinding.EnvTest)
return connection.BaseURL, connection.APIKey, err
},
timeout: config.TestWeKnoraHTTPTimeout,
allowDockerHTTP: config.TestWeKnoraAllowDockerHTTP,
timeout: config.TestWeKnoraHTTPTimeout,
allowDockerHTTP: config.TestWeKnoraAllowDockerHTTP,
allowPrivateHTTP: config.WeKnoraAllowPrivateHTTP,
}
monitorProvider, err := monitoring.NewRealProvider(monitoring.RealProviderConfig{DB: pool, WeKnoraBaseURL: config.TestWeKnoraBaseURL, TestWeKnoraResolver: testEndpointResolver, ProductionWeKnoraBaseURL: config.ProductionWeKnoraBaseURL, ProductionWeKnoraResolver: productionEndpointResolver, MinerUBaseURL: config.MinerUBaseURL, WeKnoraReadiness: weknoraProbe, WorkerStaleAfter: config.WorkerLivenessStaleAfter})
monitorProvider, err := monitoring.NewRealProvider(monitoring.RealProviderConfig{DB: pool, WeKnoraBaseURL: config.TestWeKnoraBaseURL, TestWeKnoraResolver: testEndpointResolver, ProductionWeKnoraBaseURL: config.ProductionWeKnoraBaseURL, ProductionWeKnoraResolver: productionEndpointResolver, MinerUBaseURL: config.MinerUBaseURL, WeKnoraReadiness: weknoraProbe, WorkerStaleAfter: config.WorkerLivenessStaleAfter, AllowPrivateHTTP: config.WeKnoraAllowPrivateHTTP})
if err != nil {
return err
}
@@ -292,6 +298,7 @@ func run(ctx context.Context, getenv func(string) string) error {
ProductionBindings: postgresstore.NewStore(pool),
ProductionKnowledgeBases: productionKnowledgeBases,
KBBindings: kbBindings,
WeKnoraAllowPrivateHTTP: config.WeKnoraAllowPrivateHTTP,
ProductionWeKnoraBaseURL: config.ProductionWeKnoraBaseURL,
ServiceTargetVerifier: serviceTargetVerifier,
ProductionReleaseRequestsEnabled: config.ProductionReleaseRequestsEnabled,
+10 -8
View File
@@ -52,9 +52,10 @@ func newWeKnoraReadinessResolver(
// weKnoraLister 让「系统设置」的知识库下拉与保存校验同样跟随当前端点/凭据,
// 而不是复用启动时的客户端(否则改端点后选项仍来自旧实例)。
type weKnoraLister struct {
resolve func(context.Context) (baseURL, apiKey string, err error)
timeout time.Duration
allowDockerHTTP bool
resolve func(context.Context) (baseURL, apiKey string, err error)
timeout time.Duration
allowDockerHTTP bool
allowPrivateHTTP bool
}
func (lister *weKnoraLister) ListKnowledgeBases(ctx context.Context) ([]weknora.KnowledgeBase, error) {
@@ -76,7 +77,7 @@ func (lister *weKnoraLister) ListKnowledgeBases(ctx context.Context) ([]weknora.
if timeout <= 0 || timeout > 10*time.Second {
timeout = 10 * time.Second
}
client, err := weknora.NewClient(weknora.ClientConfig{BaseURL: baseURL, APIKey: apiKey, Timeout: timeout, AllowDockerHTTP: lister.allowDockerHTTP})
client, err := weknora.NewClient(weknora.ClientConfig{BaseURL: baseURL, APIKey: apiKey, Timeout: timeout, AllowDockerHTTP: lister.allowDockerHTTP, AllowPrivateHTTP: lister.allowPrivateHTTP})
if err != nil {
return nil, err
}
@@ -87,9 +88,10 @@ func (lister *weKnoraLister) ListKnowledgeBases(ctx context.Context) ([]weknora.
// (加密密钥),而不是另一条文件凭据。显式传入的地址必须与已保存连接一致,
// 防止把生产密钥发往另一个地址。
type productionKnowledgeBaseLister struct {
bindings *kbbinding.Store
timeout time.Duration
allowDockerHTTP bool
bindings *kbbinding.Store
timeout time.Duration
allowDockerHTTP bool
allowPrivateHTTP bool
}
func (lister *productionKnowledgeBaseLister) ListProductionKnowledgeBases(ctx context.Context, baseURL string) ([]weknora.KnowledgeBase, error) {
@@ -107,7 +109,7 @@ func (lister *productionKnowledgeBaseLister) ListProductionKnowledgeBases(ctx co
if timeout <= 0 || timeout > 10*time.Second {
timeout = 10 * time.Second
}
client, err := weknora.NewClient(weknora.ClientConfig{BaseURL: target.BaseURL, APIKey: target.APIKey, Timeout: timeout, AllowDockerHTTP: lister.allowDockerHTTP})
client, err := weknora.NewClient(weknora.ClientConfig{BaseURL: target.BaseURL, APIKey: target.APIKey, Timeout: timeout, AllowDockerHTTP: lister.allowDockerHTTP, AllowPrivateHTTP: lister.allowPrivateHTTP})
if err != nil {
return nil, err
}