[PR #6565] [MERGED] fix(nodes): say which half of node mTLS failed, and say it as an error #6354

Closed
opened 2026-11-02 04:08:10 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6565
Author: @n0ctal
Created: 9/16/2026
Status: ✅ Merged
Merged: 9/16/2026
Merged by: @MHSanaei

Base: main ← Head: upstream-node-mtls-trust-bundle-diagnostics


📝 Commits (2)

  • f8e5d22 fix(nodes): say which half of node mTLS failed, and say it as an error
  • 2795737 test(nodes): drop a duplicate node mTLS trust-bundle test

📊 Changes

3 files changed (+33 additions, -4 deletions)

View changed files

📝 internal/web/service/setting_mtls.go (+5 -1)
📝 internal/web/service/setting_mtls_bundle_test.go (+19 -0)
📝 internal/web/web.go (+9 -3)

📄 Description

Summary

A node mTLS trust bundle that will not parse is reported exactly like a settings
read that failed, and both are warnings:

if pool, perr := s.settingService.NodeMtlsClientCAPool(); perr != nil {
    logger.Warning("node mTLS: failed to build client CA trust pool:", perr)
} else if pool != nil {
    applyNodeMtls(c, pool)

ClientAuth is then never set, so the node API stops accepting client
certificates entirely. A node whose sync credential is a certificate loses its
only credential, or silently falls back to a bearer token — and the single line
saying so is a warning emitted once at boot.

This reports it at error level and separates the two causes.
NodeMtlsClientCAPool tags the parse failure with
ErrNodeMtlsTrustBundleInvalid; the message text is unchanged, so anything
matching on the existing string keeps matching.

Why not fail to start

Refusing to boot was considered and rejected. The bundle is one of two equal
credentials here — checkAPIAuth accepts a verified chain or a bearer token —
so a stopped panel protects nothing while taking the proxies and the
subscription server down with it. Worse, bundles written before the stricter
validation in #6188 are already stored, and the setting is editable only through
the panel that would no longer come up.

Scope

  • internal/web/service/setting_mtls.go — the sentinel, wrapped into the
    existing message.
  • internal/web/web.go — error level, and the two causes told apart.
  • internal/web/service/setting_mtls_bundle_test.go — two tests.

No behaviour change to startup, to the listener, or to any panel without a
trust bundle configured.

Validation

  • go build ./..., golangci-lint run ./internal/web/... → 0 issues.
  • go test ./internal/web/ ./internal/web/service/ → ok.
  • The new tests pin the tag on an unusable bundle and its absence on an unset
    one. Dropping the sentinel turns the first red:
    NodeMtlsClientCAPool() error = nodeMtlsClientCAPem is not a valid certificate bundle: certificate bundle contains malformed or non-PEM data, want it to wrap ErrNodeMtlsTrustBundleInvalid.
  • TestNodeMtlsClientCAPoolRejectsPartiallyValidBundle, which asserts the full
    message string, still passes unchanged.

Risk

The only visible change is a log line moving from warning to error and gaining a
sentence. A panel with no bundle configured never reaches either branch.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6565 **Author:** [@n0ctal](https://github.com/n0ctal) **Created:** 9/16/2026 **Status:** ✅ Merged **Merged:** 9/16/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `upstream-node-mtls-trust-bundle-diagnostics` --- ### 📝 Commits (2) - [`f8e5d22`](https://github.com/MHSanaei/3x-ui/commit/f8e5d22d23dd707d3cc83c181071f3fb98077caa) fix(nodes): say which half of node mTLS failed, and say it as an error - [`2795737`](https://github.com/MHSanaei/3x-ui/commit/2795737e08cb2eacc40bd77404765140ff4b9dfa) test(nodes): drop a duplicate node mTLS trust-bundle test ### 📊 Changes **3 files changed** (+33 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `internal/web/service/setting_mtls.go` (+5 -1) 📝 `internal/web/service/setting_mtls_bundle_test.go` (+19 -0) 📝 `internal/web/web.go` (+9 -3) </details> ### 📄 Description ## Summary A node mTLS trust bundle that will not parse is reported exactly like a settings read that failed, and both are warnings: ```go if pool, perr := s.settingService.NodeMtlsClientCAPool(); perr != nil { logger.Warning("node mTLS: failed to build client CA trust pool:", perr) } else if pool != nil { applyNodeMtls(c, pool) ``` `ClientAuth` is then never set, so the node API stops accepting client certificates entirely. A node whose sync credential is a certificate loses its only credential, or silently falls back to a bearer token — and the single line saying so is a warning emitted once at boot. This reports it at error level and separates the two causes. `NodeMtlsClientCAPool` tags the parse failure with `ErrNodeMtlsTrustBundleInvalid`; the message text is unchanged, so anything matching on the existing string keeps matching. ## Why not fail to start Refusing to boot was considered and rejected. The bundle is one of two equal credentials here — `checkAPIAuth` accepts a verified chain *or* a bearer token — so a stopped panel protects nothing while taking the proxies and the subscription server down with it. Worse, bundles written before the stricter validation in #6188 are already stored, and the setting is editable only through the panel that would no longer come up. ## Scope - `internal/web/service/setting_mtls.go` — the sentinel, wrapped into the existing message. - `internal/web/web.go` — error level, and the two causes told apart. - `internal/web/service/setting_mtls_bundle_test.go` — two tests. No behaviour change to startup, to the listener, or to any panel without a trust bundle configured. ## Validation - `go build ./...`, `golangci-lint run ./internal/web/...` → 0 issues. - `go test ./internal/web/ ./internal/web/service/` → ok. - The new tests pin the tag on an unusable bundle and its absence on an unset one. Dropping the sentinel turns the first red: `NodeMtlsClientCAPool() error = nodeMtlsClientCAPem is not a valid certificate bundle: certificate bundle contains malformed or non-PEM data, want it to wrap ErrNodeMtlsTrustBundleInvalid`. - `TestNodeMtlsClientCAPoolRejectsPartiallyValidBundle`, which asserts the full message string, still passes unchanged. ## Risk The only visible change is a log line moving from warning to error and gaining a sentence. A panel with no bundle configured never reaches either branch. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:08:10 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6354
No description provided.