2023-12-11 06:56:31 +01:00
|
|
|
{ pkgs, lib, ... }:
|
|
|
|
let
|
2024-03-20 06:50:41 +01:00
|
|
|
pkgs' = pkgs;
|
|
|
|
|
2023-12-11 06:56:31 +01:00
|
|
|
ldapAdminPassword = "ldapAdminPassword";
|
|
|
|
in
|
|
|
|
{
|
2024-03-20 06:50:41 +01:00
|
|
|
basic = pkgs.testers.runNixOSTest {
|
2023-12-11 06:56:31 +01:00
|
|
|
name = "authelia-basic";
|
|
|
|
|
|
|
|
nodes.machine = { config, pkgs, ... }: {
|
|
|
|
imports = [
|
2024-03-20 06:50:41 +01:00
|
|
|
(pkgs'.path + "/nixos/modules/profiles/headless.nix")
|
|
|
|
(pkgs'.path + "/nixos/modules/profiles/qemu-guest.nix")
|
2023-12-11 06:56:31 +01:00
|
|
|
../../modules/blocks/authelia.nix
|
|
|
|
../../modules/blocks/ldap.nix
|
|
|
|
../../modules/blocks/postgresql.nix
|
|
|
|
];
|
|
|
|
|
2024-08-31 09:57:21 +02:00
|
|
|
networking.hosts = {
|
|
|
|
"127.0.0.1" = [
|
|
|
|
"machine.com"
|
|
|
|
"client1.machine.com"
|
|
|
|
"client2.machine.com"
|
|
|
|
"ldap.machine.com"
|
|
|
|
"authelia.machine.com"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
2023-12-11 06:56:31 +01:00
|
|
|
shb.ldap = {
|
|
|
|
enable = true;
|
|
|
|
dcdomain = "dc=example,dc=com";
|
|
|
|
subdomain = "ldap";
|
2024-08-31 09:57:21 +02:00
|
|
|
domain = "machine.com";
|
2023-12-11 06:56:31 +01:00
|
|
|
ldapUserPasswordFile = pkgs.writeText "user_password" ldapAdminPassword;
|
|
|
|
jwtSecretFile = pkgs.writeText "jwt_secret" "securejwtsecret";
|
|
|
|
};
|
|
|
|
|
|
|
|
shb.authelia = {
|
|
|
|
enable = true;
|
|
|
|
subdomain = "authelia";
|
2024-08-31 09:57:21 +02:00
|
|
|
domain = "machine.com";
|
2024-09-01 08:36:53 +02:00
|
|
|
ldapHostname = "${config.shb.ldap.subdomain}.${config.shb.ldap.domain}";
|
|
|
|
ldapPort = config.shb.ldap.ldapPort;
|
2023-12-11 06:56:31 +01:00
|
|
|
dcdomain = config.shb.ldap.dcdomain;
|
|
|
|
secrets = {
|
|
|
|
jwtSecretFile = pkgs.writeText "jwtSecretFile" "jwtSecretFile";
|
|
|
|
ldapAdminPasswordFile = pkgs.writeText "ldapAdminPasswordFile" ldapAdminPassword;
|
|
|
|
sessionSecretFile = pkgs.writeText "sessionSecretFile" "sessionSecretFile";
|
|
|
|
storageEncryptionKeyFile = pkgs.writeText "storageEncryptionKeyFile" "storageEncryptionKeyFile";
|
|
|
|
identityProvidersOIDCHMACSecretFile = pkgs.writeText "identityProvidersOIDCHMACSecretFile" "identityProvidersOIDCHMACSecretFile";
|
|
|
|
# This needs to be of the correct shape and at least 2048 bits. Generated with:
|
|
|
|
# nix run nixpkgs#openssl -- genrsa -out keypair.pem 2048
|
|
|
|
identityProvidersOIDCIssuerPrivateKeyFile = pkgs.writeText "identityProvidersOIDCIssuerPrivateKeyFile" (builtins.readFile ./keypair.pem);
|
|
|
|
};
|
|
|
|
|
|
|
|
oidcClients = [
|
|
|
|
{
|
2024-08-31 09:57:21 +02:00
|
|
|
client_id = "client1";
|
|
|
|
client_name = "My Client 1";
|
|
|
|
client_secret.source = pkgs.writeText "secret" "$pbkdf2-sha512$310000$LR2wY11djfLrVQixdlLJew$rPByqFt6JfbIIAITxzAXckwh51QgV8E5YZmA8rXOzkMfBUcMq7cnOKEXF6MAFbjZaGf3J/B1OzLWZTCuZtALVw";
|
2024-01-21 08:17:25 +01:00
|
|
|
public = false;
|
2023-12-11 06:56:31 +01:00
|
|
|
authorization_policy = "one_factor";
|
2024-08-31 09:57:21 +02:00
|
|
|
redirect_uris = [ "http://client1.machine.com/redirect" ];
|
2024-01-24 06:52:23 +01:00
|
|
|
}
|
|
|
|
{
|
2024-08-31 09:57:21 +02:00
|
|
|
client_id = "client2";
|
|
|
|
client_name = "My Client 2";
|
|
|
|
client_secret.source = pkgs.writeText "secret" "$pbkdf2-sha512$310000$76EqVU1N9K.iTOvD4WJ6ww$hqNJU.UHphiCjMChSqk27lUTjDqreuMuyV/u39Esc6HyiRXp5Ecx89ypJ5M0xk3Na97vbgDpwz7il5uwzQ4bfw";
|
2024-01-24 06:52:23 +01:00
|
|
|
public = false;
|
|
|
|
authorization_policy = "one_factor";
|
2024-08-31 09:57:21 +02:00
|
|
|
redirect_uris = [ "http://client2.machine.com/redirect" ];
|
2023-12-11 06:56:31 +01:00
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
testScript = { nodes, ... }: ''
|
2024-01-24 06:52:23 +01:00
|
|
|
import json
|
|
|
|
|
2023-12-11 06:56:31 +01:00
|
|
|
start_all()
|
|
|
|
machine.wait_for_unit("lldap.service")
|
2024-08-31 09:57:21 +02:00
|
|
|
machine.wait_for_unit("authelia-authelia.machine.com.service")
|
|
|
|
machine.wait_for_open_port(9091)
|
2024-01-24 06:52:23 +01:00
|
|
|
|
2024-08-31 09:57:21 +02:00
|
|
|
endpoints = json.loads(machine.succeed("curl -s http://machine.com/.well-known/openid-configuration"))
|
2024-01-24 06:52:23 +01:00
|
|
|
auth_endpoint = endpoints['authorization_endpoint']
|
|
|
|
|
|
|
|
machine.succeed(
|
|
|
|
"curl -f -s '"
|
|
|
|
+ auth_endpoint
|
|
|
|
+ "?client_id=other"
|
2024-08-31 09:57:21 +02:00
|
|
|
+ "&redirect_uri=http://client1.machine.com/redirect"
|
2024-01-24 06:52:23 +01:00
|
|
|
+ "&scope=openid%20profile%20email"
|
|
|
|
+ "&response_type=code"
|
|
|
|
+ "&state=99999999'"
|
|
|
|
)
|
|
|
|
|
|
|
|
machine.succeed(
|
|
|
|
"curl -f -s '"
|
|
|
|
+ auth_endpoint
|
|
|
|
+ "?client_id=client1"
|
2024-08-31 09:57:21 +02:00
|
|
|
+ "&redirect_uri=http://client1.machine.com/redirect"
|
2024-01-24 06:52:23 +01:00
|
|
|
+ "&scope=openid%20profile%20email"
|
|
|
|
+ "&response_type=code"
|
|
|
|
+ "&state=11111111'"
|
|
|
|
)
|
2023-12-11 06:56:31 +01:00
|
|
|
|
2024-01-24 06:52:23 +01:00
|
|
|
machine.succeed(
|
|
|
|
"curl -f -s '"
|
|
|
|
+ auth_endpoint
|
|
|
|
+ "?client_id=client2"
|
2024-08-31 09:57:21 +02:00
|
|
|
+ "&redirect_uri=http://client2.machine.com/redirect"
|
2024-01-24 06:52:23 +01:00
|
|
|
+ "&scope=openid%20profile%20email"
|
|
|
|
+ "&response_type=code"
|
|
|
|
+ "&state=22222222'"
|
|
|
|
)
|
2023-12-11 06:56:31 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|