mirror of https://gitlab.crans.org/nounous/nixos
anubis : modularisation
parent
a4ae2ea552
commit
19f40c1c4c
|
|
@ -5,162 +5,79 @@
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
formatJSON = pkgs.formats.json { };
|
|
||||||
formatYAML = pkgs.formats.yaml { };
|
|
||||||
|
|
||||||
inherit (lib.crans) fetchFromCrans;
|
inherit (lib.crans) fetchFromCrans;
|
||||||
|
|
||||||
antiBot = formatYAML.generate "antibot.yaml" [
|
anubisChallenge = [
|
||||||
{
|
{
|
||||||
name = "whitelist-crans";
|
name = "challenge-other";
|
||||||
action = "ALLOW";
|
path_regex = "^*";
|
||||||
remote_addresses = [
|
action = "CHALLENGE";
|
||||||
"185.230.79.0/22"
|
|
||||||
"2a0c:700::/32"
|
|
||||||
"46.105.102.188/32"
|
|
||||||
"2001:41d0:2:d5bc::/128"
|
|
||||||
];
|
|
||||||
}
|
|
||||||
{
|
|
||||||
# On refuse les bots qui font souvent de la merde.
|
|
||||||
# https://github.com/TecharoHQ/anubis/blob/main/data/bots/_deny-pathological.yaml
|
|
||||||
import = "(data)/bots/_deny-pathological.yaml";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
# allow google-inspection pour indexer les pages
|
|
||||||
name = "google-inspection-tool";
|
|
||||||
action = "ALLOW";
|
|
||||||
user_agent_regex = ".*Google-InspectionTool.*";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
# On autorise les indexers des moteurs de recherche.
|
|
||||||
# https://github.com/TecharoHQ/anubis/blob/main/data/crawlers/_allow-good.yaml
|
|
||||||
import = "(data)/crawlers/_allow-good.yaml";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
# On autorise l'accès à favicon, robots.txt, well-known, ...
|
|
||||||
# https://github.com/TecharoHQ/anubis/blob/main/data/common/keep-internet-working.yaml
|
|
||||||
import = "(data)/common/keep-internet-working.yaml";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
# On refuse si userAgent = ""
|
|
||||||
# https://github.com/TecharoHQ/anubis/blob/main/data/common/rfc-violations.yaml
|
|
||||||
import = "(data)/common/rfc-violations.yaml";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
# On bloque les AI aggressivement (bots/agent, training et user search par IA)
|
|
||||||
# https://github.com/TecharoHQ/anubis/blob/main/data/meta/ai-block-aggressive.yaml
|
|
||||||
import = "(data)/meta/ai-block-aggressive.yaml";
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
anubisChallenge = formatJSON.generate "anubis_challenge.json" {
|
anubisPerso = [
|
||||||
"bots" = [
|
{
|
||||||
{
|
name = "allow-public";
|
||||||
import = "${antiBot}";
|
path_regex = "^/[a-zA-Z0-9_-]*/public/.*";
|
||||||
}
|
action = "ALLOW";
|
||||||
{
|
}
|
||||||
name = "challenge-other";
|
{
|
||||||
path_regex = "^*";
|
name = "allow-phpmyadmin";
|
||||||
action = "CHALLENGE";
|
path_regex = "^/phpmyadmin/.*";
|
||||||
}
|
action = "ALLOW";
|
||||||
];
|
}
|
||||||
};
|
{
|
||||||
|
# geneau utilisait ses pages persos avant la mise en place d'Anubis.
|
||||||
|
# Le déploiement d'Anubis l'a impacté (cf les mails de fin 2025).
|
||||||
|
# À titre transitoire, il a été décidé en décembre 2025 de faire une
|
||||||
|
# exception pour lui permettre de continuer son utilisation des pages
|
||||||
|
# persos en attente d'une meilleure méthode.
|
||||||
|
name = "allow-geneau";
|
||||||
|
path_regex = "^/geneau/.*";
|
||||||
|
action = "ALLOW";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
name = "challenge-other";
|
||||||
|
path_regex = "^.*";
|
||||||
|
action = "CHALLENGE";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
anubisAllowOther = formatJSON.generate "anubis_allow.json" {
|
anubisMirrors = [
|
||||||
"bots" = [
|
{
|
||||||
{
|
name = "deny-other";
|
||||||
import = "${antiBot}";
|
path_regex = ".*cdimage-.*";
|
||||||
}
|
action = "ALLOW";
|
||||||
{
|
}
|
||||||
name = "allow-other";
|
{
|
||||||
path_regex = "^*";
|
name = "allow-repo";
|
||||||
action = "ALLOW";
|
path_regex = "^...*";
|
||||||
}
|
action = "ALLOW";
|
||||||
];
|
}
|
||||||
};
|
{
|
||||||
|
name = "deny-other";
|
||||||
|
path_regex = ".*";
|
||||||
|
action = "CHALLENGE";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
anubisPerso = formatJSON.generate "anubis_perso.json" {
|
anubisWiki = [
|
||||||
"bots" = [
|
{
|
||||||
{
|
name = "allow-mediawiki-images";
|
||||||
import = "${antiBot}";
|
path_regex = "^/w/images/.*";
|
||||||
}
|
action = "ALLOW";
|
||||||
{
|
}
|
||||||
name = "allow-public";
|
{
|
||||||
path_regex = "^/[a-zA-Z0-9_-]*/public/.*";
|
name = "allow-mediawiki-api";
|
||||||
action = "ALLOW";
|
path_regex = "^/w/api.php.*";
|
||||||
}
|
action = "ALLOW";
|
||||||
{
|
}
|
||||||
name = "allow-phpmyadmin";
|
{
|
||||||
path_regex = "^/phpmyadmin/.*";
|
name = "challenge-other";
|
||||||
action = "ALLOW";
|
path_regex = ".*";
|
||||||
}
|
action = "CHALLENGE";
|
||||||
{
|
}
|
||||||
# geneau utilisait ses pages persos avant la mise en place d'Anubis.
|
];
|
||||||
# Le déploiement d'Anubis l'a impacté (cf les mails de fin 2025).
|
|
||||||
# À titre transitoire, il a été décidé en décembre 2025 de faire une
|
|
||||||
# exception pour lui permettre de continuer son utilisation des pages
|
|
||||||
# persos en attente d'une meilleure méthode.
|
|
||||||
name = "allow-geneau";
|
|
||||||
path_regex = "^/geneau/.*";
|
|
||||||
action = "ALLOW";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
import = "${antiBot}";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
name = "challenge-other";
|
|
||||||
path_regex = "^.*";
|
|
||||||
action = "CHALLENGE";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
anubisMirrors = formatJSON.generate "anubis_mirrors.json" {
|
|
||||||
"bots" = [
|
|
||||||
{
|
|
||||||
import = "${antiBot}";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
name = "deny-other";
|
|
||||||
path_regex = ".*cdimage-.*";
|
|
||||||
action = "ALLOW";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
name = "allow-repo";
|
|
||||||
path_regex = "^...*";
|
|
||||||
action = "ALLOW";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
name = "deny-other";
|
|
||||||
path_regex = ".*";
|
|
||||||
action = "CHALLENGE";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
anubisWiki = formatJSON.generate "anubis_wiki.json" {
|
|
||||||
"bots" = [
|
|
||||||
{
|
|
||||||
import = "${antiBot}";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
name = "allow-mediawiki-images";
|
|
||||||
path_regex = "^/w/images/.*";
|
|
||||||
action = "ALLOW";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
name = "allow-mediawiki-api";
|
|
||||||
path_regex = "^/w/api.php.*";
|
|
||||||
action = "ALLOW";
|
|
||||||
}
|
|
||||||
{
|
|
||||||
name = "challenge-other";
|
|
||||||
path_regex = ".*";
|
|
||||||
action = "CHALLENGE";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
installPartySite = pkgs.python3Packages.buildPythonApplication {
|
installPartySite = pkgs.python3Packages.buildPythonApplication {
|
||||||
name = "site-install-party";
|
name = "site-install-party";
|
||||||
|
|
@ -212,12 +129,12 @@ in
|
||||||
proxyWebsockets = true;
|
proxyWebsockets = true;
|
||||||
};
|
};
|
||||||
"eclat" = {
|
"eclat" = {
|
||||||
anubisConfig = "${anubisMirrors}";
|
anubisConfig = anubisMirrors;
|
||||||
httpOnly = true;
|
httpOnly = true;
|
||||||
proxyPass = "172.16.10.104";
|
proxyPass = "172.16.10.104";
|
||||||
};
|
};
|
||||||
"eclats" = {
|
"eclats" = {
|
||||||
anubisConfig = "${anubisMirrors}";
|
anubisConfig = anubisMirrors;
|
||||||
proxyPass = "172.16.10.104";
|
proxyPass = "172.16.10.104";
|
||||||
};
|
};
|
||||||
"element".proxyPass = "172.16.10.118";
|
"element".proxyPass = "172.16.10.118";
|
||||||
|
|
@ -239,7 +156,7 @@ in
|
||||||
serverAliases = [ "re2o" ];
|
serverAliases = [ "re2o" ];
|
||||||
};
|
};
|
||||||
"install-party" = {
|
"install-party" = {
|
||||||
anubisConfig = "${anubisChallenge}";
|
anubisConfig = anubisChallenge;
|
||||||
serveLocalFiles = "${installPartySite}/site";
|
serveLocalFiles = "${installPartySite}/site";
|
||||||
serverAliases = [
|
serverAliases = [
|
||||||
"i-p"
|
"i-p"
|
||||||
|
|
@ -248,20 +165,20 @@ in
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
"lists" = {
|
"lists" = {
|
||||||
anubisConfig = "${anubisChallenge}";
|
anubisConfig = anubisChallenge;
|
||||||
proxyPass = "172.16.10.110";
|
proxyPass = "172.16.10.110";
|
||||||
};
|
};
|
||||||
"mediawiki" = {
|
"mediawiki" = {
|
||||||
anubisConfig = "${anubisWiki}";
|
anubisConfig = anubisWiki;
|
||||||
proxyPass = "172.16.10.144";
|
proxyPass = "172.16.10.144";
|
||||||
serverAliases = [ "mediakiwi" ];
|
serverAliases = [ "mediakiwi" ];
|
||||||
};
|
};
|
||||||
"mirrors" = {
|
"mirrors" = {
|
||||||
anubisConfig = "${anubisMirrors}";
|
anubisConfig = anubisMirrors;
|
||||||
proxyPass = "172.16.10.104";
|
proxyPass = "172.16.10.104";
|
||||||
};
|
};
|
||||||
"mirror" = {
|
"mirror" = {
|
||||||
anubisConfig = "${anubisMirrors}";
|
anubisConfig = anubisMirrors;
|
||||||
httpOnly = true;
|
httpOnly = true;
|
||||||
proxyPass = "172.16.10.104";
|
proxyPass = "172.16.10.104";
|
||||||
};
|
};
|
||||||
|
|
@ -278,7 +195,7 @@ in
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
"perso" = {
|
"perso" = {
|
||||||
anubisConfig = "${anubisPerso}";
|
anubisConfig = anubisPerso;
|
||||||
proxyPass = "172.16.10.31";
|
proxyPass = "172.16.10.31";
|
||||||
serverAliases = [ "clubs" ];
|
serverAliases = [ "clubs" ];
|
||||||
};
|
};
|
||||||
|
|
@ -302,7 +219,7 @@ in
|
||||||
serverAliases = [ "roundcube" ];
|
serverAliases = [ "roundcube" ];
|
||||||
};
|
};
|
||||||
"wiki" = {
|
"wiki" = {
|
||||||
anubisConfig = "${anubisChallenge}";
|
anubisConfig = anubisChallenge;
|
||||||
proxyPass = "172.16.10.161";
|
proxyPass = "172.16.10.161";
|
||||||
serverAliases = [ "wikipedia" ];
|
serverAliases = [ "wikipedia" ];
|
||||||
};
|
};
|
||||||
|
|
@ -337,5 +254,5 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,112 @@
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
let
|
||||||
|
formatJSON = pkgs.formats.json { };
|
||||||
|
|
||||||
|
inherit (lib)
|
||||||
|
types
|
||||||
|
mkEnableOption
|
||||||
|
mkIf
|
||||||
|
mkOption
|
||||||
|
;
|
||||||
|
|
||||||
|
cfg = config.crans.anubis;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.crans.anubis = {
|
||||||
|
enable = mkEnableOption "Configuration d’Anubis du Crans.";
|
||||||
|
instances = mkOption {
|
||||||
|
type = types.attrsOf (
|
||||||
|
types.submodule {
|
||||||
|
options = {
|
||||||
|
hostname = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
example = "wiki.crans.org";
|
||||||
|
description = ''
|
||||||
|
Hostname to redirect to.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
bind = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
example = "/run/anubis/anubis-wiki/socket.sock";
|
||||||
|
description = ''
|
||||||
|
Where Anubis should listen
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
target = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
example = "unix:///run/nginx/socket.sock";
|
||||||
|
description = ''
|
||||||
|
Target that will handle the request.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
bots = mkOption {
|
||||||
|
type = types.listOf types.attrs;
|
||||||
|
description = ''
|
||||||
|
Anubis bot policy.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
age.secrets.anubis-secret = mkIf cfg.enable {
|
||||||
|
file = ../../secrets/reverseproxy/anubis-secret.age;
|
||||||
|
owner = "anubis";
|
||||||
|
};
|
||||||
|
|
||||||
|
services.anubis = {
|
||||||
|
defaultOptions.group = "nginx";
|
||||||
|
instances = lib.mapAttrs (name: conf: {
|
||||||
|
enable = true;
|
||||||
|
policy = {
|
||||||
|
extraBots = [
|
||||||
|
{
|
||||||
|
name = "whitelist-crans";
|
||||||
|
action = "ALLOW";
|
||||||
|
remote_addresses = [
|
||||||
|
"185.230.79.0/22"
|
||||||
|
"2a0c:700::/32"
|
||||||
|
"46.105.102.188/32"
|
||||||
|
"2001:41d0:2:d5bc::/128"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
{
|
||||||
|
# https://github.com/TecharoHQ/anubis/blob/main/data/botPolicies.yaml
|
||||||
|
import = "(data)/meta/default-config.yaml";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
# On refuse si userAgent = ""
|
||||||
|
# https://github.com/TecharoHQ/anubis/blob/main/data/common/rfc-violations.yaml
|
||||||
|
import = "(data)/common/rfc-violations.yaml";
|
||||||
|
}
|
||||||
|
]
|
||||||
|
++ conf.bots;
|
||||||
|
# Inclus via l’import de default-config.yaml.
|
||||||
|
useDefaultBotRules = false;
|
||||||
|
};
|
||||||
|
settings = {
|
||||||
|
BIND = conf.bind;
|
||||||
|
BIND_NETWORK = "unix";
|
||||||
|
METRIC_BIND = "/run/anubis/anubis-${name}/metrics.sock";
|
||||||
|
TARGET = conf.target;
|
||||||
|
COOKIE_DOMAIN = conf.hostname;
|
||||||
|
# TODO: db pour mettre en commun les token.
|
||||||
|
# Transitoirement on les sépare
|
||||||
|
COOKIE_PREFIX = "anubis-${conf.hostname}";
|
||||||
|
REDIRECT_DOMAINS = conf.hostname;
|
||||||
|
SOCKET_MODE = "0660";
|
||||||
|
# Secret partagé entre les instances
|
||||||
|
ED25519_PRIVATE_KEY_HEX_FILE = config.age.secrets.anubis-secret.path;
|
||||||
|
};
|
||||||
|
}) cfg.instances;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
@ -14,6 +14,7 @@ in
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
./age.nix
|
./age.nix
|
||||||
|
./anubis.nix
|
||||||
./grub.nix
|
./grub.nix
|
||||||
./home.nix
|
./home.nix
|
||||||
./locale.nix
|
./locale.nix
|
||||||
|
|
|
||||||
|
|
@ -72,19 +72,10 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
anubisConfig = mkOption {
|
anubisConfig = mkOption {
|
||||||
type = types.nullOr types.str;
|
type = types.nullOr (types.listOf types.attrs);
|
||||||
default = null;
|
default = null;
|
||||||
description = ''
|
description = ''
|
||||||
Chemin du fichier de configuration
|
Configuration pour anubis
|
||||||
'';
|
|
||||||
example = "/var/www/anubis.conf";
|
|
||||||
};
|
|
||||||
|
|
||||||
anubisOpenGraph = mkOption {
|
|
||||||
type = types.bool;
|
|
||||||
default = true;
|
|
||||||
description = ''
|
|
||||||
Activer openGraph pour l'indexation et l'embedding
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -126,13 +117,13 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = mkIf cfg.enable {
|
||||||
systemd.services = lib.mapAttrs (vhostName: vhostConfig: {
|
systemd.services = lib.mapAttrs (vhostName: vhostConfig: {
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
}) cfg.virtualHosts;
|
}) cfg.virtualHosts;
|
||||||
|
|
||||||
# On fait un certificat commun pour tous les hosts
|
# On fait un certificat commun pour tous les hosts
|
||||||
security.acme.certs."all.crans.all" = mkIf cfg.enable {
|
security.acme.certs."all.crans.all" = {
|
||||||
domain = "*.crans.${mainTld}";
|
domain = "*.crans.${mainTld}";
|
||||||
dnsProvider = "rfc2136";
|
dnsProvider = "rfc2136";
|
||||||
# Contient le serveur à contacter avec le protocole
|
# Contient le serveur à contacter avec le protocole
|
||||||
|
|
@ -160,45 +151,18 @@ in
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
age.secrets.anubis-secret = mkIf cfg.enable {
|
# On active Anubis
|
||||||
file = ../../secrets/reverseproxy/anubis-secret.age;
|
crans.anubis = {
|
||||||
owner = "anubis";
|
enable = true;
|
||||||
|
instances = lib.mapAttrs (vhostName: vhostConfig: {
|
||||||
|
hostname = mkHostName vhostName mainTld;
|
||||||
|
bind = "/run/anubis/anubis-${vhostName}/socket.sock";
|
||||||
|
target = "unix:/run/nginx/nginx-${vhostName}.sock";
|
||||||
|
bots = vhostConfig.anubisConfig;
|
||||||
|
}) (lib.filterAttrs (_: c: c.anubisConfig != null) cfg.virtualHosts);
|
||||||
};
|
};
|
||||||
|
|
||||||
services = mkIf cfg.enable {
|
services = {
|
||||||
anubis = {
|
|
||||||
defaultOptions.group = "nginx";
|
|
||||||
instances = lib.mapAttrs (
|
|
||||||
vhostName: vhostConfig:
|
|
||||||
let
|
|
||||||
hostname = mkHostName vhostName mainTld;
|
|
||||||
in
|
|
||||||
mkIf (vhostConfig.anubisConfig != null) {
|
|
||||||
enable = true;
|
|
||||||
settings = {
|
|
||||||
BIND = "/run/anubis/anubis-${vhostName}/socket.sock";
|
|
||||||
BIND_NETWORK = "unix";
|
|
||||||
METRICS_BIND = "/run/anubis/anubis-${vhostName}/anubis-${vhostName}-metrics.sock";
|
|
||||||
TARGET = "unix:///run/nginx/nginx-${vhostName}.sock";
|
|
||||||
COOKIE_DOMAIN = hostname;
|
|
||||||
# TODO: db pour mettre en commun les token.
|
|
||||||
# Transitoirement on les sépare
|
|
||||||
COOKIE_PREFIX = "anubis-${vhostName}";
|
|
||||||
REDIRECT_DOMAINS = hostname;
|
|
||||||
SOCKET_MODE = "0660";
|
|
||||||
# Secret partagé entre les instances
|
|
||||||
ED25519_PRIVATE_KEY_HEX_FILE = config.age.secrets.anubis-secret.path;
|
|
||||||
# OpenGraph config
|
|
||||||
OG_PASSTHROUGH = vhostConfig.anubisOpenGraph;
|
|
||||||
OG_EXPIRY_TIME = "24h";
|
|
||||||
OG_CACHE_CONSIDER_HOST = true;
|
|
||||||
# Policy config
|
|
||||||
POLICY_FNAME = vhostConfig.anubisConfig;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
) cfg.virtualHosts;
|
|
||||||
};
|
|
||||||
|
|
||||||
logrotate.settings =
|
logrotate.settings =
|
||||||
let
|
let
|
||||||
# https://github.com/NixOS/nixpkgs/blob/nixos-26.05/nixos/modules/services/web-servers/nginx/default.nix
|
# https://github.com/NixOS/nixpkgs/blob/nixos-26.05/nixos/modules/services/web-servers/nginx/default.nix
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue