mirror of https://gitlab.crans.org/nounous/nixos
Anubis subrequest
parent
19f40c1c4c
commit
bf059ed261
|
|
@ -1,12 +1,9 @@
|
||||||
{
|
{
|
||||||
config,
|
config,
|
||||||
lib,
|
lib,
|
||||||
pkgs,
|
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
formatJSON = pkgs.formats.json { };
|
|
||||||
|
|
||||||
inherit (lib)
|
inherit (lib)
|
||||||
types
|
types
|
||||||
mkEnableOption
|
mkEnableOption
|
||||||
|
|
@ -37,13 +34,6 @@ in
|
||||||
Where Anubis should listen
|
Where Anubis should listen
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
target = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
example = "unix:///run/nginx/socket.sock";
|
|
||||||
description = ''
|
|
||||||
Target that will handle the request.
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
bots = mkOption {
|
bots = mkOption {
|
||||||
type = types.listOf types.attrs;
|
type = types.listOf types.attrs;
|
||||||
description = ''
|
description = ''
|
||||||
|
|
@ -67,6 +57,12 @@ in
|
||||||
instances = lib.mapAttrs (name: conf: {
|
instances = lib.mapAttrs (name: conf: {
|
||||||
enable = true;
|
enable = true;
|
||||||
policy = {
|
policy = {
|
||||||
|
settings = {
|
||||||
|
statusCodes = {
|
||||||
|
CHALLENGE = 200;
|
||||||
|
DENY = 403;
|
||||||
|
};
|
||||||
|
};
|
||||||
extraBots = [
|
extraBots = [
|
||||||
{
|
{
|
||||||
name = "whitelist-crans";
|
name = "whitelist-crans";
|
||||||
|
|
@ -96,7 +92,7 @@ in
|
||||||
BIND = conf.bind;
|
BIND = conf.bind;
|
||||||
BIND_NETWORK = "unix";
|
BIND_NETWORK = "unix";
|
||||||
METRIC_BIND = "/run/anubis/anubis-${name}/metrics.sock";
|
METRIC_BIND = "/run/anubis/anubis-${name}/metrics.sock";
|
||||||
TARGET = conf.target;
|
TARGET = " "; # Subrequest authentification.
|
||||||
COOKIE_DOMAIN = conf.hostname;
|
COOKIE_DOMAIN = conf.hostname;
|
||||||
# TODO: db pour mettre en commun les token.
|
# TODO: db pour mettre en commun les token.
|
||||||
# Transitoirement on les sépare
|
# Transitoirement on les sépare
|
||||||
|
|
|
||||||
|
|
@ -157,7 +157,6 @@ in
|
||||||
instances = lib.mapAttrs (vhostName: vhostConfig: {
|
instances = lib.mapAttrs (vhostName: vhostConfig: {
|
||||||
hostname = mkHostName vhostName mainTld;
|
hostname = mkHostName vhostName mainTld;
|
||||||
bind = "/run/anubis/anubis-${vhostName}/socket.sock";
|
bind = "/run/anubis/anubis-${vhostName}/socket.sock";
|
||||||
target = "unix:/run/nginx/nginx-${vhostName}.sock";
|
|
||||||
bots = vhostConfig.anubisConfig;
|
bots = vhostConfig.anubisConfig;
|
||||||
}) (lib.filterAttrs (_: c: c.anubisConfig != null) cfg.virtualHosts);
|
}) (lib.filterAttrs (_: c: c.anubisConfig != null) cfg.virtualHosts);
|
||||||
};
|
};
|
||||||
|
|
@ -203,32 +202,6 @@ in
|
||||||
acmeRoot = null;
|
acmeRoot = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
# Conf pour l’hôte en entrée
|
|
||||||
entryExtraConf = {
|
|
||||||
extraConfig = ''
|
|
||||||
set_real_ip_from 172.16.0.0/16;
|
|
||||||
set_real_ip_from fd00::/56;
|
|
||||||
real_ip_header X-Real-Ip;
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
// sslConf;
|
|
||||||
# Conf supplémentaire pour le proxy principal
|
|
||||||
vhostExtraConf =
|
|
||||||
if vhostConfig.anubisConfig != null then
|
|
||||||
# Il reçoit les requêtes d’Anubis
|
|
||||||
{
|
|
||||||
listen = [
|
|
||||||
{ addr = "unix:/run/nginx/nginx-${vhostName}.sock"; }
|
|
||||||
];
|
|
||||||
extraConfig = ''
|
|
||||||
set_real_ip_from unix:;
|
|
||||||
real_ip_header X-Real-IP;
|
|
||||||
'';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
# Il est en entrée
|
|
||||||
entryExtraConf;
|
|
||||||
|
|
||||||
logHostConf = ''
|
logHostConf = ''
|
||||||
access_log /var/log/nginx/host/${vhostName}/access.log;
|
access_log /var/log/nginx/host/${vhostName}/access.log;
|
||||||
error_log /var/log/nginx/host/${vhostName}/error.log;
|
error_log /var/log/nginx/host/${vhostName}/error.log;
|
||||||
|
|
@ -249,37 +222,52 @@ in
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# Configuration du service à proxy.
|
# Configuration du service à proxy.
|
||||||
"${vhostName}" = vhostExtraConf // {
|
"${vhostName}" = sslConf // {
|
||||||
serverName = hostname;
|
serverName = hostname;
|
||||||
locations."/" = mkIf (vhostConfig.proxyPass != null) {
|
|
||||||
proxyPass = "http://${vhostConfig.proxyPass}";
|
# Site statiques et alias
|
||||||
proxyWebsockets = vhostConfig.proxyWebsockets;
|
|
||||||
};
|
|
||||||
root = vhostConfig.serveLocalFiles;
|
root = vhostConfig.serveLocalFiles;
|
||||||
globalRedirect = vhostConfig.globalRedirect;
|
globalRedirect = vhostConfig.globalRedirect;
|
||||||
extraConfig = vhostExtraConf.extraConfig + logHostConf;
|
locations = {
|
||||||
};
|
# Entrée site, via proxy
|
||||||
|
"/" = mkIf (vhostConfig.proxyPass != null) {
|
||||||
# Entrée d’Anubis
|
proxyPass = "http://${vhostConfig.proxyPass}";
|
||||||
"${vhostName}-anubis" = mkIf (vhostConfig.anubisConfig != null) (
|
|
||||||
entryExtraConf
|
|
||||||
// rec {
|
|
||||||
serverName = hostname;
|
|
||||||
locations."/" = {
|
|
||||||
proxyPass = "http://unix:/run/anubis/anubis-${vhostName}/socket.sock";
|
|
||||||
proxyWebsockets = vhostConfig.proxyWebsockets;
|
proxyWebsockets = vhostConfig.proxyWebsockets;
|
||||||
};
|
extraConfig = lib.optionalString (vhostConfig.anubisConfig != null) ''
|
||||||
locations."/.within.website/x/cmd/anubis/api/honeypot/" = locations."/" // {
|
auth_request /.within.website/x/cmd/anubis/api/check;
|
||||||
extraConfig = ''
|
error_page 401 = @redirectToAnubis;
|
||||||
add_header 'X-Robots-Tag' 'noindex,nofollow' always;
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
extraConfig = entryExtraConf.extraConfig + ''
|
# Anubis
|
||||||
access_log /var/log/nginx/anubis/access.log;
|
"/.within.website/" = mkIf (vhostConfig.anubisConfig != null) {
|
||||||
error_log /var/log/nginx/anubis/error.log;
|
# https://anubis.techaro.lol/docs/admin/configuration/subrequest-auth/
|
||||||
'';
|
proxyPass = "http://unix:/run/anubis/anubis-${vhostName}/socket.sock";
|
||||||
}
|
extraConfig = ''
|
||||||
);
|
proxy_pass_request_body off;
|
||||||
|
proxy_set_header content-length "";
|
||||||
|
add_header 'X-Robots-Tag' 'noindex,nofollow' always;
|
||||||
|
auth_request off;
|
||||||
|
access_log /var/log/nginx/anubis/access.log;
|
||||||
|
error_log /var/log/nginx/anubis/error.log;
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
"@redirectToAnubis" = mkIf (vhostConfig.anubisConfig != null) {
|
||||||
|
extraConfig = ''
|
||||||
|
return 307 /.within.website/?redir=$scheme://$host$request_uri;
|
||||||
|
auth_request off;
|
||||||
|
access_log /var/log/nginx/anubis/access.log;
|
||||||
|
error_log /var/log/nginx/anubis/error.log;
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
extraConfig = ''
|
||||||
|
set_real_ip_from 172.16.0.0/16;
|
||||||
|
set_real_ip_from fd00::/56;
|
||||||
|
real_ip_header X-Real-Ip;
|
||||||
|
''
|
||||||
|
+ logHostConf;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
# Les alias
|
# Les alias
|
||||||
// lib.mergeAttrsList (
|
// lib.mergeAttrsList (
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue