modules/proxy: multi-user support
This commit is contained in:
parent
7727c5cf43
commit
082e64b960
3 changed files with 159 additions and 137 deletions
|
@ -3,6 +3,7 @@
|
||||||
config = {
|
config = {
|
||||||
sops = {
|
sops = {
|
||||||
age.sshKeyPaths = [ "/etc/ssh/ssh_host_ed25519_key" ];
|
age.sshKeyPaths = [ "/etc/ssh/ssh_host_ed25519_key" ];
|
||||||
|
defaultSopsFile = ./secrets/secrets.yaml;
|
||||||
secrets = {
|
secrets = {
|
||||||
wg_private_key = {
|
wg_private_key = {
|
||||||
owner = "root";
|
owner = "root";
|
||||||
|
@ -12,14 +13,6 @@
|
||||||
owner = "root";
|
owner = "root";
|
||||||
sopsFile = ./secrets + "/${config.networking.hostName}.yaml";
|
sopsFile = ./secrets + "/${config.networking.hostName}.yaml";
|
||||||
};
|
};
|
||||||
"sing-box/password" = {
|
|
||||||
owner = "root";
|
|
||||||
sopsFile = ./secrets/secrets.yaml;
|
|
||||||
};
|
|
||||||
"sing-box/uuid" = {
|
|
||||||
owner = "root";
|
|
||||||
sopsFile = ./secrets/secrets.yaml;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
swapDevices = [
|
swapDevices = [
|
||||||
|
@ -32,6 +25,7 @@
|
||||||
custom.prometheus.exporters = {
|
custom.prometheus.exporters = {
|
||||||
enable = true;
|
enable = true;
|
||||||
node.enable = true;
|
node.enable = true;
|
||||||
|
blackbox.enable = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
custom.monitoring = {
|
custom.monitoring = {
|
||||||
|
@ -44,6 +38,11 @@
|
||||||
auth.enable = true;
|
auth.enable = true;
|
||||||
proxyServer = {
|
proxyServer = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
users = [
|
||||||
|
"wyj"
|
||||||
|
"yhb"
|
||||||
|
"xin"
|
||||||
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
sing-box:
|
sing-box:
|
||||||
password: ENC[AES256_GCM,data:qCc1v8nAL0oYisRinMDXGrBQA+r6XNoa,iv:eTxtad4kEdE28XqnrZEek8BtXNY1rNgLvGLxlMzRtl4=,tag:s/shWAkYE4DSnScpTY8ulQ==,type:str]
|
users:
|
||||||
uuid: ENC[AES256_GCM,data:lEpz15sLOVrGDzQwTJyS+tFJY0bMeO265bxocWAjB6qrvxYx,iv:lhk5jl/udUH3AZEuk5ffuvin/qhRUaOZ/3nk1Jaw+DI=,tag:4mKFIVKT+D47njfDsxe9iA==,type:str]
|
wyj:
|
||||||
|
password: ENC[AES256_GCM,data:yp+T3eci9RiuZzdmRSq5nTjHaz8e/Rri,iv:hIPc+7YHUnaIdU9O8GGx3r7l3oBA6prQb+KBQV0G+8k=,tag:2GNiBP4PQy+KGHgLupKGSg==,type:str]
|
||||||
|
uuid: ENC[AES256_GCM,data:Qrgil6G7pjQAQzCCOlstDi27EqqmSuBMhs+RTl9++wrPrIgJ,iv:u+3Z17uX4I6li2qd9UP3y+WaKn7aKfbb3J6H1Pyc1QY=,tag:hSa4AB383/B58XMmZ8LIfQ==,type:str]
|
||||||
|
yhb:
|
||||||
|
password: ENC[AES256_GCM,data:TwRct68TePpcZcnpWIQpFaF23WGMre8=,iv:YU4mQNm0rt2u4ItJwQ8nZPEmJi0+lmEIPG2Kxh/nI58=,tag:ukZem38O/b42dEKM3CYa+w==,type:str]
|
||||||
|
uuid: ENC[AES256_GCM,data:6hVhEqWPLVrn8rCS4x/eapd+iL7JRaXtOGCj9uuPlkGjBTMK,iv:VZ27KWCY6/K5GoNwRNmaRWzqfV7+8iFjtias1vKeGfA=,tag:8mhmZPooxHaGNYdznuFhMQ==,type:str]
|
||||||
|
xin:
|
||||||
|
password: ENC[AES256_GCM,data:SRiPFO+Uwy/PT41SIg7eI68wk4AX6so=,iv:aXwP5wa1IrlnvFo/ZL+DYFFHDdWw2Z83de3ApHUTsXo=,tag:sxXoy1FnDxZBQCDeNxphzQ==,type:str]
|
||||||
|
uuid: ENC[AES256_GCM,data:7xK53SO4x0tOIEIYl6kmmAvnpdsR/tYQoG1t/ytsnO4QqWY3,iv:i694Fnu7g1OA3IGzSaoSGA5/eMPo+I/1TZbYuaQrgNA=,tag:4cUlioJn/IvsvZclgboOSA==,type:str]
|
||||||
sops:
|
sops:
|
||||||
kms: []
|
kms: []
|
||||||
gcp_kms: []
|
gcp_kms: []
|
||||||
|
@ -43,8 +51,8 @@ sops:
|
||||||
K1F1SzI2NFNIKzlreVBXSjAxaUxQd28KFaf1uu7OlqIe0TirJFgS3iPjhXPyfNDE
|
K1F1SzI2NFNIKzlreVBXSjAxaUxQd28KFaf1uu7OlqIe0TirJFgS3iPjhXPyfNDE
|
||||||
m2XUjzdXp+chJCzVOFvpYStqz+e08ADEc+jp3YsTLcxyqvXhQdyL/Q==
|
m2XUjzdXp+chJCzVOFvpYStqz+e08ADEc+jp3YsTLcxyqvXhQdyL/Q==
|
||||||
-----END AGE ENCRYPTED FILE-----
|
-----END AGE ENCRYPTED FILE-----
|
||||||
lastmodified: "2024-12-02T05:26:17Z"
|
lastmodified: "2024-12-06T04:35:52Z"
|
||||||
mac: ENC[AES256_GCM,data:K94zFWPWGUisLCqDjSLs17QxHXPH4tPU/98Sb4lCnt7IRAIn14x/T+BnInY/DK+DOVLLtzSfuN0kgzzGjSzwJx5Vq1G3MkhngRQQRT9dvODTCMAw6lPt98Ofw1CEEsFQnpYo9zIUlCGKg2YPKFLqE7OjkPxqw7VYvgzr5dDw58s=,iv:3xcJfNX5v/e9HgZt3UrHs2/C5ivaBV1rXKIBs9hKKFg=,tag:RQPQQ1cmZiOpQjUwqnzZQA==,type:str]
|
mac: ENC[AES256_GCM,data:DAg4UTwNv+rs6hye2z5UUtA1a4yZbFaAWjLoKAXf87tKgBCZzK8C1q6gLyTQOqp07ptYQd5Q951kfE1a/35SFJsubREzJmu6haxznRgq7pO5HDGqgtjYEHsngsWZh3bUSX/aG2dLISdD81VY68nLzTO0r4h/SL6DNG36RzJgL8E=,iv:V0WhENNt/Szi5VWVD2t5AsWP1tOZUGjFjMNYPDq59XI=,tag:ThRstdzVNtSs6E7qlvKPOw==,type:str]
|
||||||
pgp: []
|
pgp: []
|
||||||
unencrypted_suffix: _unencrypted
|
unencrypted_suffix: _unencrypted
|
||||||
version: 3.9.1
|
version: 3.9.1
|
||||||
|
|
|
@ -21,9 +21,7 @@ let
|
||||||
config.security.acme.certs.${config.deployment.targetHost}.directory + "/cert.pem";
|
config.security.acme.certs.${config.deployment.targetHost}.directory + "/cert.pem";
|
||||||
};
|
};
|
||||||
|
|
||||||
mkSingConfig =
|
mkSingConfig = users: {
|
||||||
{ uuid, password, ... }:
|
|
||||||
{
|
|
||||||
log = {
|
log = {
|
||||||
level = "warn";
|
level = "warn";
|
||||||
};
|
};
|
||||||
|
@ -36,14 +34,12 @@ let
|
||||||
listen_port = cfg.trojan.port;
|
listen_port = cfg.trojan.port;
|
||||||
tcp_multi_path = true;
|
tcp_multi_path = true;
|
||||||
tcp_fast_open = true;
|
tcp_fast_open = true;
|
||||||
users = [
|
users = map (user: {
|
||||||
{
|
name = user.name;
|
||||||
name = "proxy";
|
|
||||||
password = {
|
password = {
|
||||||
_secret = password;
|
_secret = user.passwordFile;
|
||||||
};
|
};
|
||||||
}
|
}) users;
|
||||||
];
|
|
||||||
tls = singTls;
|
tls = singTls;
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -53,17 +49,15 @@ let
|
||||||
listen = "::";
|
listen = "::";
|
||||||
listen_port = port;
|
listen_port = port;
|
||||||
congestion_control = "bbr";
|
congestion_control = "bbr";
|
||||||
users = [
|
users = map (user: {
|
||||||
{
|
name = user.name;
|
||||||
name = "proxy";
|
|
||||||
uuid = {
|
uuid = {
|
||||||
_secret = uuid;
|
_secret = user.uuidFile;
|
||||||
};
|
};
|
||||||
password = {
|
password = {
|
||||||
_secret = password;
|
_secret = user.passwordFile;
|
||||||
};
|
};
|
||||||
}
|
}) users;
|
||||||
];
|
|
||||||
tls = singTls;
|
tls = singTls;
|
||||||
});
|
});
|
||||||
outbounds =
|
outbounds =
|
||||||
|
@ -137,9 +131,14 @@ in
|
||||||
onTrojan = mkEnableOption "forward to warp in trojan";
|
onTrojan = mkEnableOption "forward to warp in trojan";
|
||||||
onTuic = mkEnableOption "forward to warp in first two port of tuic";
|
onTuic = mkEnableOption "forward to warp in first two port of tuic";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
users = mkOption {
|
||||||
|
type = lib.types.listOf lib.types.str;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable (
|
||||||
|
{
|
||||||
boot.kernel.sysctl = {
|
boot.kernel.sysctl = {
|
||||||
"net.core.default_qdisc" = "fq";
|
"net.core.default_qdisc" = "fq";
|
||||||
"net.ipv4.tcp_congestion_control" = "bbr";
|
"net.ipv4.tcp_congestion_control" = "bbr";
|
||||||
|
@ -167,10 +166,26 @@ in
|
||||||
|
|
||||||
services.sing-box = {
|
services.sing-box = {
|
||||||
enable = true;
|
enable = true;
|
||||||
settings = mkSingConfig {
|
settings = (
|
||||||
uuid = config.sops.secrets."sing-box/uuid".path;
|
mkSingConfig (
|
||||||
password = config.sops.secrets."sing-box/password".path;
|
map (n: {
|
||||||
};
|
name = n;
|
||||||
};
|
uuidFile = config.sops.secrets."sing-box/users/${n}/uuid".path;
|
||||||
|
passwordFile = config.sops.secrets."sing-box/users/${n}/password".path;
|
||||||
|
}) cfg.users
|
||||||
|
)
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
// {
|
||||||
|
sops.secrets = (
|
||||||
|
builtins.foldl' (a: b: a // b) { } (
|
||||||
|
map (u: {
|
||||||
|
"sing-box/users/${u}/uuid" = { };
|
||||||
|
"sing-box/users/${u}/password" = { };
|
||||||
|
}) cfg.users
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue