+ AZ-PLT-1
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
{
|
||||
imports = [
|
||||
./netbird.nix
|
||||
./pgbouncer.nix
|
||||
./postgres.nix
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
{pkgs, ...}: {
|
||||
services.netbird = {
|
||||
enable = true;
|
||||
package = pkgs.unstable.netbird;
|
||||
};
|
||||
|
||||
systemd.services.netbird = {
|
||||
environment = {
|
||||
NB_DISABLE_SSH_CONFIG = "true";
|
||||
};
|
||||
path = [
|
||||
pkgs.shadow
|
||||
pkgs.util-linux
|
||||
];
|
||||
};
|
||||
|
||||
programs.ssh.extraConfig = ''
|
||||
Match exec "${pkgs.netbird}/bin/netbird ssh detect %h %p"
|
||||
PreferredAuthentications password,publickey,keyboard-interactive
|
||||
PasswordAuthentication yes
|
||||
PubkeyAuthentication yes
|
||||
BatchMode no
|
||||
ProxyCommand ${pkgs.netbird}/bin/netbird ssh proxy %h %p
|
||||
StrictHostKeyChecking no
|
||||
UserKnownHostsFile /dev/null
|
||||
CheckHostIP no
|
||||
LogLevel ERROR
|
||||
'';
|
||||
|
||||
networking.firewall.checkReversePath = "loose";
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
# AZ-PLT-1 pgbouncer (AZ-NIX-aso), Muster wie AZ-CLD-1/services/pgbouncer.nix —
|
||||
# bewusst schlank: nur der TX-Pool fuer die zwei PLT-1-DBs (Session-Pool-DBs
|
||||
# wie outline/zammad bleiben bis AZ-NIX-42r auf CLD-1). Listen nur auf
|
||||
# Loopback, da PLT-1 (noch) keine Podman-Bridge hat — hostBridgeIP nachziehen,
|
||||
# sobald Container (ES 8, ERPNext) kommen.
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
txPort = config.m3ta.ports.get "pgbouncer-tx";
|
||||
pgPort = config.m3ta.ports.get "postgres";
|
||||
|
||||
# pgbouncer (1.24+ als auch 1.25.2) laedt bei JEDEM TLS-Setup eine CA — auch
|
||||
# bei sslmode=prefer/require ohne Verifikation. Ohne explizite Datei faellt
|
||||
# es auf die OpenSSL-Default-Verify-Paths zurueck, die hier fehlschlagen:
|
||||
# "TLS setup failed: failed to load CA: (null)" -> Startabbruch.
|
||||
# (Erkenntnis aus AZ-CLD-1, verifiziert 2026-08-20 gegen 1.24.1 + 1.25.2.)
|
||||
caBundle = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";
|
||||
|
||||
mkDatabases = dbs:
|
||||
lib.listToAttrs (map (db:
|
||||
lib.nameValuePair db "host=127.0.0.1 port=${toString pgPort} dbname=${db}")
|
||||
dbs);
|
||||
in {
|
||||
services.pgbouncer = {
|
||||
enable = true;
|
||||
settings = {
|
||||
pgbouncer = {
|
||||
listen_addr = "127.0.0.1";
|
||||
listen_port = txPort;
|
||||
pool_mode = "transaction";
|
||||
|
||||
auth_type = "scram-sha-256";
|
||||
auth_file = config.age.secrets.pgbouncer-userlist.path;
|
||||
|
||||
admin_users = "sascha_koenig";
|
||||
stats_users = "sascha_koenig";
|
||||
|
||||
max_client_conn = 300;
|
||||
default_pool_size = 10;
|
||||
min_pool_size = 2;
|
||||
reserve_pool_size = 3;
|
||||
reserve_pool_timeout = 3;
|
||||
max_prepared_statements = 200;
|
||||
|
||||
client_tls_sslmode = "prefer";
|
||||
client_tls_cert_file = config.age.secrets.pgbouncer-tls-cert.path;
|
||||
client_tls_key_file = config.age.secrets.pgbouncer-tls-key.path;
|
||||
client_tls_protocols = "secure";
|
||||
client_tls_ca_file = caBundle;
|
||||
|
||||
log_connections = 1;
|
||||
log_disconnections = 1;
|
||||
server_reset_query = "DISCARD ALL";
|
||||
server_check_query = "SELECT 1";
|
||||
server_check_delay = 30;
|
||||
|
||||
server_tls_sslmode = "prefer";
|
||||
server_tls_protocols = "secure";
|
||||
server_tls_ca_file = caBundle;
|
||||
};
|
||||
databases = mkDatabases [
|
||||
"metabase"
|
||||
"az_kpi_raw"
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
systemd.services.pgbouncer = {
|
||||
after = ["postgresql.service"];
|
||||
requires = ["postgresql.service"];
|
||||
};
|
||||
|
||||
# Kein Firewall-Eintrag noetig: pgbouncer lauscht nur auf 127.0.0.1.
|
||||
# Kestra (PRM-1) verbindet direkt auf 5432, siehe ./postgres.nix.
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
# AZ-PLT-1 Postgres (AZ-NIX-aso): Zielinstanz fuer Metabase + az_kpi_raw.
|
||||
# Muster wie AZ-CLD-1/services/postgres.nix (Postgres 17 + pgvector + SSL).
|
||||
# Rollen/DBs bewusst minimal — der Rest der CLD-1-DBs bleibt dort bis AZ-NIX-42r.
|
||||
{
|
||||
config,
|
||||
pkgs,
|
||||
...
|
||||
}: {
|
||||
services.postgresql = {
|
||||
enable = true;
|
||||
enableTCPIP = true;
|
||||
package = pkgs.postgresql_17;
|
||||
settings = {
|
||||
ssl = true;
|
||||
ssl_cert_file = config.age.secrets.pg-cert.path;
|
||||
ssl_key_file = config.age.secrets.pg-key.path;
|
||||
max_connections = 60;
|
||||
shared_buffers = "4GB";
|
||||
work_mem = "8MB";
|
||||
superuser_reserved_connections = 5;
|
||||
idle_in_transaction_session_timeout = "10min";
|
||||
idle_session_timeout = "2h";
|
||||
tcp_keepalives_idle = 60;
|
||||
tcp_keepalives_interval = 10;
|
||||
tcp_keepalives_count = 6;
|
||||
deadlock_timeout = "1s";
|
||||
authentication_timeout = "30s";
|
||||
log_connections = true;
|
||||
log_disconnections = true;
|
||||
log_lock_waits = true;
|
||||
};
|
||||
extensions = with pkgs.postgresql17Packages; [
|
||||
pgvector
|
||||
];
|
||||
# Cutover (AZ-NIX-aso): Passwoerter hier sind Initialwerte; beim Umzug per
|
||||
# ALTER USER auf die Werte aus den bestehenden Secrets setzen (metabase-env,
|
||||
# kestra auf PRM-1) — dann aendert sich fuer keine App ein Credential.
|
||||
# az_kpi_raw wird per pg_dump (CLD-1) | pg_restore --clean --if-exists hierher
|
||||
# eingespielt; die GRANTs fuer kestra_prm kommen aus dem Dump mit.
|
||||
initialScript = pkgs.writeText "plt1-initScript" ''
|
||||
CREATE USER metabase WITH ENCRYPTED PASSWORD 'metabase';
|
||||
CREATE DATABASE metabase;
|
||||
ALTER DATABASE metabase OWNER to metabase;
|
||||
ALTER DATABASE metabase CONNECTION LIMIT 15;
|
||||
|
||||
CREATE USER kestra_prm WITH ENCRYPTED PASSWORD 'kestra_prm';
|
||||
CREATE DATABASE az_kpi_raw OWNER metabase;
|
||||
'';
|
||||
authentication = pkgs.lib.mkOverride 10 ''
|
||||
# Local connections (Unix socket)
|
||||
local all postgres peer
|
||||
local metabase,az_kpi_raw metabase scram-sha-256
|
||||
|
||||
# Localhost connections (Metabase laeuft auf demselben Host)
|
||||
host metabase,az_kpi_raw metabase 127.0.0.1/32 scram-sha-256
|
||||
host metabase,az_kpi_raw metabase ::1/128 scram-sha-256
|
||||
|
||||
# PRM-1-Kestra schreibt az_kpi_raw (NetBird, siehe firewall unten)
|
||||
host az_kpi_raw kestra_prm 100.91.49.26/32 scram-sha-256
|
||||
|
||||
# Deny all other connections
|
||||
local all all reject
|
||||
host all all 0.0.0.0/0 reject
|
||||
host all all ::/0 reject
|
||||
'';
|
||||
};
|
||||
|
||||
services.postgresqlBackup = {
|
||||
enable = true;
|
||||
startAt = "03:10:00";
|
||||
databases = ["az_kpi_raw" "metabase"];
|
||||
# Verschiffen Richtung NFS-/var/storage geschieht mit AZ-NIX-7t2 (Retention).
|
||||
};
|
||||
|
||||
# Erste gezielte Oeffnung der default-deny-Firewall (Traffic-Matrix):
|
||||
# Postgres nur von PRM-1 (Kestra) ueber NetBird — Muster wie AZ-CLD-1.
|
||||
networking.firewall.extraCommands = ''
|
||||
iptables -A INPUT -p tcp -s 100.91.49.26/32 --dport 5432 -j ACCEPT
|
||||
'';
|
||||
}
|
||||
Reference in New Issue
Block a user