mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[GH-ISSUE #5900] [Feature]: Client Group Policies #4089
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#4089
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Ssentiago on GitHub (Jul 10, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5900
Is your feature request related to a problem?
Managing clients at scale requires manually editing each client's traffic limit, expiry, IP limit, and inbound access one by one. With a large number of clients split into tiers (e.g. "Free", "Standard", "Premium"), every policy change means opening each client individually and updating the same fields. There's no way to link a set of parameters to a group and have them propagate automatically.
Describe the solution you'd like
Policy entity
A
Policyconcept that bundles together the fields that should be shared across a group of clients: which inbounds they have access to, traffic limit, expiry, and IP limit. Policies would be manageable from a dedicated page under Groups (create/edit/delete).Group ↔ Policy link
A group could optionally have a policy attached to it. The Groups page would show which policy (if any) is assigned to a given group, editable from the group's edit modal, with an option to unlink it.
Client form — managed fields
When a client belongs to a group with a linked policy, the policy-controlled fields (traffic limit, IP limit, attached inbounds) would be shown as managed in the client form — visually marked, not manually editable by default. Each such field would need:
A summary near the top of the form would indicate which fields are currently policy-managed and by which policy.
Group autocomplete auto-fill
When creating a client and picking a group that has a policy, the relevant fields would auto-fill from that policy.
Auto-apply on policy changes
When a policy's values are edited, clients in groups linked to it that still inherit those fields would get updated automatically. Same when a group's policy assignment itself changes.
Data model considerations
Each client would need some way to track, per field, whether it's currently inherited from a policy or has been manually overridden — so that overridden fields are preserved across policy updates and "return to policy" knows what to do. The
enablefield should stay independent of policy management — always admin-controlled directly.Alternatives you've considered
client_groups— store the limits (totalGB, limitIP, inbounds) on the group itself, inherited by clients at creation time. This is architecturally simpler on paper, but it shifts part of the client's configuration ownership onto the group — the client stops being self-describing and starts depending on its group for its own effective limits. Given the codebase is built around the client as the central entity, this works against that model.Policyavoids this: it's an optional top-level entity that clients can reference, but the client itself remains the source of truth for its own effective configuration (viainherited_from_policy), so the core "client-centric" structure of the codebase stays intact.- A blanket "select all" for inbounds — the client form already has this, but it adds every inbound indiscriminately. Policies need per-tier inbound scoping (e.g. VLESS-only for Free, everything for Premium), which a blanket toggle can't express.Concrete use case
Clients are spread across several inbound protocols (VLESS, Trojan, Shadowsocks) and grouped into tiers with different limits — e.g. Free (10GB, 1 IP, VLESS only), Standard (100GB, 3 IPs, VLESS+Trojan), Premium (unlimited, 5 IPs, all inbounds).
If the traffic limit for "Standard" changes from 100GB to 200GB, instead of editing every client in that tier individually, updating the policy once would propagate to all of them automatically — except for the handful that were manually overridden, which would keep their custom values.
Mockups, screenshots, or examples
No response
Which parts of the panel would this affect?
No response
Are you willing to help?
Before submitting
@github-actions[bot] commented on GitHub (Jul 10, 2026):
Thanks for the detailed proposal — the "Alternatives" section accurately reflects the current state of bulk editing, which made this easy to verify against the source.
What already exists
model.ClientGroup(internal/database/model/model.go:826, tableclient_groups) is justId,Name,ResetUp,ResetDown(a traffic-reset baseline) — no policy or limit fields. TheGroupspage (frontend/src/pages/groups/GroupsPage.tsx) already has create/rename/delete and add/remove-clients actions, so "a dedicated page under Groups" would extend an existing page rather than start from nothing.totalGB,limitIp,expiryTimeandgroupare columns directly onClientRecord(model.go:795, tableclients), and inbound access is the separateclient_inboundsjoin table (ClientInbound,model.go:868).internal/web/service/client_bulk.gohasBulkAttach/BulkDetach(inbound membership) andBulkAdjust(additiveaddDays/addBytesonly, backing the existing "Adjust" modal) — one-shot operations with no persisted link back to a source of truth, which is exactly the gap you describe.client_inbounds.flow_override(model.go:871) lets the flow of a client be pinned per-inbound, withclient_lookup.go/client_link.goresolving the effective flow by falling back through non-empty overrides. It is one field on one join table, not a general per-field inheritance system, but the shape proposed forinherited_from_policyis not foreign to this codebase. Single-client setters likeResetClientIpLimitByEmail/ResetClientExpiryTimeByEmail/ResetClientTrafficLimitByEmail(internal/web/service/client_inbound_apply.go:1286-1298) already encapsulate mutating one field for one client consistently across its inbound JSON, which a propagation step could loop over rather than reinventing.What it would add
A new
Policytable and CRUD (service, controller, routes), a nullable policy reference onclient_groups, per-field inherited/overridden tracking onclients(or a side table) coveringtotalGB/limitIp/inbound membership, propagation logic triggered both when the values of a policy change and when the policy link of a group changes, a migration entry ininternal/database/db.go, new REST routes (registered infrontend/src/pages/api-docs/endpoints.ts, following the convention this repository uses for documenting routes), and frontend work in bothGroupsPage.tsx(policy CRUD plus link/unlink) andClientFormModal.tsx(managed-field badges, Override and Return-to-Policy actions, group autofill). This is a substantial, multi-layer change, not a small addition.Related open issues (not duplicates, but worth reading together since they touch the same area):
policy.levelstimeout and stats tuning built into Xray itself, not client-tier bundles.Given the overlap in touched code (
client_inbounds, groups, bulk propagation) with #5026 and #5371, @MHSanaei may want to weigh sequencing and scope across the three before a PR lands — in particular whether inherited and overridden tracking belongs onclientsdirectly or on a side table, and whether policy-driven inbound membership should reuseBulkAttach/BulkDetach. Since you have offered to implement this yourself, landing it as an incremental sequence (data model and migration, then propagation logic, then the Groups and Policy UI, then the client-form override UI) would be the most reviewable path — consistent with how this area of the codebase is already split into small, focused files (client_bulk.go,client_crud.go,client_groups.go,client_inbound_apply.go).This reply was generated automatically. A maintainer may follow up.