1
0
Fork 0

avoid some impossible states in authelia and nginx

This commit is contained in:
Pierre Penninckx 2023-11-30 22:49:34 -08:00 committed by GitHub
parent 76e27ae7eb
commit 0014e5c2f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 87 additions and 13 deletions

View file

@ -108,6 +108,7 @@
mergeTests (importFiles [ mergeTests (importFiles [
./test/modules/arr.nix ./test/modules/arr.nix
./test/modules/davfs.nix ./test/modules/davfs.nix
./test/modules/nginx.nix
./test/modules/postgresql.nix ./test/modules/postgresql.nix
]); ]);
}; };

View file

@ -36,17 +36,9 @@ in
}; };
autheliaUser = lib.mkOption { autheliaUser = lib.mkOption {
type = lib.types.nullOr lib.types.str; type = lib.types.str;
description = ''System user for this Authelia instance. description = "System user for this Authelia instance.";
default = "authelia";
If set to null, defaults to:
<programlisting language="nix">
"authelia_" +
(builtins.replaceStrings ["-" "."] ["_" "_"]
''${shb.authelia.subdomain}.''${shb.authelia.domain}")
</programlisting>
'';
default = null;
}; };
secrets = lib.mkOption { secrets = lib.mkOption {
@ -120,7 +112,7 @@ If set to null, defaults to:
services.authelia.instances.${fqdn} = { services.authelia.instances.${fqdn} = {
enable = true; enable = true;
user = cfg.autheliaUser or "authelia_" + builtins.replaceStrings ["-" "."] ["_" "_"] fqdn; user = cfg.autheliaUser;
secrets = { secrets = {
inherit (cfg.secrets) jwtSecretFile storageEncryptionKeyFile; inherit (cfg.secrets) jwtSecretFile storageEncryptionKeyFile;

View file

@ -20,7 +20,7 @@ let
}; };
authEndpoint = lib.mkOption { authEndpoint = lib.mkOption {
type = lib.types.nullOr lib.types.str; type = lib.types.str;
description = "Auth endpoint for SSO."; description = "Auth endpoint for SSO.";
default = null; default = null;
example = "https://authelia.example.com"; example = "https://authelia.example.com";

81
test/modules/nginx.nix Normal file
View file

@ -0,0 +1,81 @@
{ pkgs, lib, ... }:
let
anyOpt = default: lib.mkOption {
type = lib.types.anything;
inherit default;
};
testConfig = m:
let
cfg = (lib.evalModules {
specialArgs = { inherit pkgs; };
modules = [
{
options = {
assertions = anyOpt [];
networking = anyOpt {};
security = anyOpt {};
services = anyOpt {};
shb.authelia = anyOpt {};
shb.backup = anyOpt {};
shb.ssl = anyOpt {};
};
}
../../modules/blocks/nginx.nix
m
];
}).config;
in lib.attrsets.filterAttrsRecursive (n: v: n != "extraConfig") {
inherit (cfg) services;
shb = { inherit (cfg.shb) backup nginx; };
};
in
{
testNoOptions = {
expected = {
shb.backup = {};
shb.nginx = {
accessLog = false;
autheliaProtect = [];
debugLog = false;
};
services.nginx.enable = true;
};
expr = testConfig {};
};
testAuth = {
expected = {
shb.backup = {};
shb.nginx = {
accessLog = false;
autheliaProtect = [{
authEndpoint = "hello";
autheliaRules = [{}];
subdomain = "my";
domain = "example.com";
upstream = "http://127.0.0.1:1234";
}];
debugLog = false;
};
services.nginx.enable = true;
services.nginx.virtualHosts."my.example.com" = {
forceSSL = true;
locations."/" = {};
locations."/authelia" = {};
sslCertificate = "/var/lib/acme/example.com/cert.pem";
sslCertificateKey = "/var/lib/acme/example.com/key.pem";
};
};
expr = testConfig {
shb.ssl.enable = true;
shb.nginx.autheliaProtect = [{
subdomain = "my";
domain = "example.com";
upstream = "http://127.0.0.1:1234";
authEndpoint = "hello";
autheliaRules = [{}];
}];
};
};
}