Skip to content

Commit e3088a6

Browse files
committed
module: prohibit store-paths for environmentFile
The store is world-readable, so secrets shouldn't end up there in the first place. On top, `types.path` has the following behavior: * `toString foo` returns the absolute path * `${foo}` copies the path silently into the store and returns the store-path. This happens without any real feedback, so this can be caused by an innocent looking change. To address this problem, `pathsWith` was introduced into <nixpkgs/lib> which allows absolute paths represented as string, but rejects things pointing to the store and path literals which may be copied later on.
1 parent b4916a8 commit e3088a6

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

module.nix

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ let
4444
;
4545

4646
settingsFormat = pkgs.formats.yaml { };
47+
48+
pathToSecret = types.pathWith {
49+
inStore = false;
50+
absolute = true;
51+
};
4752
in
4853
{
4954
options.services = {
@@ -81,7 +86,7 @@ in
8186
};
8287

8388
environmentFile = mkOption {
84-
type = types.nullOr types.path;
89+
type = types.nullOr pathToSecret;
8590
default = null;
8691
example = "/run/secrets/authentik/authentik-env";
8792
description = ''
@@ -105,7 +110,7 @@ in
105110
enable = mkEnableOption "authentik LDAP outpost";
106111

107112
environmentFile = mkOption {
108-
type = types.nullOr types.path;
113+
type = types.nullOr pathToSecret;
109114
default = null;
110115
example = "/run/secrets/authentik-ldap/authentik-ldap-env";
111116
description = ''
@@ -128,7 +133,7 @@ in
128133
enable = mkEnableOption "authentik RADIUS outpost";
129134

130135
environmentFile = mkOption {
131-
type = types.nullOr types.path;
136+
type = types.nullOr pathToSecret;
132137
default = null;
133138
example = "/run/secrets/authentik-radius/authentik-radius-env";
134139
description = ''

tests/minimal-vmtest.nix

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
authentik-version,
44
nixosModules,
55
}:
6-
let
7-
# use a root-owned EnvironmentFile in production instead (services.authentik.environmentFile)
8-
authentik-env = pkgs.writeText "authentik-test-secret-env" ''
9-
AUTHENTIK_SECRET_KEY=thissecretwillbeinthenixstore
10-
'';
11-
in
126
pkgs.nixosTest {
137
name = "authentik";
148
nodes = {
@@ -23,9 +17,13 @@ pkgs.nixosTest {
2317
"${pkgs.path}/nixos/tests/common/x11.nix"
2418
];
2519

20+
systemd.tmpfiles.rules = [
21+
"f /etc/authentik.env 0700 root root - AUTHENTIK_SECRET_KEY=thissecretwillnotbeinthenixstore"
22+
];
23+
2624
services.authentik = {
2725
enable = true;
28-
environmentFile = authentik-env;
26+
environmentFile = "/etc/authentik.env";
2927
nginx = {
3028
enable = true;
3129
host = "localhost";

0 commit comments

Comments
 (0)