[relay] Calls: a long-poll on the fetch route, TURN credentials for coturn, wakes every 10 s; the module passes the TURN secret by systemd credential
This commit is contained in:
+28
-1
@@ -64,6 +64,24 @@ in
|
||||
'';
|
||||
};
|
||||
|
||||
turn = {
|
||||
secretFile = lib.mkOption {
|
||||
# A string, not a path: a path would copy the secret into the world-readable Nix store.
|
||||
type = lib.types.nullOr lib.types.str;
|
||||
default = null;
|
||||
description = ''
|
||||
The secret the relay shares with the TURN server for calls (coturn `use-auth-secret`), as a file outside
|
||||
the Nix store (e.g. written by Custos). Null: no TURN route (`POST /v0/mailboxes/{id}/turn` is 404).
|
||||
'';
|
||||
};
|
||||
urls = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [ ];
|
||||
example = [ "turn:turn.example.org:3478?transport=udp" "turn:turn.example.org:3478?transport=tcp" ];
|
||||
description = "The TURN servers named in each credential. Required with `secretFile`.";
|
||||
};
|
||||
};
|
||||
|
||||
openFirewall = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = true;
|
||||
@@ -72,6 +90,11 @@ in
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
assertions = [{
|
||||
assertion = (cfg.turn.secretFile == null) == (cfg.turn.urls == [ ]);
|
||||
message = "services.tabellarius.turn: secretFile and urls come together, or neither.";
|
||||
}];
|
||||
|
||||
systemd.services.tabellarius = {
|
||||
description = "Tabellarius message relay (loopback only; Caddy in front)";
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
@@ -84,7 +107,11 @@ in
|
||||
"--max-bytes" (toString cfg.maxBytes)
|
||||
"--max-mailboxes" (toString cfg.maxMailboxes)
|
||||
"--max-invites" (toString cfg.maxInvites)
|
||||
];
|
||||
] + lib.optionalString (cfg.turn.secretFile != null) (" " + lib.escapeShellArgs (
|
||||
# systemd hands the secret to the DynamicUser under its credentials directory (%d); it is never in the store.
|
||||
[ "--turn-secret-file" "%d/turn-secret" ] ++ lib.concatMap (u: [ "--turn-url" u ]) cfg.turn.urls
|
||||
));
|
||||
LoadCredential = lib.mkIf (cfg.turn.secretFile != null) [ "turn-secret:${toString cfg.turn.secretFile}" ];
|
||||
Restart = "on-failure";
|
||||
DynamicUser = true;
|
||||
StateDirectory = "tabellarius";
|
||||
|
||||
Reference in New Issue
Block a user