A Telegram bot has a single getUpdates consumer, so a broker per host would split approval taps between them. mars now runs the gateway: the bot's only poller, relaying prompts and taps for terra's and titan's brokers over the tailnet (:8097) without ever seeing an item. Each broker authenticates with its own pass_broker_gateway_token; mars holds only the sha256, and the prompt is labelled with the host that token belongs to. The bot token and chat id move to mars and are dropped from the other hosts' sops files (terra.yaml also loses its leftover LibreChat keys and gains protonvpn_wg_private_key, which a later commit uses). Covered by checks.pass-broker-gateway (two nodes: labels, cancel, expiry, per-host token isolation, gateway down); the fakes are shared with checks.pass-broker. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
109 lines
3.4 KiB
Nix
109 lines
3.4 KiB
Nix
{ config, pkgs, lib, ... }:
|
|
|
|
# The approval gateway: sole owner of the pass-broker Telegram bot, so every
|
|
# host's broker (pass-broker.nix with `gateway`) prompts in the same chat. It
|
|
# relays prompts and taps and never sees an item. Tailnet-only: tailscale0 is
|
|
# a trusted interface (services/vpn/tailscale.nix) and nothing opens the port
|
|
# elsewhere.
|
|
#
|
|
# Brokers authenticate with a per-host token; only its sha256 is here, so this
|
|
# host holds no broker's credential. The prompt is labelled with the host the
|
|
# token belongs to, not what the request claims.
|
|
|
|
let
|
|
cfg = config.homelab.passBrokerGateway;
|
|
pass-broker = pkgs.callPackage ../../pkgs/pass-broker.nix { };
|
|
|
|
configFile = pkgs.writeText "pass-broker-gateway.json" (builtins.toJSON {
|
|
listen = "0.0.0.0:${toString cfg.port}";
|
|
telegram = {
|
|
api_base = cfg.telegram.apiBase;
|
|
token_file = cfg.telegram.tokenFile;
|
|
chat_id_file = cfg.telegram.chatIdFile;
|
|
};
|
|
hosts = lib.mapAttrsToList (name: h: { inherit name; token_sha256 = h.tokenSha256; }) cfg.hosts;
|
|
max_timeout_secs = cfg.maxTimeout;
|
|
});
|
|
in
|
|
{
|
|
options.homelab.passBrokerGateway = {
|
|
enable = lib.mkEnableOption "pass-broker approval gateway";
|
|
|
|
port = lib.mkOption {
|
|
type = lib.types.port;
|
|
default = 8097;
|
|
};
|
|
|
|
telegram = {
|
|
apiBase = lib.mkOption {
|
|
type = lib.types.str;
|
|
default = "https://api.telegram.org";
|
|
};
|
|
tokenFile = lib.mkOption {
|
|
type = lib.types.path;
|
|
description = "Bot token of a bot nothing else polls.";
|
|
};
|
|
chatIdFile = lib.mkOption {
|
|
type = lib.types.path;
|
|
description = "Your Telegram user id; only its taps count.";
|
|
};
|
|
};
|
|
|
|
hosts = lib.mkOption {
|
|
description = "Brokers allowed to prompt, by the name shown in the prompt.";
|
|
type = lib.types.attrsOf (lib.types.submodule {
|
|
options.tokenSha256 = lib.mkOption {
|
|
type = lib.types.strMatching "[0-9a-f]{64}";
|
|
description = "sha256 of that host's gateway token, hex.";
|
|
};
|
|
});
|
|
};
|
|
|
|
maxTimeout = lib.mkOption {
|
|
type = lib.types.int;
|
|
default = 600;
|
|
description = "Cap on how long a broker may keep a prompt open, in seconds.";
|
|
};
|
|
};
|
|
|
|
config = lib.mkIf cfg.enable {
|
|
users.users.pass-broker-gateway = {
|
|
isSystemUser = true;
|
|
group = "pass-broker-gateway";
|
|
};
|
|
users.groups.pass-broker-gateway = { };
|
|
|
|
systemd.services.pass-broker-gateway = {
|
|
description = "pass-broker approval gateway (Telegram)";
|
|
wantedBy = [ "multi-user.target" ];
|
|
wants = [ "network-online.target" ];
|
|
after = [ "network-online.target" ];
|
|
environment.PASS_BROKER_GATEWAY_CONFIG = configFile;
|
|
|
|
serviceConfig = {
|
|
ExecStart = "${pass-broker}/bin/pass-broker gateway";
|
|
User = "pass-broker-gateway";
|
|
Group = "pass-broker-gateway";
|
|
Restart = "on-failure";
|
|
RestartSec = 5;
|
|
|
|
NoNewPrivileges = true;
|
|
ProtectSystem = "strict";
|
|
ProtectHome = true;
|
|
PrivateTmp = true;
|
|
PrivateDevices = true;
|
|
ProtectProc = "invisible";
|
|
ProtectKernelTunables = true;
|
|
ProtectKernelModules = true;
|
|
ProtectControlGroups = true;
|
|
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
|
|
RestrictNamespaces = true;
|
|
LockPersonality = true;
|
|
MemoryDenyWriteExecute = true;
|
|
SystemCallArchitectures = "native";
|
|
UMask = "0077";
|
|
};
|
|
};
|
|
};
|
|
}
|