Skip to content

Manage VLESS client UUIDs from the dashboard, applied to xray live - #10

Merged
GlobalTechInfo merged 1 commit into
mainfrom
feat/vless-client-management
Oct 17, 2026
Merged

GlobalTechInfo merged 1 commit into
mainfrom
feat/vless-client-management

Conversation

@GlobalTechInfo

Copy link
Copy Markdown
Owner

Why

Until now the REALITY client list was one comma-joined config value. Revoking a UUID meant editing configuration and restarting the service — so there was no way to remove a lost phone without taking the front door down for everyone. Management that only takes effect on restart is a trap, so this makes the change real: an added UUID serves traffic in 0.08s, and a revoked one stops working immediately.

What changed

Storage. A vless_clients table, one row per client (uuid, label, enabled). Precedence keeps its existing shape:

  1. REALITY_CLIENT_IDS — pins the list from configuration
  2. the managed table — what the dashboard edits
  3. the old comma-joined config value, adopted into the table on first run
  4. a generated UUID, stored as a row so restarts don't rotate it

Point 3 is the upgrade safety net: without it, the first dashboard change would silently revoke a client that is still in the field, because the table would then shadow the config. My own test asserted the opposite at first — adopting means "keeps working", not "goes away".

Live application. The supervisor loop now owns reloads. The new config is rendered and put through xray run --test before anything is touched, so an invalid change is refused and the running front door keeps serving. The supervisor is the only code that stops and starts the child, and it answers the request once the new child is actually accepting connections — not when it was asked to.

API (/api/vless-clients, same shape as /api/users): list, create, relabel, enable/disable, delete. Dashboard: a "REALITY Clients" panel with add/copy/disable/delete, reusing the existing badge and button styles. Rows are built with textContent, so a label containing markup cannot inject anything into the admin page.

Refusals, on purpose

  • Removing the last client is rejected. Xray with no clients is a front door that refuses everyone; an operator should have to mean that.
  • REALITY_CLIENT_IDS set → 409 naming the variable, rather than accepting edits that quietly do nothing.
  • REALITY disabled → 409 for mutations, while listing still works so the panel can explain itself.
  • A refused change restores the row. My first version deleted it instead, and a test caught it: xray never stopped accepting that UUID, so the database must not claim otherwise.

Verification

  • go vet and gofmt clean; full suite green with and without Xray; -race clean over the REALITY and VLESS tests.
  • Live, real xray on a real port, driven through the actual admin API: added a UUID → served traffic (200, real source IP) → revoked it → the same client failed at once → the untouched client kept working → xray's own log named the refusal (proxy/vless/encoding: rejected).
  • End-to-end test in vless_test.go asserts the same three things deterministically, with two independent client xray processes: revoked fails, non-revoked keeps working, no restart anywhere.
  • Upgrade path covered: a legacy comma-joined id is adopted, still works after a new client is added, and disappears from the config only when disabled.
  • GET /api/vless-clients serialises [] rather than null, so the panel can loop over it.

Not in this PR

VLESS clients are not linked to SOCKS5 users, so tier limits apply to SOCKS5 sessions only — REALITY sessions arrive through the socks outbound with the service's own credentials. Linking them would mean per-user routing in the xray config and is its own piece of work. Backup needs no change: the table is inside the SQLite file that VACUUM INTO already snapshots.

Until now the REALITY client list was a comma-joined config value, so
revoking a UUID meant editing configuration and restarting the service. A
management screen that only takes effect on restart is a trap, so this
makes the change real.

The list lives in a vless_clients table, one row per client. Precedence is
unchanged in spirit: REALITY_CLIENT_IDS still pins the list from
configuration and now says so, because accepting edits that quietly do
nothing is worse than refusing them. An id left behind by the old
comma-joined value is adopted into the table on first run rather than
dropped -- otherwise the first dashboard change would revoke a client
that is still in the field.

Making it live meant teaching the xray supervisor to re-point itself. The
reload carries a config that has already passed `xray run --test`, so an
invalid change is refused and the running front door keeps serving; the
supervisor is the only thing that stops and starts the child, and it
answers once the new child is actually accepting connections. Measured
live: an add applies in 0.08s.

Two refusals worth having. Removing the last client is rejected, because
xray with no clients is a front door that rejects everyone and an operator
should have to mean it. And a refused change restores the row rather than
dropping it, so the database never claims something xray does not do.

Verified live against xray on a real port: a UUID added through the API
served traffic immediately, the same client failed the moment it was
revoked, the untouched client kept working, and xray's own log named the
refusal (proxy/vless/encoding: rejected). Covered end to end in tests too,
including the case the race detector caught on the way: s.cfg is written
under configMu while being read here.
@coderabbitai

coderabbitai Bot commented Oct 17, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 19 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1bf8c59f-4129-4994-b8b7-edc5eadcb454
📥 Commits

Reviewing files that changed from the base of the PR and between ea155ff and 05f7aa9.

📒 Files selected for processing: 7
  • README.md
  • database.go
  • main.go
  • reality.go
  • reality_test.go
  • vless_test.go
  • web/index.html
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@GlobalTechInfo
GlobalTechInfo merged commit 71912e8 into main Oct 17, 2026
3 checks passed
@GlobalTechInfo
GlobalTechInfo deleted the feat/vless-client-management branch October 17, 2026 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant