refactor: users single-point
This commit is contained in:
35 files changed
+1009
-381
No files matched your search
@@ -1,4 +1,9 @@
|
||||
{ lib, proxySuiteUpstream, ... }:
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
proxySuiteUpstream,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
inherit (lib)
|
||||
@@ -108,19 +113,88 @@ in
|
||||
blockRu = bool true ''Block Russian destinations (geosite "category-ru", geoip "ru").'';
|
||||
blockPrivate = bool true "Block private and loopback addresses, so clients cannot reach this host's LAN or local services.";
|
||||
|
||||
zapretDirect = bool true "Send zapret hostlist sites direct, so this host's zapret unblocks them. Only for the default `via`.";
|
||||
zapretDirect = bool true "Send zapret hostlist sites direct, so this host's zapret unblocks them. Only for the default `via`. With a direct listener or the XRay backend, only by IP: XRay matches names by what a client puts in its handshake, whatever address it connects to.";
|
||||
|
||||
# Consumed in derived.nix (the addresses), rules/proxy-inbounds.nix and the inbounds'
|
||||
# start script (the interface).
|
||||
serverSource = {
|
||||
ipv4 = mkOption {
|
||||
type = types.nullOr (types.strMatching "([0-9]{1,3}\\.){3}[0-9]{1,3}/[0-9]{1,2}");
|
||||
default = null;
|
||||
example = "10.78.0.0/24";
|
||||
description = ''
|
||||
Range each inbound user gets an address from, for the connections they make to this
|
||||
host itself (`serverAddress`, `serverAliases`, `serverPorts`). Otherwise those come
|
||||
from this host's own address, and its services (mail, the web server, their rate
|
||||
limits and bans) see every user as one. They see neither the users' real addresses.
|
||||
The addresses sit on a dummy interface and reach nothing but this host. Pick a range
|
||||
nothing here routes or trusts. Users are numbered by their `order`, then name, from
|
||||
the range's second address: set `order` to keep each user's address as users come
|
||||
and go.
|
||||
'';
|
||||
};
|
||||
ipv6 = mkOption {
|
||||
type = types.nullOr (types.strMatching "[0-9a-fA-F:]*::/[0-9]{1,3}");
|
||||
default = null;
|
||||
example = "fd78:78:78::/64";
|
||||
description = ''
|
||||
The same for IPv6: a prefix written with "::", such as a ULA /64. Needed as well when
|
||||
`serverAliases` lists an IPv6 address, which is otherwise dialed from this host's own.
|
||||
'';
|
||||
};
|
||||
interface = mkOption {
|
||||
type = types.strMatching "[a-zA-Z0-9_-]{1,15}";
|
||||
default = "ps-self";
|
||||
description = "Dummy interface the `serverSource` addresses are put on.";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
users = mkOption {
|
||||
type = types.attrsOf (types.submodule t.userModule);
|
||||
default = { };
|
||||
description = ''
|
||||
Inbound users, by name, which listeners accept by naming them in their `users`. Each
|
||||
listener takes the secret its protocol wants: `uuid`/`uuidFile` for vless and vmess,
|
||||
`password`/`passwordFile` for the others, the keys for AmneziaWG.
|
||||
'';
|
||||
example = literalExpression ''
|
||||
{
|
||||
phone = {
|
||||
order = 1;
|
||||
uuidFile = "/run/secrets/proxy-inbound-uuid";
|
||||
};
|
||||
laptop.order = 2;
|
||||
}
|
||||
'';
|
||||
};
|
||||
|
||||
listeners = mkOption {
|
||||
type = types.attrsOf t.inboundType;
|
||||
default = { };
|
||||
description = "Server listeners, by tag.";
|
||||
# Each named user becomes the user, with their name: nothing past the options sees names.
|
||||
apply = lib.mapAttrs (
|
||||
tag: listener:
|
||||
listener
|
||||
// {
|
||||
users = map (
|
||||
name:
|
||||
(config.services.proxy-suite.inbounds.users.${name}
|
||||
or (throw "proxy-suite: inbounds listener '${tag}' names user '${name}', which inbounds.users does not define")
|
||||
)
|
||||
// {
|
||||
inherit name;
|
||||
}
|
||||
) listener.users;
|
||||
}
|
||||
);
|
||||
example = literalExpression ''
|
||||
{
|
||||
vless-reality = {
|
||||
type = "vless";
|
||||
port = 443;
|
||||
users = [ { uuidFile = "/run/secrets/proxy-inbound-uuid"; } ];
|
||||
users = [ "phone" ];
|
||||
flow = "xtls-rprx-vision";
|
||||
reality = {
|
||||
enable = true;
|
||||
@@ -134,7 +208,7 @@ in
|
||||
home = {
|
||||
type = "amneziawg";
|
||||
port = 51820;
|
||||
users = [ { name = "phone"; } { name = "laptop"; } ];
|
||||
users = [ "phone" "laptop" ];
|
||||
amneziaWg.mode = "lan";
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,13 +5,20 @@ let
|
||||
inherit (import ./amnezia-wg.nix { inherit lib; }) obfuscationType;
|
||||
inherit (import ../lib.nix { inherit lib; }) nullStr;
|
||||
|
||||
userType = types.submodule {
|
||||
# One inbound user, in `inbounds.users` under their name (shown in share links, subscriptions
|
||||
# and stats); listeners name the ones they accept.
|
||||
userModule = {
|
||||
options = {
|
||||
name = mkOption {
|
||||
type = types.str;
|
||||
default = "";
|
||||
description = "User name, shown in share links, subscriptions and stats.";
|
||||
example = "phone";
|
||||
order = mkOption {
|
||||
type = types.nullOr types.ints.positive;
|
||||
default = null;
|
||||
description = ''
|
||||
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.
|
||||
'';
|
||||
example = 1;
|
||||
};
|
||||
uuid = nullStr "UUID (vless, vmess). Ends up in the Nix store; prefer `uuidFile`." "b831381d-6324-4d53-ad4f-8cda48b30811";
|
||||
uuidFile = nullStr "File with the UUID." "/run/secrets/proxy-inbound-uuid";
|
||||
@@ -382,10 +389,15 @@ let
|
||||
};
|
||||
|
||||
users = mkOption {
|
||||
type = types.listOf userType;
|
||||
# Resolved to the users themselves, with their name, by the listeners option's apply
|
||||
# (options/inbounds.nix): everything past the options reads full users.
|
||||
type = types.listOf (types.strMatching "[^[:space:]]+");
|
||||
default = [ ];
|
||||
description = "Accepted users.";
|
||||
example = [ { uuidFile = "/run/secrets/proxy-inbound-uuid"; } ];
|
||||
description = "Accepted users, by their names in `inbounds.users`.";
|
||||
example = [
|
||||
"phone"
|
||||
"laptop"
|
||||
];
|
||||
};
|
||||
|
||||
flow = mkOption {
|
||||
@@ -500,5 +512,5 @@ let
|
||||
);
|
||||
in
|
||||
{
|
||||
inherit inboundType;
|
||||
inherit inboundType userModule;
|
||||
}
|
||||
@@ -106,7 +106,7 @@ in
|
||||
type = types.package;
|
||||
default = proxySuiteUpstream.whitelist-bypass;
|
||||
defaultText = lib.literalMD "proxy-suite's `whitelist-bypass` (`pkgs/whitelist-bypass.nix`)";
|
||||
description = "whitelist-bypass package.";
|
||||
description = "whitelist-bypass package. It must take the call link and the proxy password from WB_LINK and WB_UPSTREAM_PASS, as `pkgs/whitelist-bypass.nix` patches it to.";
|
||||
};
|
||||
|
||||
joiners = mkOption {
|
||||
|
||||
Reference in new issue
Block a user