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
135 lines
4.3 KiB
Nix
135 lines
4.3 KiB
Nix
# Forgejo at git.asxp.io (git.czsk.it is an alias), with its package
|
|
# registry and Actions. It runs as user git, so git@git.asxp.io reaches
|
|
# it through the host's sshd with no passthrough.
|
|
#
|
|
# State: /var/lib/forgejo (repositories/, data/forgejo.db, data/lfs, ...).
|
|
{
|
|
config,
|
|
lib,
|
|
pkgs,
|
|
...
|
|
}:
|
|
let
|
|
cfg = config.services.forgejo;
|
|
secret = name: config.sops.secrets."forgejo/${name}".path;
|
|
in
|
|
{
|
|
sops.secrets = lib.genAttrs (map (n: "forgejo/${n}") [
|
|
"secret_key"
|
|
"internal_token"
|
|
"jwt_secret"
|
|
"lfs_jwt_secret"
|
|
"smtp_user"
|
|
"smtp_password"
|
|
"metrics_token"
|
|
]) (_: { owner = cfg.user; });
|
|
|
|
users.users.git = {
|
|
isSystemUser = true;
|
|
group = "git";
|
|
home = cfg.stateDir;
|
|
useDefaultShell = true;
|
|
};
|
|
users.groups.git = { };
|
|
# Anyone may try a key against git; Forgejo decides what it may do
|
|
services.openssh.settings.AllowUsers = [ "git" ];
|
|
asxpio.security.loginUsers = [ "git" ];
|
|
# HTTP for Traefik and, over the private network, for the runners
|
|
asxpio.security.ports = [ "tcp/3000/.forgejo-wrappe" ];
|
|
asxpio.security.forgejoDb = "${cfg.stateDir}/data/forgejo.db";
|
|
|
|
services.forgejo = {
|
|
enable = true;
|
|
package = pkgs.forgejo; # the current release, not the LTS: the data is from 17
|
|
user = "git";
|
|
group = "git";
|
|
database.type = "sqlite3";
|
|
lfs.enable = true;
|
|
|
|
secrets = {
|
|
security.SECRET_KEY = lib.mkForce (secret "secret_key");
|
|
security.INTERNAL_TOKEN = lib.mkForce (secret "internal_token");
|
|
oauth2.JWT_SECRET = lib.mkForce (secret "jwt_secret");
|
|
server.LFS_JWT_SECRET = lib.mkForce (secret "lfs_jwt_secret");
|
|
mailer.USER = secret "smtp_user";
|
|
mailer.PASSWD = secret "smtp_password";
|
|
metrics.TOKEN = secret "metrics_token";
|
|
};
|
|
|
|
settings = {
|
|
DEFAULT.APP_NAME = "Git with a cup of tea";
|
|
server = {
|
|
DOMAIN = "git.asxp.io";
|
|
ROOT_URL = "https://git.asxp.io/";
|
|
HTTP_PORT = 3000;
|
|
SSH_DOMAIN = "git.asxp.io";
|
|
SSH_PORT = 22;
|
|
LANDING_PAGE = "explore";
|
|
};
|
|
repository = {
|
|
DEFAULT_BRANCH = "main";
|
|
DEFAULT_PRIVATE = "private";
|
|
ENABLE_PUSH_CREATE_USER = true;
|
|
ENABLE_PUSH_CREATE_ORG = false;
|
|
DEFAULT_REPO_UNITS = "repo.code,repo.releases,repo.issues,repo.pulls,repo.wiki,repo.projects,repo.packages,repo.actions";
|
|
};
|
|
"repository.pull-request".DEFAULT_MERGE_STYLE = "merge";
|
|
"repository.signing".DEFAULT_TRUST_MODEL = "collaborator";
|
|
ui = {
|
|
THEMES = "forgejo-auto,forgejo-light,forgejo-dark,gitea-auto,gitea-light,gitea-dark";
|
|
DEFAULT_THEME = "forgejo-auto";
|
|
};
|
|
security.PASSWORD_HASH_ALGO = "pbkdf2";
|
|
service = {
|
|
DISABLE_REGISTRATION = true;
|
|
REQUIRE_SIGNIN_VIEW = false;
|
|
REGISTER_EMAIL_CONFIRM = false;
|
|
ENABLE_NOTIFY_MAIL = true;
|
|
DEFAULT_KEEP_EMAIL_PRIVATE = true;
|
|
DEFAULT_ALLOW_CREATE_ORGANIZATION = true;
|
|
DEFAULT_ENABLE_TIMETRACKING = true;
|
|
NO_REPLY_ADDRESS = "noreply.git.asxp.io";
|
|
};
|
|
oauth2.ENABLED = true;
|
|
mailer = {
|
|
ENABLED = lib.mkDefault true;
|
|
FROM = "Czechoslovakia Git <noreply@asxp.io>";
|
|
PROTOCOL = "smtp+starttls";
|
|
SMTP_ADDR = "smtp.fastmail.com";
|
|
SMTP_PORT = 587;
|
|
};
|
|
session.PROVIDER = "file";
|
|
log.LEVEL = "Info";
|
|
actions = {
|
|
ENABLED = true;
|
|
DEFAULT_ACTIONS_URL = "https://github.com";
|
|
ARTIFACT_RETENTION_DAYS = 365;
|
|
};
|
|
packages.ENABLED = true;
|
|
other = {
|
|
SHOW_FOOTER_VERSION = false;
|
|
SHOW_FOOTER_TEMPLATE_LOAD_TIME = false;
|
|
SHOW_FOOTER_POWERED_BY = false;
|
|
};
|
|
metrics.ENABLED = true;
|
|
};
|
|
};
|
|
asxpio.waitForData = [
|
|
"forgejo"
|
|
"forgejo-secrets"
|
|
];
|
|
|
|
# `forgejo-admin regenerate keys`, `forgejo-admin user list`, ...
|
|
environment.systemPackages = [
|
|
(pkgs.writeShellScriptBin "forgejo-admin" ''
|
|
exec ${pkgs.util-linux}/bin/runuser -u ${cfg.user} -- env \
|
|
HOME=${cfg.stateDir} FORGEJO_WORK_DIR=${cfg.stateDir} FORGEJO_CUSTOM=${cfg.customDir} \
|
|
${lib.getExe cfg.package} --config ${cfg.customDir}/conf/app.ini admin "$@"
|
|
'')
|
|
];
|
|
|
|
asxpio.backup.paths = [ "/var/lib/forgejo" ];
|
|
asxpio.backup.hooks = [
|
|
''sqlite3 /var/lib/forgejo/data/forgejo.db ".backup '$STAGE/forgejo.db'"''
|
|
];
|
|
}
|