ExtAuth - external authentication API for VLESS (potential upstream contribution) #5787
Replies: 2 comments 2 replies
-
|
Hiya! In case someone reads this discussion, quick update on the progress. Honestly, forget everything I wrote above about the After some thinking and testing, I realized I built a monolithic module trying to solve too many problems at once. Mixing connection metrics with authentication is just a bad idea that completely breaks the separation of concerns. Also, hitting the auth backend for every single connection is a guaranteed way to DDoS your own servers on scale. I even tried to fix this by batching events into single requests, but to be honest, the code just turned into a messy garbage that was overcomplicated and hard to maintain. So, here is the new plan: I'm currently rewriting the whole core module to reflect this clean, auth-only approach! So consider everything written in wiki out of date! |
Beta Was this translation helpful? Give feedback.
-
|
I think first variant is better because i can have 1 million accounts in databse and store it in xray cache not good, too much memory usage. to prevent ddos user storage i can use load balancer + cache in my own api. But idea about move out from auth module lifecycle events (connect, heartbeat, disconnect) is good. I think it should be another module in xray-core with another config for inbound (to have ability to set different event receivers for different inbounds). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi! I'm a founder building a VPN service, and I ran into a problem I think some of you know well.
Xray-core gives you two ways to manage users: hardcode them in a config file, or use the gRPC API. Both work, but neither is great at scale, with a cluster of nodes you're either editing files everywhere or hitting every server individually with no session visibility.
There are panels like Remnawave and Marzban that try to solve this, and I used them! But they come with significant overhead and sit between you and the core, which makes it hard to implement precise business logic on your end.
I also know such feature has been discussed before, but it never got implemented. So I decided to build it myself as a fork: cnap-core 🎉
What it adds: ExtAuth
A new
extAuthblock in VLESS (Only supported protocol for now) inbound config that delegates authentication to your HTTP API:{ "inbounds": [ { "port": 443, "protocol": "vless", "settings": { "decryption": "none", "extAuth": { "url": "https://your-backend.com/auth", "timeout": 5, "ttl": 60, "headers": { "Authorization": "Bearer secret" }, "notifications": { "connect": true, "heartbeat": 30, "disconnect": true } } } } ] }When a client connects, your server receives:
{ "type": "authorization", "credential": "550e8400-e29b-41d4-a716-446655440000", "connection": "a3f1c2d4-9b8e-4f1a-b2c3-d4e5f6a7b8c9", "email": "alice@example.com", "level": 0, "protocol": "vless", "inboundTag": "my-inbound", "sourceIP": "1.2.3.4", "sourcePort": 52341, "localIP": "10.0.0.1", "localPort": 443, "timestamp": 1710000000 }Reply with user info to allow:
{ "user": { "email": "alice@example.com", "level": 0 } }Or
401/403to deny.If
notifications.connect,notifications.heartbeat, ornotifications.disconnectare enabled, your server also receives lifecycle events for each connection: same endpoint, just a differenttypefield (connect,heartbeat,disconnect). Useful for session tracking, usage metering, or kicking users mid-session by returning401on a heartbeat.A few honest caveats:
The VLESS validator integration is not fully complete yet, some methods are currently no-ops since ExtAuth is read-only by nature. It works reliably for authentication and session tracking, but things like dynamic user management via gRPC API won't work when ExtAuth is enabled. I plan to address this before any upstream PR. Down the road I also want to extend ExtAuth to other protocols beyond VLESS.
If the maintainers are interested, I'm happy to submit a proper upstream PR, even if it needs significant changes to fit the codebase!
Full docs: GitHub Wiki
Beta Was this translation helpful? Give feedback.
All reactions