feat: better inbounds user management
This commit is contained in:
47 files changed
+6767
-78
No files matched your search
@@ -4,6 +4,8 @@
|
||||
enable = true;
|
||||
baseUrl = "https://vpn.example.com/sub";
|
||||
};
|
||||
services.nginx.virtualHosts."vpn.example.com".locations."/sub/".alias =
|
||||
"/run/proxy-suite-inbounds/subscriptions/";
|
||||
services.nginx.virtualHosts."vpn.example.com".locations."/sub/" = {
|
||||
alias = "/run/proxy-suite-inbounds/subscriptions/";
|
||||
extraConfig = "access_log off;"; # the token is the URL's secret
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
{
|
||||
services.proxy-suite.inbounds = {
|
||||
manager = {
|
||||
enable = true;
|
||||
speedLimits.enable = true; # nftables, and proxy-suite's XRay patch
|
||||
};
|
||||
# Declared users take a policy in the config; runtime ones get theirs from proxy-ctl or the API.
|
||||
users.phone.policy = {
|
||||
expiresAt = "2026-12-31";
|
||||
trafficLimit = "100G";
|
||||
trafficPeriod = "monthly";
|
||||
ipLimit = 2;
|
||||
speedLimit = "50M/10M"; # down/up, bits per second
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -101,6 +101,12 @@ outbound, a subscription URL a subscription. An AmneziaWG `vpn://` link or a who
|
||||
becomes a global profile, or an outbound when pasted onto the Outbounds tab. See
|
||||
[Use an AmneziaWG config](./amneziawg.md).
|
||||
|
||||
The app also opens `proxy-suite://install-config?url=<subscription URL>` links, which the
|
||||
subscription page of a proxy-suite server offers on Linux: it shows the `proxy subs add` it
|
||||
would run and waits for you to confirm it. The link's `name` becomes the subscription's tag
|
||||
(`VPN alice` as `VPN-alice`, with `-2` after it when taken); without one, it is named after
|
||||
the URL's host.
|
||||
|
||||
Adding a rule, an outbound, a group, a listener or a user opens a form with one field per
|
||||
parameter. Optional fields are marked, and the values the field knows (outbounds, users,
|
||||
listeners, strategies) are offered: in the TUI, → completes one, and in the app, a list beside
|
||||
|
||||
+181
-2
@@ -101,12 +101,22 @@ services.proxy-suite.inbounds.subscriptions = {
|
||||
enable = true;
|
||||
baseUrl = "https://vpn.example.com/sub";
|
||||
};
|
||||
services.nginx.virtualHosts."vpn.example.com".locations."/sub/".alias =
|
||||
"/run/proxy-suite-inbounds/subscriptions/";
|
||||
services.nginx.virtualHosts."vpn.example.com".locations."/sub/" = {
|
||||
alias = "/run/proxy-suite-inbounds/subscriptions/";
|
||||
extraConfig = "access_log off;"; # the token is the URL's secret
|
||||
};
|
||||
```
|
||||
|
||||
Then `proxy-ctl inbounds sub phone --qr` prints that user's subscription.
|
||||
|
||||
The token at the end of the URL is all that guards a subscription. It is an HMAC under a key
|
||||
generated on first start (/var/lib/proxy-suite/inbounds/subscription-key, carried by
|
||||
`proxy-ctl inbounds export`), or under `subscriptions.keyFile` when you keep your own. A
|
||||
server that handed out URLs before there was a key keeps them with
|
||||
`subscriptions.keyFile = false`: its tokens stay a hash of the user's name and
|
||||
credentials, which anyone who has one of the user's links can work out, and with it the rest
|
||||
of their links. Turning the key on later changes every user's URL.
|
||||
|
||||
## Add users and listeners at runtime
|
||||
|
||||
With `inbounds.runtime`, users and listeners can be added with `proxy-ctl`, the TUI or the app,
|
||||
@@ -144,10 +154,179 @@ up is refused, and anything that stops working later (a certificate removed from
|
||||
say) is left out with a warning in `proxy-ctl logs proxy-suite-inbounds` while the rest runs.
|
||||
Without root, members of `userControl.group` need the `inbounds` scope.
|
||||
|
||||
## Policies: expiry, traffic, devices, speed
|
||||
|
||||
`inbounds.manager` runs a daemon that keeps each user's policy and applies it to the running
|
||||
inbounds without a restart: users switched off, out of time or out of traffic leave XRay
|
||||
through its API (their open connections are cut), the others keep theirs.
|
||||
|
||||
```nix
|
||||
services.proxy-suite.inbounds = {
|
||||
manager = {
|
||||
enable = true;
|
||||
speedLimits.enable = true; # nftables, and proxy-suite's XRay patch
|
||||
};
|
||||
# Declared users take a policy in the config; runtime ones get theirs from proxy-ctl or the API.
|
||||
users.phone.policy = {
|
||||
expiresAt = "2026-12-31";
|
||||
trafficLimit = "100G";
|
||||
trafficPeriod = "monthly";
|
||||
ipLimit = 2;
|
||||
speedLimit = "50M/10M"; # down/up, bits per second
|
||||
};
|
||||
};
|
||||
```
|
||||
|
||||
```sh
|
||||
proxy-ctl inbounds users add alice --listener vless-reality --expires +30d --traffic 50G --period monthly --ips 2
|
||||
proxy-ctl inbounds users # status, traffic used of the allowance, expiry
|
||||
proxy-ctl inbounds users show alice
|
||||
proxy-ctl inbounds users set alice --speed 20M/5M
|
||||
proxy-ctl inbounds users extend alice 30d # from the expiry, or from now if it passed
|
||||
proxy-ctl inbounds users extend alice 30d --reset # a renewal: the traffic starts over too
|
||||
proxy-ctl inbounds users add bob --listener vless-reality --on-hold 30d --traffic 50G
|
||||
proxy-ctl inbounds users reset alice # start the traffic over
|
||||
proxy-ctl inbounds users rotate-sub alice # a new subscription URL; the old one stops answering
|
||||
proxy-ctl inbounds users disable alice
|
||||
proxy-ctl inbounds bans # addresses past an ipLimit, banned for a while
|
||||
```
|
||||
|
||||
What a policy holds:
|
||||
|
||||
- `expiresAt`: past it the user is switched off, and their subscription still says when.
|
||||
- `expiresAfter` (`--on-hold`): a term that starts with the first connection, for access sold
|
||||
ahead. Until the user connects they are on hold; then `expiresAt` is set that much later
|
||||
(event user.activated). `extend` lengthens the term while on hold. An `expiresAt` given wins.
|
||||
- `trafficLimit`, `trafficPeriod`: up and down together, counted from the day the user came
|
||||
or was reset; a period renews at local midnight, monthly on that day of the month.
|
||||
- `ipLimit`: past it, the addresses that came last are banned from the user's ports for
|
||||
`manager.ipLimit.banTime`. Not on AmneziaWG (a peer has one address anyway), nor behind
|
||||
a PROXY-protocol front.
|
||||
- `speedLimit`: XRay marks the sockets its exits dial for the user with their slot, and
|
||||
nftables polices that mark both ways; AmneziaWG peers by their tunnel address.
|
||||
- `meta`: strings for a bot of yours, such as a Telegram ID.
|
||||
|
||||
Runtime users expired long ago can go by themselves: `manager.deleteExpiredAfter = "30d"`
|
||||
deletes each that long after its expiry (event user.deleted, with the reason). Declared users
|
||||
stay.
|
||||
|
||||
Subscriptions served by the manager carry the traffic, the allowance and the expiry
|
||||
(`subscription-userinfo`), which v2rayN, Hiddify, Happ and Streisand show, plus a title and
|
||||
an update interval. The same URL answers each client in what it reads:
|
||||
|
||||
- Clash and mihomo apps (Clash Meta, Clash Verge, FlClash, Stash): a mihomo config, the
|
||||
user's servers in a group that picks the fastest and one to choose by hand.
|
||||
- The sing-box apps (SFA, SFI, SFM): a sing-box config with TUN.
|
||||
- A browser: a page with the state, traffic and expiry, a QR code, buttons that add the
|
||||
subscription to an app, and each link to copy. In Russian when the browser asks for it.
|
||||
The buttons for the browser's system come first (Android, iOS, macOS, Windows, Linux), the
|
||||
rest under "Other apps": Happ, Hiddify, v2rayNG, Streisand, Karing, sing-box, Clash (Clash
|
||||
Meta, FlClash, Clash Verge Rev, Clash Party, Stash) and, on Linux, proxy-suite's own desktop
|
||||
app (`gui.enable`), which asks before it adds the subscription.
|
||||
- Everything else, Hiddify included: base64 of the links, as before.
|
||||
|
||||
`?format=base64|links|clash|sing-box|html` picks one by hand. Listeners only XRay dials
|
||||
(XHTTP, ECH) are left out of the Clash and sing-box configs, and AmneziaWG out of all of them.
|
||||
The page's QR code, drawn by the browser, is of `inbounds.subscriptions.baseUrl`; without it,
|
||||
of the address the browser asked for, as the web server passes it on in `Host` and
|
||||
`X-Forwarded-Proto`. Set `baseUrl`: then no header decides what the page offers. The page
|
||||
runs nothing but its own script and stylesheet (a CSP with their hashes), and no answer is
|
||||
cached, sent on as a referrer or indexed.
|
||||
|
||||
Point the web server at the manager's socket instead of the static files; the tokens and so
|
||||
the URLs stay the same. Keep the tokens out of its access log, and slow down whoever guesses:
|
||||
|
||||
```nix
|
||||
services.nginx.appendHttpConfig = "limit_req_zone $binary_remote_addr zone=sub:1m rate=30r/m;";
|
||||
services.nginx.virtualHosts."vpn.example.com".locations."/sub/" = {
|
||||
proxyPass = "http://unix:/run/proxy-suite-inbounds-manager/sub.sock:";
|
||||
recommendedProxySettings = true; # Host, X-Forwarded-Proto, X-Real-IP
|
||||
extraConfig = ''
|
||||
access_log off;
|
||||
limit_req zone=sub burst=20 nodelay;
|
||||
'';
|
||||
};
|
||||
```
|
||||
|
||||
A token that is not there gets a 404 and a line in the manager's journal, at most one a minute
|
||||
per address (X-Real-IP from the web server), with how many came since:
|
||||
`subscription: unknown token from 203.0.113.7 (12 more since the last line)`. A fail2ban
|
||||
filter on it bans whoever keeps guessing.
|
||||
|
||||
`proxy-ctl inbounds users rotate-sub <name>` gives a user a new URL with their credentials
|
||||
left as they are, for a URL that got out; their clients need the new one. It stays with the
|
||||
user through an export and import.
|
||||
|
||||
Worth knowing:
|
||||
|
||||
- A user switched off by the manager loses their open connections too: TCP ones are closed
|
||||
(`ss -K`), UDP ones (Hysteria2, XHTTP over HTTP/3) dropped for a while. Others behind the
|
||||
same address reconnect once. Without the manager, removing a runtime user cuts its TCP
|
||||
connections only.
|
||||
- Giving a user a speed limit, or taking it away, changes their XRay level: their
|
||||
connections drop once.
|
||||
- An exit whose own JSON or URL sets `sockopt.mark` keeps it, and its users are not
|
||||
speed-limited there. Socks and http listeners take no speed limit either.
|
||||
|
||||
### The API
|
||||
|
||||
The manager answers HTTP+JSON on `/run/proxy-suite-inbounds-manager/api.sock` (root, and
|
||||
`userControl.group` with the "inbounds" scope, or `manager.api.group`), and with
|
||||
`manager.api.listen` and bearer tokens over TCP, for a bot elsewhere (behind TLS):
|
||||
|
||||
```sh
|
||||
curl --unix-socket /run/proxy-suite-inbounds-manager/api.sock http://x/api/v1/users
|
||||
curl --unix-socket /run/proxy-suite-inbounds-manager/api.sock http://x/api/v1/users \
|
||||
-d '{"name": "bob", "listeners": ["vless-reality"], "policy": {"expiresAt": "+30d", "trafficLimit": "50G"}}'
|
||||
```
|
||||
|
||||
| Call | What |
|
||||
| --- | --- |
|
||||
| `GET /api/v1/users`, `GET /api/v1/users/<name>` | users: policy, status and why, traffic, online addresses, subscription |
|
||||
| `POST /api/v1/users` | `{name, listeners, order?, policy?}`: a runtime user, secrets generated |
|
||||
| `PATCH /api/v1/users/<name>` | policy fields, and `unset: [fields]` to drop runtime ones |
|
||||
| `DELETE /api/v1/users/<name>` | a runtime user, and their policy |
|
||||
| `POST /api/v1/users/<name>/enable`, `/disable`, `/reset-traffic` | |
|
||||
| `POST /api/v1/users/<name>/extend` | `{by: "30d"}` or `{until: "2027-01-31"}`, and `resetTraffic: true` to start the traffic over |
|
||||
| `POST /api/v1/users/<name>/rotate-subscription` | a new subscription URL; the old one stops answering |
|
||||
| `PUT /api/v1/users/<name>/listeners` | `{listeners: [...]}` |
|
||||
| `GET /api/v1/users/<name>/links` | share links and client configs |
|
||||
| `GET /api/v1/listeners`, `/online`, `/bans`; `DELETE /api/v1/bans/<address>` | |
|
||||
| `GET /api/v1/export`, `POST /api/v1/import` | see below |
|
||||
| `GET /api/v1/events` | the latest events |
|
||||
|
||||
Sizes take K, M, G, T (binary), speeds k, M, G bits per second, times a date, an ISO time,
|
||||
a Unix time or `+30d`. Errors come as `{"error": "..."}` with a 4xx status.
|
||||
|
||||
`manager.webhooks` POST each event as JSON (`{event, user, at, data}`), signed with
|
||||
`X-Proxy-Suite-Signature: sha256=<HMAC>` when given a secret: user.created, user.deleted,
|
||||
user.updated, user.enabled, user.disabled (with the reasons), user.reset, user.activated
|
||||
(a term on hold started), user.traffic (80 % and 100 % of the allowance), user.expiring
|
||||
(3 days and 1 day before) and user.ip-limit.
|
||||
|
||||
### Moving to another server
|
||||
|
||||
```sh
|
||||
proxy-ctl inbounds export users.json # on the old one: 0600, it holds every secret
|
||||
proxy-ctl inbounds import users.json # on the new one, with the same listeners
|
||||
```
|
||||
|
||||
The export holds the runtime users and listeners (their UUIDs, passwords and REALITY keys),
|
||||
the policies and what they are measured against, the AmneziaWG listeners' keys and
|
||||
addresses, the Salamander passwords proxy-suite generated, and the traffic counted. Secrets
|
||||
the config names by file (sops and the like) are not in it. Runtime users and listeners
|
||||
already on the new server are refused and policies already there kept, unless `--replace`;
|
||||
an AmneziaWG listener that has a key already keeps it unless `--replace`, which its existing
|
||||
clients need.
|
||||
|
||||
## Good to know
|
||||
|
||||
- Clients cannot reach this host's LAN or Russian sites by default
|
||||
(`inbounds.routing.blockPrivate`, `blockRu`).
|
||||
- Nor, by default, BitTorrent or port 25 (`routing.blockTorrent`, `routing.blockPorts`):
|
||||
copyright notices and spam are what hosters close servers over. XRay's sniffing catches
|
||||
the peers' handshake, not trackers, DHT or encrypted connections: torrents get slow, not
|
||||
impossible. Should a complaint come anyway, `inbounds.accessLog` logs who went where.
|
||||
- Through "direct", clients reach this host itself only on the listeners' ports and
|
||||
`inbounds.serverPorts` (80/443 with subscriptions), whatever it listens on. Its addresses
|
||||
are read when the inbounds start: restart them after the address changes.
|
||||
|
||||
Reference in new issue
Block a user