Files
homelab/services/identity/pass-broker.nix
T
darmanandClaude Opus 5.5 3dccafe2b8 feat(terra): pass-broker for Telegram-approved Proton Pass access
A Rust daemon running as its own system user holds terra's only pass-cli
session, an agent PAT scoped to the HomeLab vaults. `pass-broker get` asks
it for an item; per-item rules decide auto/ask/deny, and "ask" sends a
Telegram prompt that only darman's account can approve (10-min grant for
darman@*/root@*). Requests whose client is gone are dropped or withdrawn,
and the client gives up after 30s without an answer.

scripts/deploy uses the broker exclusively when its socket exists. Covered
by checks.pass-broker (fake pass-cli + Telegram). Secrets added for all
hosts; only terra runs the broker so far.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-16 01:48:46 +02:00

179 lines
5.5 KiB
Nix

{ config, pkgs, lib, ... }:
# pass-broker: Proton Pass items for darman's processes (Claude included),
# each gated by a tap on Telegram. The daemon runs as its own user and holds
# the host's only pass-cli session, an agent PAT scoped to the homelab vaults,
# so nothing running as darman can read the session itself. Client:
# `pass-broker get --item <title> --reason <why>`; scripts/deploy uses it.
#
# Telegram, not a desktop dialog: any process of darman's can fake Wayland
# input and click its own approval. The bot must be dedicated to this: a bot
# has one getUpdates consumer, so sharing it (e.g. with Hermes) would let the
# other side see or swallow the approvals.
let
cfg = config.homelab.passBroker;
pass-broker = pkgs.callPackage ../../pkgs/pass-broker.nix { };
stateDir = "/var/lib/pass-broker";
configFile = pkgs.writeText "pass-broker.json" (builtins.toJSON {
host = config.networking.hostName;
default_vault = cfg.vault;
allowed_users = cfg.users;
pass_cli = "${cfg.passCli}/bin/pass-cli";
session_dir = "${stateDir}/session";
pat_file = cfg.patFile;
approval_timeout_secs = cfg.approvalTimeout;
telegram = {
api_base = cfg.telegram.apiBase;
token_file = cfg.telegram.tokenFile;
chat_id_file = cfg.telegram.chatIdFile;
};
rules = map (r: {
inherit (r) vault item approval;
grant_minutes = r.grantMinutes;
}) cfg.rules;
});
in
{
options.homelab.passBroker = {
enable = lib.mkEnableOption "Telegram-approved Proton Pass broker";
passCli = lib.mkOption {
type = lib.types.package;
default = pkgs.proton-pass-cli;
defaultText = lib.literalExpression "pkgs.proton-pass-cli";
description = "Package providing bin/pass-cli.";
};
patFile = lib.mkOption {
type = lib.types.path;
description = "Agent personal access token (pst_…::…), readable by pass-broker.";
};
vault = lib.mkOption {
type = lib.types.str;
default = "HomeLab";
description = "Vault used when a request names none.";
};
users = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ "darman" ];
description = "Users allowed on the socket, besides root.";
};
approvalTimeout = lib.mkOption {
type = lib.types.int;
default = 120;
description = "Seconds to wait for a tap before refusing.";
};
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 used for nothing else.";
};
chatIdFile = lib.mkOption {
type = lib.types.path;
description = "Your Telegram user id; only its taps count.";
};
};
rules = lib.mkOption {
description = "First match wins; an item no rule matches is refused.";
default = [
{ item = "darman@*"; }
{ item = "root@*"; }
];
type = lib.types.listOf (lib.types.submodule {
options = {
vault = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = "null = the default vault.";
};
item = lib.mkOption {
type = lib.types.str;
description = "Item title; `*` matches anything.";
};
approval = lib.mkOption {
type = lib.types.enum [ "auto" "ask" "deny" ];
default = "ask";
};
grantMinutes = lib.mkOption {
type = lib.types.int;
default = 10;
description = "How long one approval covers the item; 0 = this request only.";
};
};
});
};
};
config = lib.mkIf cfg.enable {
environment.systemPackages = [ pass-broker ];
users.users.pass-broker = {
isSystemUser = true;
group = "pass-broker";
home = stateDir;
};
users.groups.pass-broker = { };
# World-writable on purpose: the daemon checks the peer uid, so adding a
# client needs no group membership and no re-login.
systemd.sockets.pass-broker = {
wantedBy = [ "sockets.target" ];
socketConfig = {
ListenStream = "/run/pass-broker.sock";
SocketMode = "0666";
};
};
systemd.services.pass-broker = {
description = "Proton Pass broker (Telegram-approved)";
requires = [ "pass-broker.socket" ];
wants = [ "network-online.target" ];
after = [ "network-online.target" ];
environment = {
PASS_BROKER_CONFIG = configFile;
HOME = stateDir;
# No keyring for a system user; the session key sits in the 0700 state dir.
PROTON_PASS_KEY_PROVIDER = "fs";
PROTON_PASS_DISABLE_TELEMETRY = "1";
PROTON_PASS_NO_UPDATE_CHECK = "1";
};
serviceConfig = {
ExecStart = "${pass-broker}/bin/pass-broker daemon";
User = "pass-broker";
Group = "pass-broker";
StateDirectory = "pass-broker";
StateDirectoryMode = "0700";
UMask = "0077";
Restart = "on-failure";
RestartSec = 5;
NoNewPrivileges = true;
ProtectSystem = "strict";
ProtectHome = true;
PrivateTmp = true;
PrivateDevices = true;
ProtectKernelTunables = true;
ProtectKernelModules = true;
ProtectControlGroups = true;
RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" ];
RestrictNamespaces = true;
LockPersonality = true;
SystemCallArchitectures = "native";
};
};
};
}