@@ -9,21 +9,24 @@ lib.mkModule args "ioga.services.authelia" {
99 user = "authelia-${ cfg . instanceName } " ;
1010 group = "authelia-${ cfg . instanceName } " ;
1111 } ;
12+
1213 services . authelia . instances . ${ cfg . instanceName } = {
1314 enable = true ;
15+
1416 secrets = {
1517 jwtSecretFile = "${ secrets . authelia } /jwtSecretFile" ;
1618 sessionSecretFile = "${ secrets . authelia } /sessionSecretFile" ;
1719 storageEncryptionKeyFile =
1820 "${ secrets . authelia } /storageEncryptionKeyFile" ;
21+ oidcHmacSecretFile = "${ secrets . authelia } /oidcHmac" ;
22+ oidcIssuerPrivateKeyFile = "${ secrets . authelia } /oidcKey" ;
1923 } ;
2024
2125 settings = {
2226 theme = "dark" ;
2327 server . address = "tcp://0.0.0.0:9091" ;
2428
25- authentication_backend . file . path =
26- "/var/lib/authelia-${ cfg . instanceName } /users.yml" ;
29+ authentication_backend . file . path = "${ secrets . authelia } /users.yml" ;
2730 storage . local . path = "/var/lib/authelia-${ cfg . instanceName } /db.sqlite3" ;
2831 notifier . filesystem . filename =
2932 "/var/lib/authelia-${ cfg . instanceName } /emails.txt" ;
@@ -42,6 +45,23 @@ lib.mkModule args "ioga.services.authelia" {
4245 ] ;
4346 } ;
4447
48+ identity_providers . oidc = {
49+ clients = [ {
50+ client_id = "vault" ;
51+ client_name = "HashiCorp Vault" ;
52+ public = false ;
53+ client_secret =
54+ ''{{ secret "${ secrets . authelia } /clientSecretHash" }}'' ;
55+ authorization_policy = "two_factor" ;
56+ redirect_uris = [
57+ "https://vault.ioga.dev"
58+ "http://localhost:8250/oidc/callback"
59+ ] ;
60+ scopes = [ "openid" "profile" "email" "groups" ] ;
61+ userinfo_signed_response_alg = "none" ;
62+ } ] ;
63+ } ;
64+
4565 session . cookies = [ {
4666 inherit ( cfg ) domain ;
4767 authelia_url = "https://auth.${ cfg . domain } " ;
@@ -52,23 +72,10 @@ lib.mkModule args "ioga.services.authelia" {
5272
5373 systemd . services . "authelia-${ cfg . instanceName } " = {
5474 serviceConfig . StateDirectory = "authelia-${ cfg . instanceName } " ;
55- preStart = # bash
56- ''
57- USER_DB="/var/lib/authelia-${ cfg . instanceName } /users.yml"
58- PASS=$(cat ${ secrets . authelia } /adminPassword)
59- HASHED_PASSWORD=$(${ pkgs . authelia } /bin/authelia crypto hash generate argon2 --password "$PASS" | ${ pkgs . gawk } /bin/awk '/Digest:/ {print $2}')
60- if [ ! -s "$USER_DB" ]; then
61- echo "${ ''
62- users:
63- admin:
64- displayname: "Admin"
65- password: "$HASHED_PASSWORD"
66- email: "admin@${ cfg . domain } "
67- groups: [admins]'' } " > "$USER_DB"
68- chmod 600 "$USER_DB"
69- chown authelia-${ cfg . instanceName } :authelia-${ cfg . instanceName } "$USER_DB"
70- fi
71- '' ;
75+
76+ # 4. Enable the 'template' filter via environment variable
77+ # This allows Authelia to process the {{ secret }} syntax in the config file.
78+ environment . X_AUTHELIA_CONFIG_FILTERS = "template" ;
7279 } ;
7380 } ;
7481}
0 commit comments