feat: runtime users and inbounds

This commit is contained in:
fufsob committed 2026-09-29 08:11:29 +00:00
1 parent a4752049ef
commit 9bbffe24b4
36 files changed
+2932 -83

No files matched your search

+3
View File
@@ -74,6 +74,9 @@ in
firewall = {
allowedTCPPorts = internalOption (types.listOf types.port) [ ];
allowedUDPPorts = internalOption (types.listOf types.port) [ ];
# { from; to; }, as networking.firewall takes them.
allowedTCPPortRanges = internalOption (types.listOf (types.attrsOf types.port)) [ ];
allowedUDPPortRanges = internalOption (types.listOf (types.attrsOf types.port)) [ ];
extraReversePathFilterRules = internalOption types.lines "";
# nftables firewall only: iptables has no such hook.
extraInputRules = internalOption types.lines "";
+85
View File
@@ -150,6 +150,91 @@ in
};
};
# Consumed by scripts/inbound_runtime.py, which merges the spool into the spec at start,
# and by proxy-ctl, which writes the spool.
runtime = {
enable = mkEnableOption "" // {
description = ''
Users and listeners added at runtime with `proxy-ctl inbounds users add` and
`inbounds add`, kept in `inbounds.d` in the state directory. Runtime users can be
bound to any listener; declared users to runtime listeners only. A change restarts
the inbounds, which drops every connection once. Anything a runtime listener could
reach beyond its port is declared here: its ports, certificates, exits and
fallbacks. Members of `userControl.group` need the "inbounds" scope.
'';
};
ports = mkOption {
type = types.listOf (types.either types.port (types.strMatching "[0-9]+-[0-9]+"));
default = [ ];
description = ''
Ports runtime listeners may use, on any address: single ports and "from-to" ranges.
Opened in the firewall (TCP and UDP) with `openFirewall`, and reachable through the
tunnel like the listeners' own. Keep them clear of the declared listeners and of
other services here.
'';
example = [
8443
"20000-20099"
];
};
vias = mkOption {
type = types.listOf types.str;
default = [ ];
description = ''
Exits a runtime listener may pick with `via`, besides `routing.via` and "block":
"proxy", "direct" or a `proxy.outbounds` tag, as in `routing.via`.
'';
example = [ "direct" ];
};
tlsCertificates = mkOption {
type = types.attrsOf (
types.submodule {
options = {
certificateFile = mkOption {
type = types.str;
description = "File with the PEM certificate chain.";
};
keyFile = mkOption {
type = types.str;
description = "File with the PEM private key.";
};
serverName = mkOption {
type = types.nullOr types.str;
default = null;
description = "SNI in share links. `null`: `serverAddress`.";
};
};
}
);
default = { };
description = ''
Certificates a runtime listener with TLS (trojan, hysteria2, `tls.enable`) may use,
by name: it names one in `tls.certificate` (`--tls <name>`), never a file.
'';
example = literalExpression ''
{
main = {
certificateFile = "/var/lib/acme/vpn.example.com/fullchain.pem";
keyFile = "/var/lib/acme/vpn.example.com/key.pem";
};
}
'';
};
fallbackDests = mkOption {
type = types.listOf (types.either types.port types.str);
default = [ ];
description = ''
`dest` values a runtime listener's fallbacks may use, such as a decoy site. A
fallback to a `listener` must name another runtime listener.
'';
example = [ "127.0.0.1:8080" ];
};
};
users = mkOption {
type = types.attrsOf (types.submodule t.userModule);
default = { };
@@ -16,7 +16,7 @@ let
The user's number, for good: their `inbounds.routing.serverSource` addresses are
that many past the start of each range (5: 10.78.0.5 in 10.78.0.0/24). Users
without one follow the highest number given, by name, and move when users are
added before them. Unique.
added before them. Unique. Runtime users (`inbounds.runtime`) go around these numbers.
'';
example = 1;
};
@@ -24,6 +24,7 @@ in
"autoProxy"
"zapret"
"stats"
"inbounds"
"whitelistBypass"
"amneziaWg"
]
@@ -39,6 +40,8 @@ in
- "autoProxy": see and change what autoProxy learned.
- "zapret": change zapret2's learned sites, and `zapret cutoff probe`.
- "stats": `inbounds stats`.
- "inbounds": add, remove and bind runtime inbound users and listeners
(`inbounds.runtime`), and read the secrets they are given.
- "whitelistBypass": everything under `proxy-ctl wl`.
- "amneziaWg": add and remove global AmneziaWG profiles (`proxy-ctl awg add`, `awg rm`).
A global profile takes over the host's routes and DNS. Starting and stopping one is