experimental/clashapi: emit "user" field in TrackerMetadata.MarshalJSON#4159
Open
PavelLizunov wants to merge 97 commits into
Open
experimental/clashapi: emit "user" field in TrackerMetadata.MarshalJSON#4159PavelLizunov wants to merge 97 commits into
PavelLizunov wants to merge 97 commits into
Conversation
`SecTrustEvaluateWithError` is serial
This reverts commit 62cb06c.
83b7304 to
8a42af3
Compare
8ea55ff to
a9fe3f3
Compare
2ee20d0 to
ecc4776
Compare
6b41423 to
585d3e6
Compare
8bdafbb to
9ec7cc8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
TrackerMetadata.MarshalJSON(inexperimental/clashapi/trafficontrol/tracker.go)emits a fixed set of metadata keys but silently drops the authenticated
user identifier. This PR adds a single key
"user": t.Metadata.Usertothe marshalled JSON.
Why
adapter.InboundContext.Useris populated server-side by every auth-bearinginbound (VLESS, TUIC, Trojan, etc) — the data exists, it just never
reaches the Clash-API wire. Downstream consumers that need per-user
attribution (abuse detection, per-account quota visualisation,
multi-tenant dashboards) have no way to associate a connection with the
account that opened it.
What changes
For inbounds WITHOUT an authenticated user (direct/socks/tun)
Useristhe empty string — preserves existing observable behaviour for those
inbounds.
Compatibility
the de-facto convention.
upstream of
MarshalJSON; this only changes what gets marshalled.Real-world driver
A Rust-based VPN-fleet control plane (github.com/PavelLizunov/vpnctl)
polls clash-api on each node to attribute per-connection traffic to
inv.db user_ids. The attribution column in its
vpn_connection_statstable is
NULLon every row today becauseUseris never on the wire —even though authenticated VLESS connections populate it server-side.
Test plan
curl localhost:9090/connections→ metadata now contains"user": "<uuid-or-name>"."user": ""(no regression).