[PR #6194] [MERGED] fix(nodes): apply a rotated master mTLS certificate without restarting the panel #6158

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6194
Author: @n0ctal
Created: 8/10/2026
Status: ✅ Merged
Merged: 8/15/2026
Merged by: @MHSanaei

Base: main ← Head: upstream-mtls-invalidate-pooled-clients


📝 Commits (2)

  • 89e82e4 fix(mtls): invalidate pooled clients after credential rotation
  • b558443 fix(mtls): make connection reload read-only

📊 Changes

24 files changed (+747 additions, -101 deletions)

View changed files

📝 docs/content/docs/en/reference/api/nodes.mdx (+56 -88)
📝 docs/public/openapi.json (+30 -0)
📝 frontend/public/openapi.json (+30 -0)
📝 frontend/src/pages/api-docs/endpoints.ts (+5 -0)
📝 internal/web/controller/node.go (+11 -0)
📝 internal/web/runtime/tls_client.go (+131 -0)
📝 internal/web/runtime/tls_client_test.go (+233 -0)
➕ internal/web/runtime/tls_client_wire_test.go (+162 -0)
📝 internal/web/service/node_mtls.go (+18 -0)
📝 internal/web/service/node_mtls_test.go (+26 -0)
📝 internal/web/service/setting_mtls.go (+19 -0)
📝 internal/web/translation/ar-EG.json (+2 -1)
📝 internal/web/translation/en-US.json (+2 -1)
📝 internal/web/translation/es-ES.json (+2 -1)
📝 internal/web/translation/fa-IR.json (+2 -1)
📝 internal/web/translation/id-ID.json (+2 -1)
📝 internal/web/translation/ja-JP.json (+2 -1)
📝 internal/web/translation/pt-BR.json (+2 -1)
📝 internal/web/translation/ru-RU.json (+2 -1)
📝 internal/web/translation/tr-TR.json (+2 -1)

...and 4 more files

📄 Description

Summary

Make the panel's outbound mTLS client transports observe a credential generation, so a rotated master certificate takes effect on the next request instead of after a panel restart. Adds POST /panel/api/nodes/mtls/reloadClient to trigger it.

Why

The panel caches an mTLS transport per node. When the master client certificate changes — first issuance, or an operator rotating the stored credential — cached transports keep their old TLS config and keep reusing pooled keep-alive connections authenticated with the previous leaf. The new certificate only takes effect once the process restarts.

That forces a panel restart into any credential rotation. On an installation where the panel supervises Xray, restarting the panel interrupts the data plane for something that is purely a control-plane change.

Scope

  • A generation counter; each cached transport compares it before its next request, rebuilds its TLS transport and closes the old idle pool. Requests already in flight are not interrupted; no request that starts after invalidation reuses a connection authenticated with the previous leaf.
  • POST /panel/api/nodes/mtls/reloadClient verifies the current credential pair is readable, then invalidates. This covers rotation performed directly against settings, not only first issuance.
  • The endpoint is registered in the API docs inventory. Its absence was caught by a full TestRouteRegistryContract run and fixed.

Validation

  • go test ./... green; go test -race ./internal/web/runtime green; targeted controller/service/runtime tests green.
  • Wire test: after the leaf changes, the next request presents the new certificate and the old keep-alive connection is not reused.

Not proven: the endpoint has not been exercised through a fully started panel against a real remote node. That remains an integration check rather than a unit one.

Risk

Low. With no rotation the generation never advances and behaviour is unchanged. The endpoint only invalidates a cache; it does not mint, replace or delete any credential.


🔄 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/6194 **Author:** [@n0ctal](https://github.com/n0ctal) **Created:** 8/10/2026 **Status:** ✅ Merged **Merged:** 8/15/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `upstream-mtls-invalidate-pooled-clients` --- ### 📝 Commits (2) - [`89e82e4`](https://github.com/MHSanaei/3x-ui/commit/89e82e4691e6a0d8cf3e7bed824c03e92dd6d0e2) fix(mtls): invalidate pooled clients after credential rotation - [`b558443`](https://github.com/MHSanaei/3x-ui/commit/b5584435b35f03d3e7e02f903884d4efc3fca4cb) fix(mtls): make connection reload read-only ### 📊 Changes **24 files changed** (+747 additions, -101 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/en/reference/api/nodes.mdx` (+56 -88) 📝 `docs/public/openapi.json` (+30 -0) 📝 `frontend/public/openapi.json` (+30 -0) 📝 `frontend/src/pages/api-docs/endpoints.ts` (+5 -0) 📝 `internal/web/controller/node.go` (+11 -0) 📝 `internal/web/runtime/tls_client.go` (+131 -0) 📝 `internal/web/runtime/tls_client_test.go` (+233 -0) ➕ `internal/web/runtime/tls_client_wire_test.go` (+162 -0) 📝 `internal/web/service/node_mtls.go` (+18 -0) 📝 `internal/web/service/node_mtls_test.go` (+26 -0) 📝 `internal/web/service/setting_mtls.go` (+19 -0) 📝 `internal/web/translation/ar-EG.json` (+2 -1) 📝 `internal/web/translation/en-US.json` (+2 -1) 📝 `internal/web/translation/es-ES.json` (+2 -1) 📝 `internal/web/translation/fa-IR.json` (+2 -1) 📝 `internal/web/translation/id-ID.json` (+2 -1) 📝 `internal/web/translation/ja-JP.json` (+2 -1) 📝 `internal/web/translation/pt-BR.json` (+2 -1) 📝 `internal/web/translation/ru-RU.json` (+2 -1) 📝 `internal/web/translation/tr-TR.json` (+2 -1) _...and 4 more files_ </details> ### 📄 Description ## Summary Make the panel's outbound mTLS client transports observe a credential generation, so a rotated master certificate takes effect on the next request instead of after a panel restart. Adds `POST /panel/api/nodes/mtls/reloadClient` to trigger it. ## Why The panel caches an mTLS transport per node. When the master client certificate changes — first issuance, or an operator rotating the stored credential — cached transports keep their old TLS config and keep reusing pooled keep-alive connections authenticated with the previous leaf. The new certificate only takes effect once the process restarts. That forces a panel restart into any credential rotation. On an installation where the panel supervises Xray, restarting the panel interrupts the data plane for something that is purely a control-plane change. ## Scope - A generation counter; each cached transport compares it before its next request, rebuilds its TLS transport and closes the old idle pool. Requests already in flight are not interrupted; no request that starts after invalidation reuses a connection authenticated with the previous leaf. - `POST /panel/api/nodes/mtls/reloadClient` verifies the current credential pair is readable, then invalidates. This covers rotation performed directly against settings, not only first issuance. - The endpoint is registered in the API docs inventory. Its absence was caught by a full `TestRouteRegistryContract` run and fixed. ## Validation - `go test ./...` green; `go test -race ./internal/web/runtime` green; targeted controller/service/runtime tests green. - Wire test: after the leaf changes, the next request presents the new certificate and the old keep-alive connection is not reused. Not proven: the endpoint has not been exercised through a fully started panel against a real remote node. That remains an integration check rather than a unit one. ## Risk Low. With no rotation the generation never advances and behaviour is unchanged. The endpoint only invalidates a cache; it does not mint, replace or delete any credential. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:06:45 +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#6158
No description provided.