[PR #6176] [MERGED] fix(database): keep IP limits when the fail2ban probe is inconclusive #6138

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

📋 Pull Request Information

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

Base: main ← Head: upstream-preserve-configured-iplimit


📝 Commits (3)

  • dfd4ed3 fix(database): keep IP limits when the fail2ban probe is inconclusive
  • 1a3130c test(database): cover fail2ban reset safeguards
  • 2e8d65f Merge branch 'main' into upstream-preserve-configured-iplimit

📊 Changes

2 files changed (+135 additions, -5 deletions)

View changed files

📝 internal/database/db.go (+26 -5)
➕ internal/database/fail2ban_state_test.go (+109 -0)

📄 Description

Summary

ResetIpLimitNoFail2ban wiped every configured limitIp whenever fail2ban-client -h failed for any reason, including a transient one, and then recorded itself so the decision was never revisited. Distinguish "fail2ban is absent" from "the probe failed".

Why

The seeder's intent is sound: with no fail2ban there is nothing to enforce limitIp, so clearing it avoids a setting that silently does nothing.

The problem is the evidence it acts on. exec.Command("fail2ban-client", "-h").Run() == nil is false both when the binary does not exist and when it exists but that one run failed — a panel started before fail2ban is up, an image where fail2ban is installed a moment later, a momentarily unavailable exec.

The consequence is not proportional to the uncertainty: it rewrites every inbound's settings JSON and every clients.limit_ip to 0, records ResetIpLimitNoFail2ban in the seeder history, and returns. There is no log line on the destructive path, and because the history row exists the seeder never looks again. Operator configuration is gone with nothing to restore it from.

Scope

  • internal/database/db.go — fail2banEnforcementState() returns fail2banEnforcing / fail2banAbsent / fail2banUnknown; a missing binary (exec.LookPath) is still absent, a present-but-unrunnable one is unknown. fail2banCanEnforce() keeps its signature for existing callers.
  • The seeder skips the cleanup on fail2banUnknown, logs the probe error, and does not record itself, so the next start re-evaluates. Behaviour on absent and on enforcing is unchanged.
  • internal/database/fail2ban_state_test.go — covers all three states with a stub fail2ban-client on PATH.

Validation

  • go test ./internal/database/ -count=1 green; go build ./... and go vet clean.
  • The new subtest "present but failing" is the case that previously mapped to false and triggered the wipe.

Risk

Low, and strictly less destructive than before. A host that genuinely lacks fail2ban still gets the cleanup on the same schedule. The only new outcome is that an inconclusive probe defers instead of deleting.


🔄 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/6176 **Author:** [@n0ctal](https://github.com/n0ctal) **Created:** 8/5/2026 **Status:** ✅ Merged **Merged:** 8/14/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `upstream-preserve-configured-iplimit` --- ### 📝 Commits (3) - [`dfd4ed3`](https://github.com/MHSanaei/3x-ui/commit/dfd4ed3cde2a505d85356ab1d7359683fde2edd1) fix(database): keep IP limits when the fail2ban probe is inconclusive - [`1a3130c`](https://github.com/MHSanaei/3x-ui/commit/1a3130c3756c54bf3135556f750350a934133af0) test(database): cover fail2ban reset safeguards - [`2e8d65f`](https://github.com/MHSanaei/3x-ui/commit/2e8d65fccb0f1d97de646ee1c2a24cc4d310fc38) Merge branch 'main' into upstream-preserve-configured-iplimit ### 📊 Changes **2 files changed** (+135 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `internal/database/db.go` (+26 -5) ➕ `internal/database/fail2ban_state_test.go` (+109 -0) </details> ### 📄 Description ## Summary `ResetIpLimitNoFail2ban` wiped every configured `limitIp` whenever `fail2ban-client -h` failed for any reason, including a transient one, and then recorded itself so the decision was never revisited. Distinguish "fail2ban is absent" from "the probe failed". ## Why The seeder's intent is sound: with no fail2ban there is nothing to enforce `limitIp`, so clearing it avoids a setting that silently does nothing. The problem is the evidence it acts on. `exec.Command("fail2ban-client", "-h").Run() == nil` is false both when the binary does not exist and when it exists but that one run failed — a panel started before fail2ban is up, an image where fail2ban is installed a moment later, a momentarily unavailable exec. The consequence is not proportional to the uncertainty: it rewrites every inbound's settings JSON and every `clients.limit_ip` to 0, records `ResetIpLimitNoFail2ban` in the seeder history, and returns. There is no log line on the destructive path, and because the history row exists the seeder never looks again. Operator configuration is gone with nothing to restore it from. ## Scope - `internal/database/db.go` — `fail2banEnforcementState()` returns `fail2banEnforcing` / `fail2banAbsent` / `fail2banUnknown`; a missing binary (`exec.LookPath`) is still absent, a present-but-unrunnable one is unknown. `fail2banCanEnforce()` keeps its signature for existing callers. - The seeder skips the cleanup on `fail2banUnknown`, logs the probe error, and does not record itself, so the next start re-evaluates. Behaviour on absent and on enforcing is unchanged. - `internal/database/fail2ban_state_test.go` — covers all three states with a stub `fail2ban-client` on `PATH`. ## Validation - `go test ./internal/database/ -count=1` green; `go build ./...` and `go vet` clean. - The new subtest "present but failing" is the case that previously mapped to false and triggered the wipe. ## Risk Low, and strictly less destructive than before. A host that genuinely lacks fail2ban still gets the cleanup on the same schedule. The only new outcome is that an inconclusive probe defers instead of deleting. --- <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:38 +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#6138
No description provided.