iac/nixos/hosts/asxpio-services/xmpp.nix
Sergei Poljanski cbf14b4b99
nixos: monitoring as native services
Every host runs node_exporter, cAdvisor (now against Podman), Alloy and
the security-metrics script, on its private address. Each service
declares its own expected ports, users and privileged containers next
to its definition, so the security baseline follows the config instead
of a separate inventory list.

On ops: Prometheus, Loki, Grafana, the blackbox prober and the Postgres
exporter, with the same scrape jobs, probes, retention, dashboards and
33 alert rules. Two rules matched container-era names and now match the
native ones: Forgejo's log is unit forgejo.service, Grafana's route is
grafana@file.

Grafana keeps its default secret_key on production, because its
database was written with it; rotating it is a separate step.

Prometheus, Grafana and Alloy come from nixos-unstable: their data is
from newer versions than 26.05 ships.

LLMNR and mDNS are off: the baseline flagged them as public listeners.

Tried on the rehearsal pair: all 28 scrape targets up, logs from both
hosts in Loki, Grafana WireGuard-only, no unexpected port, user or
container on either host.

Assisted-by: Claude:opus-5-5
2026-11-17 04:48:56 +04:00

113 lines
3.6 KiB
Nix

# XMPP for asxp.io: another.im's ejabberd build, its push server and the
# Telegram gateway. A custom image, so containers; the two helpers share
# ejabberd's network namespace and reach its component port on 127.0.0.1.
#
# /opt/xmpp/state (secrets.env, certs/, apushd/, tackygram/) is host data:
# generated once, backed up, not in this repo. Certificates arrive there
# from asxpio-ops (xmpp-cert-sync).
{ config, lib, ... }:
let
# renovate: datasource=docker depName=dev.another.im/another-im/anotherim-server
ejabberd = "dev.another.im/another-im/anotherim-server:2026.11.07";
# renovate: datasource=docker depName=dev.another.im/another-im/apushd
apushd = "dev.another.im/another-im/apushd:0.2";
# renovate: datasource=docker depName=dev.another.im/another-im/tackygram
tackygram = "dev.another.im/another-im/tackygram:0.4.3";
callPorts = "50000-50099";
state = "/opt/xmpp/state";
helper = {
dependsOn = [ "xmpp-ejabberd" ];
extraOptions = [ "--network=container:xmpp-ejabberd" ];
};
in
{
options.asxpio.publicIPv4 = lib.mkOption { type = lib.types.str; };
config = {
virtualisation.oci-containers.containers = {
xmpp-ejabberd = {
image = ejabberd;
environment = {
EJABBERD_MACRO_XMPP_DOMAIN = "asxp.io";
EJABBERD_MACRO_TURN_IP = config.asxpio.publicIPv4;
EJABBERD_MACRO_POW_DIFFICULTY = "6";
EJABBERD_MACRO_REGISTRATION_TIMEOUT = "600";
EJABBERD_MACRO_UPLOAD_URL = "https://hel1.your-objectstorage.com/asxpio-xmpp-public/";
EJABBERD_MACRO_ACME_URL = "https://acme-v02.api.letsencrypt.org/directory";
};
environmentFiles = [ "${state}/secrets.env" ];
ports = [
"5222:5222" # clients, STARTTLS
"5223:5223" # clients, direct TLS
"5269:5269" # other servers
"5443:5443" # WebSocket, host-meta
"8448:8448" # Matrix federation
"3478:3478/udp" # STUN and TURN
"3478:3478/tcp"
"49160-49199:49160-49199/udp" # TURN relay
"7777:7777" # SOCKS5 bytestreams proxy
"${callPorts}:${callPorts}/udp" # gateway calls
];
volumes = [
"xmpp_database:/opt/ejabberd/database"
"xmpp_logs:/opt/ejabberd/logs"
"${state}/certs:/opt/ejabberd/conf/certs:ro"
];
};
xmpp-apushd = helper // {
image = apushd;
volumes = [ "${state}/apushd:/etc/apushd:ro" ];
};
xmpp-tackygram = helper // {
image = tackygram;
environment = {
CREDENTIALS_DIRECTORY = "/run/credentials";
TACKYGRAM_CALL_IP = config.asxpio.publicIPv4;
TACKYGRAM_CALL_PORTS = callPorts;
};
environmentFiles = [ "${state}/tackygram/env" ];
volumes = [
"xmpp_tackygram:/var/lib/tackygram"
"${state}/tackygram/key:/run/credentials/gateway-key:ro"
];
};
};
asxpio.waitForData = [
"podman-xmpp-ejabberd"
"podman-xmpp-apushd"
"podman-xmpp-tackygram"
];
# Published ports belong to rootful Podman's port forwarder
asxpio.security.ports = map (p: "${p}/conmon") [
"tcp/5222-5223"
"tcp/5269"
"tcp/5443"
"tcp/8448"
"tcp/3478"
"udp/3478"
"tcp/7777"
"udp/49160-49199"
"udp/50000-50099"
];
networking.firewall.allowedTCPPorts = [
5222
5223
5269
5443
8448
3478
7777
];
networking.firewall.allowedUDPPorts = [ 3478 ];
networking.firewall.allowedUDPPortRanges = [
{ from = 49160; to = 49199; }
{ from = 50000; to = 50099; }
];
};
}