[GH-ISSUE #5900] [Feature]: Client Group Policies #4089

Open
opened 2026-10-31 20:37:05 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @Ssentiago on GitHub (Jul 10, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5900

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 Policy concept 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:

  • an Override option, to make it manual for that one client while keeping its current value,
  • a Return to Policy option, to revert it back to following the policy.

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 enable field should stay independent of policy management — always admin-controlled directly.

Alternatives you've considered

  • Bulk edit on the clients page — lets you apply relative adjustments (add/subtract days, add/subtract traffic) to a selection of clients at once, but it doesn't cover inbound access or IP limits, doesn't set absolute values, and doesn't persist any link — any future change to the tier's policy would mean re-selecting the same clients and re-applying manually again.
  • Group-level fields directly on 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.
  • A Policy avoids 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 (via inherited_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?

  • I'd like to implement this feature myself and open a PR.
  • I can help test once a PR is open.

Before submitting

  • I searched existing issues and this feature has not been requested.
  • This feature request is written in English.
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 `Policy` concept 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: - an **Override** option, to make it manual for that one client while keeping its current value, - a **Return to Policy** option, to revert it back to following the policy. 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 `enable` field should stay independent of policy management — always admin-controlled directly. ### Alternatives you've considered - **Bulk edit on the clients page** — lets you apply relative adjustments (add/subtract days, add/subtract traffic) to a selection of clients at once, but it doesn't cover inbound access or IP limits, doesn't set absolute values, and doesn't persist any link — any future change to the tier's policy would mean re-selecting the same clients and re-applying manually again. - **Group-level fields directly on `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. - A `Policy` avoids 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 (via `inherited_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? - [x] I'd like to implement this feature myself and open a PR. - [x] I can help test once a PR is open. ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this feature has not been requested. - [x] This feature request is written in English.
Author
Owner

@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

  • Client groups are already a first-class concept, but purely a label today: model.ClientGroup (internal/database/model/model.go:826, table client_groups) is just Id, Name, ResetUp, ResetDown (a traffic-reset baseline) — no policy or limit fields. The Groups page (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.
  • The fields you want centralized already live where you would expect: totalGB, limitIp, expiryTime and group are columns directly on ClientRecord (model.go:795, table clients), and inbound access is the separate client_inbounds join table (ClientInbound, model.go:868).
  • Your bulk-edit description is accurate: internal/web/service/client_bulk.go has BulkAttach/BulkDetach (inbound membership) and BulkAdjust (additive addDays/addBytes only, 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.
  • The "inherited value, explicitly overridable" idea has a narrow precedent already: client_inbounds.flow_override (model.go:871) lets the flow of a client be pinned per-inbound, with client_lookup.go/client_link.go resolving 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 for inherited_from_policy is not foreign to this codebase. Single-client setters like ResetClientIpLimitByEmail/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 Policy table and CRUD (service, controller, routes), a nullable policy reference on client_groups, per-field inherited/overridden tracking on clients (or a side table) covering totalGB/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 in internal/database/db.go, new REST routes (registered in frontend/src/pages/api-docs/endpoints.ts, following the convention this repository uses for documenting routes), and frontend work in both GroupsPage.tsx (policy CRUD plus link/unlink) and ClientFormModal.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):

  • #5371 proposes a one-time "set to value" bulk-edit modal — it covers the "no absolute-value bulk edit" gap also noted in your Alternatives section, but has no persistent group-to-policy link or auto-propagation, so it does not cover the core ask here.
  • #5026 proposes "Dynamic Inbound Groups" — despite similar vocabulary ("groups", "override"), it groups inbounds for subscription resolution, not clients for limit bundling; different data model, different problem.
  • #3683 (closed) used "policy" for something unrelated — the per-inbound policy.levels timeout 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 on clients directly or on a side table, and whether policy-driven inbound membership should reuse BulkAttach/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.

<!-- gh-comment-id:4939946649 --> @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** - Client groups are already a first-class concept, but purely a label today: `model.ClientGroup` (`internal/database/model/model.go:826`, table `client_groups`) is just `Id`, `Name`, `ResetUp`, `ResetDown` (a traffic-reset baseline) — no policy or limit fields. The `Groups` page (`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. - The fields you want centralized already live where you would expect: `totalGB`, `limitIp`, `expiryTime` and `group` are columns directly on `ClientRecord` (`model.go:795`, table `clients`), and inbound access is the separate `client_inbounds` join table (`ClientInbound`, `model.go:868`). - Your bulk-edit description is accurate: `internal/web/service/client_bulk.go` has `BulkAttach`/`BulkDetach` (inbound membership) and `BulkAdjust` (additive `addDays`/`addBytes` only, 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. - The "inherited value, explicitly overridable" idea has a narrow precedent already: `client_inbounds.flow_override` (`model.go:871`) lets the flow of a client be pinned per-inbound, with `client_lookup.go`/`client_link.go` resolving 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 for `inherited_from_policy` is not foreign to this codebase. Single-client setters like `ResetClientIpLimitByEmail`/`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 `Policy` table and CRUD (service, controller, routes), a nullable policy reference on `client_groups`, per-field inherited/overridden tracking on `clients` (or a side table) covering `totalGB`/`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 in `internal/database/db.go`, new REST routes (registered in `frontend/src/pages/api-docs/endpoints.ts`, following the convention this repository uses for documenting routes), and frontend work in both `GroupsPage.tsx` (policy CRUD plus link/unlink) and `ClientFormModal.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): - #5371 proposes a one-time "set to value" bulk-edit modal — it covers the "no absolute-value bulk edit" gap also noted in your Alternatives section, but has no persistent group-to-policy link or auto-propagation, so it does not cover the core ask here. - #5026 proposes "Dynamic Inbound Groups" — despite similar vocabulary ("groups", "override"), it groups *inbounds* for subscription resolution, not clients for limit bundling; different data model, different problem. - #3683 (closed) used "policy" for something unrelated — the per-inbound `policy.levels` timeout 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 on `clients` directly or on a side table, and whether policy-driven inbound membership should reuse `BulkAttach`/`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.*
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#4089
No description provided.