[PR #5098] [MERGED] feat: synchronize access.log client IPs across nodes #5780

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

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/5098
Author: @rqzbeh
Created: 6/8/2026
Status: ✅ Merged
Merged: 6/8/2026
Merged by: @MHSanaei

Base: main ← Head: feat/sync-client-ips-across-nodes


📝 Commits (3)

  • a9be483 feat: synchronize access.log client IPs across nodes for global fail2ban limits
  • e554151 Merge branch 'main' into feat/sync-client-ips-across-nodes
  • 4d102c5 fix(nodes): harden cross-node client-IP merge for cluster fail2ban

📊 Changes

9 files changed (+532 additions, -3 deletions)

View changed files

📝 frontend/public/openapi.json (+73 -0)
📝 frontend/src/pages/api-docs/endpoints.ts (+15 -0)
📝 web/controller/server.go (+18 -0)
📝 web/job/check_client_ip_job.go (+5 -1)
📝 web/job/check_client_ip_job_test.go (+21 -0)
📝 web/job/node_traffic_sync_job.go (+39 -2)
📝 web/runtime/remote.go (+19 -0)
📝 web/service/inbound.go (+131 -0)
➕ web/service/inbound_client_ips_merge_test.go (+211 -0)

📄 Description

Summary

Synchronizes access.log client IPs from sub-nodes to the main server so that fail2ban limits are correctly enforced cluster-wide.

Why

Currently, when users connect to a node server, the access.log on that node records the client IP, but this information is not synchronized back to the main server's global view. As a result, the fail2ban feature (which limits the maximum number of simultaneous IPs a client can use) fails to count connections made through remote nodes, allowing users to bypass their IP limit.

This PR implements a robust synchronization mechanism where NodeTrafficSyncJob pulls recent InboundClientIps from remote nodes and safely aggregates them into the main database without double-counting identical IPs across different nodes.

Closes #5080

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Documentation
  • Tests only
  • Build / CI / tooling
  • Other

Areas affected

  • Frontend (UI / panel pages)
  • Backend (API endpoints, login, settings)
  • Xray config generation
  • Subscription (share links / Clash / JSON)
  • Statistics / traffic counters
  • Database / migrations
  • Install / upgrade script
  • Docker image
  • Multi-node (sub-nodes)
  • Telegram bot

How was this tested?

  1. Add GET/POST /panel/api/server/clientIps endpoints for inter-node communication.
  2. The logic safely uses a Map to deduplicate concurrent IPs (ipMap[ipTime.IP] = ipTime.Timestamp), guaranteeing the system does not double-count the same IP accessing multiple nodes.
  3. Created a unit test TestPartitionLiveIps_RecentSyncedIpIsLive in check_client_ip_job_test.go to mathematically prove the 2-minute rolling window sync accurately labels recently-synced cluster IPs as "live" even if they weren't seen by the local access.log scan.
  4. Fully ran go test -v ./web/job/... which passes flawlessly.

Screenshots / recordings

N/A (Backend logic only).

Breaking changes

None.

Checklist

  • I tested the change locally and confirmed the described behavior.
  • I added or updated tests for the new behavior (when applicable).
  • go build ./... and the test suite pass locally.
  • For frontend changes: npm run lint, npm run typecheck, and npm run build pass.
  • I updated the Wiki / README / API docs if user-facing behavior changed.
  • My commits follow the project's existing message style.
  • I have no unrelated changes mixed into this PR.

🔄 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/5098 **Author:** [@rqzbeh](https://github.com/rqzbeh) **Created:** 6/8/2026 **Status:** ✅ Merged **Merged:** 6/8/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `feat/sync-client-ips-across-nodes` --- ### 📝 Commits (3) - [`a9be483`](https://github.com/MHSanaei/3x-ui/commit/a9be4836efb0764e9aadc0a9d445fe3f62158449) feat: synchronize access.log client IPs across nodes for global fail2ban limits - [`e554151`](https://github.com/MHSanaei/3x-ui/commit/e554151d0ead3c287130bf261df029d3b9eee842) Merge branch 'main' into feat/sync-client-ips-across-nodes - [`4d102c5`](https://github.com/MHSanaei/3x-ui/commit/4d102c5d18c4cd1fb352b8384530ce15e3c70508) fix(nodes): harden cross-node client-IP merge for cluster fail2ban ### 📊 Changes **9 files changed** (+532 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `frontend/public/openapi.json` (+73 -0) 📝 `frontend/src/pages/api-docs/endpoints.ts` (+15 -0) 📝 `web/controller/server.go` (+18 -0) 📝 `web/job/check_client_ip_job.go` (+5 -1) 📝 `web/job/check_client_ip_job_test.go` (+21 -0) 📝 `web/job/node_traffic_sync_job.go` (+39 -2) 📝 `web/runtime/remote.go` (+19 -0) 📝 `web/service/inbound.go` (+131 -0) ➕ `web/service/inbound_client_ips_merge_test.go` (+211 -0) </details> ### 📄 Description ## Summary Synchronizes access.log client IPs from sub-nodes to the main server so that `fail2ban` limits are correctly enforced cluster-wide. ## Why Currently, when users connect to a node server, the `access.log` on that node records the client IP, but this information is not synchronized back to the main server's global view. As a result, the `fail2ban` feature (which limits the maximum number of simultaneous IPs a client can use) fails to count connections made through remote nodes, allowing users to bypass their IP limit. This PR implements a robust synchronization mechanism where `NodeTrafficSyncJob` pulls recent `InboundClientIps` from remote nodes and safely aggregates them into the main database without double-counting identical IPs across different nodes. Closes #5080 ## Type of change - [ ] Bug fix - [x] New feature - [ ] Refactoring (no behavior change) - [ ] Documentation - [ ] Tests only - [ ] Build / CI / tooling - [ ] Other ## Areas affected - [ ] Frontend (UI / panel pages) - [x] Backend (API endpoints, login, settings) - [ ] Xray config generation - [ ] Subscription (share links / Clash / JSON) - [ ] Statistics / traffic counters - [x] Database / migrations - [ ] Install / upgrade script - [ ] Docker image - [x] Multi-node (sub-nodes) - [ ] Telegram bot ## How was this tested? 1. Add `GET/POST /panel/api/server/clientIps` endpoints for inter-node communication. 2. The logic safely uses a Map to deduplicate concurrent IPs (`ipMap[ipTime.IP] = ipTime.Timestamp`), guaranteeing the system does not double-count the same IP accessing multiple nodes. 3. Created a unit test `TestPartitionLiveIps_RecentSyncedIpIsLive` in `check_client_ip_job_test.go` to mathematically prove the 2-minute rolling window sync accurately labels recently-synced cluster IPs as "live" even if they weren't seen by the local `access.log` scan. 4. Fully ran `go test -v ./web/job/...` which passes flawlessly. ## Screenshots / recordings N/A (Backend logic only). ## Breaking changes None. ## Checklist - [x] I tested the change locally and confirmed the described behavior. - [x] I added or updated tests for the new behavior (when applicable). - [x] `go build ./...` and the test suite pass locally. - [x] For frontend changes: `npm run lint`, `npm run typecheck`, and `npm run build` pass. - [x] I updated the Wiki / README / API docs if user-facing behavior changed. - [x] My commits follow the project's existing message style. - [x] I have no unrelated changes mixed into this PR. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:04:01 +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#5780
No description provided.