-
-
Notifications
You must be signed in to change notification settings - Fork 19.7k
nixos/authentik: init module, authentik: 2024.6.4 -> 2024.8.3 #345940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
98cb289
nixos/authentik: init module
jvanbruegge deff7f8
nixos/tests/authentik: init tests
jvanbruegge b51db43
python3Packages.scim2-filter-parser: 0.5.0 -> 0.7.0
jvanbruegge 4c2851f
python3Packages.drf-orjson-renderer: init at 1.7.3
jvanbruegge 7746b58
authentik,authentik.outposts.{ldap,radius}: 2024.6.4 -> 2024.8.3
jvanbruegge 697e7c6
authentik.outposts.proxy: init at 2024.8.3
jvanbruegge ca15b55
python3Packages.django-cte: move out of authentik
jvanbruegge 6aa43f2
python3Packages.django-tenants: move out of authentik
jvanbruegge 36da7cf
python3Packages.django-pgactivity: move out of authentik
jvanbruegge dde3110
python3Packages.django-pglock: move out of authentik
jvanbruegge 482a30b
python3Packages.tenant-schemas-celery: move out of authentik
jvanbruegge File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,235 @@ | ||
| { | ||
| config, | ||
| lib, | ||
| pkgs, | ||
| ... | ||
| }: | ||
| let | ||
| inherit (lib) | ||
| mkIf | ||
| types | ||
| mkOption | ||
| mkEnableOption | ||
| mkPackageOption | ||
| ; | ||
| cfg = config.services.authentik; | ||
|
|
||
| isRedisUnixSocket = lib.hasPrefix "/" cfg.redis.host; | ||
|
|
||
| commonServiceConfig = { | ||
| Type = "simple"; | ||
| User = cfg.user; | ||
| Group = cfg.group; | ||
| Restart = "always"; | ||
| RestartSec = 3; | ||
| RuntimeDirectory = "authentik"; | ||
| NoNewPrivileges = true; | ||
| PrivateTmp = true; | ||
| ProtectHome = true; | ||
| ProtectSystem = "strict"; | ||
| ProtectKernelTunables = true; | ||
| ProtectKernelModules = true; | ||
| ProtectControlGroups = true; | ||
| SystemCallFilter = "~@cpu-emulation @keyring @module @obsolete @raw-io @reboot @swap @sync"; | ||
| ConfigurationDirectory = "authentik"; | ||
| }; | ||
| in | ||
| { | ||
| options.services.authentik = { | ||
| enable = mkEnableOption "authentik"; | ||
| package = mkPackageOption pkgs "authentik" { }; | ||
|
|
||
| secretsFile = mkOption { | ||
| type = types.nullOr ( | ||
| types.str | ||
| // { | ||
| # We don't want users to be able to pass a path literal here but | ||
| # it should look like a path. | ||
| check = it: lib.isString it && lib.types.path.check it; | ||
| } | ||
| ); | ||
| default = null; | ||
| example = "/run/secrets/authentik"; | ||
| description = '' | ||
| Path of a file with extra environment variables to be loaded from disk. | ||
| This file is not added to the nix store, so it can be used to pass secrets to authentik. | ||
| Refer to the [documentation](https://docs.goauthentik.io/docs/installation/configuration) for options. | ||
|
|
||
| authentik requires at least a secret key: | ||
| ``` | ||
| AUTHENTIK_SECRET_KEY=<random key> | ||
| ``` | ||
| You can also use services.authentik.environment.AUTHENTIK_SECRET_KEY = 'file:///path/to/secret' instead | ||
| ''; | ||
| }; | ||
| environment = mkOption { | ||
| type = types.attrsOf types.str; | ||
| default = { }; | ||
| example = { | ||
| AUTHENTIK_LOG_LEVEL = "debug"; | ||
| }; | ||
| description = '' | ||
| Extra configuration environment variables. Refer to the [documentation](https://docs.goauthentik.io/docs/installation/configuration) for options. | ||
| ''; | ||
| }; | ||
|
|
||
| host = lib.mkOption { | ||
| type = types.str; | ||
| default = "localhost"; | ||
| description = "The host that authentik will listen on."; | ||
| }; | ||
| httpPort = mkOption { | ||
| type = types.port; | ||
| default = 9000; | ||
|
jvanbruegge marked this conversation as resolved.
Outdated
|
||
| description = "The http port that authentik will listen on."; | ||
| }; | ||
| httpsPort = mkOption { | ||
| type = types.port; | ||
| default = 9443; | ||
| description = "The https port that authentik will listen on."; | ||
| }; | ||
| user = mkOption { | ||
| type = types.str; | ||
| default = "authentik"; | ||
| description = "The user authentik should run as."; | ||
| }; | ||
| group = mkOption { | ||
| type = types.str; | ||
| default = "authentik"; | ||
| description = "The group authentik should run as."; | ||
| }; | ||
| database = { | ||
| enable = | ||
| mkEnableOption "the postgresql database for use with authentik. See {option}`services.postgresql`" | ||
| // { | ||
| default = true; | ||
| }; | ||
| createDB = mkEnableOption "the automatic creation of the database for authentik." // { | ||
| default = true; | ||
| }; | ||
| name = mkOption { | ||
| type = types.str; | ||
| default = "authentik"; | ||
| description = "The name of the authentik database."; | ||
| }; | ||
|
jvanbruegge marked this conversation as resolved.
Outdated
|
||
| host = mkOption { | ||
| type = types.str; | ||
| default = "/run/postgresql"; | ||
| example = "127.0.0.1"; | ||
| description = "Hostname or address of the postgresql server. If an absolute path is given here, it will be interpreted as a unix socket path."; | ||
| }; | ||
| port = mkOption { | ||
| type = types.port; | ||
| default = 5432; | ||
| description = "The port of the postgresql server"; | ||
| }; | ||
| user = mkOption { | ||
| type = types.str; | ||
| default = "authentik"; | ||
| description = "The database user for authentik."; | ||
| }; | ||
| }; | ||
| redis = { | ||
| enable = mkEnableOption "a redis cache for use with authentik" // { | ||
| default = true; | ||
| }; | ||
| host = mkOption { | ||
| type = types.str; | ||
| default = config.services.redis.servers.authentik.unixSocket; | ||
| defaultText = lib.literalExpression "config.services.redis.servers.authentik.unixSocket"; | ||
| description = "The host that redis will listen on."; | ||
| }; | ||
| port = mkOption { | ||
| type = types.port; | ||
| default = 0; | ||
| description = "The port that redis will listen on. Set to zero to disable TCP."; | ||
| }; | ||
| }; | ||
|
Comment on lines
132
to
147
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be like the DB, with a specific option for local provisioning?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you mean? |
||
| }; | ||
|
|
||
| config = mkIf cfg.enable { | ||
| assertions = [ | ||
| { | ||
| assertion = cfg.database.createDB -> cfg.database.name == cfg.database.user; | ||
| message = "The postgres module requires the database name and the database user name to be the same."; | ||
| } | ||
| { | ||
| assertion = cfg.secretsFile == null -> lib.hasPrefix "file://" cfg.environment.AUTHENTIK_SECRET_KEY; | ||
| message = "If no secretsFile is provided, services.authentik.environment has to provide AUTHENTIK_SECRET_KEY with a file:// prefix"; | ||
| } | ||
| { | ||
| assertion = cfg.secretsFile != null -> !(cfg.environment ? "AUTHENTIK_SECRET_KEY"); | ||
| message = "Possibly conflicting AUTHENTIK_SECRET_KEY definition in secretsFile and services.authentik.environment"; | ||
| } | ||
| ]; | ||
|
|
||
| systemd.services.authentik-server = { | ||
| description = "Authentik server component"; | ||
| after = [ "network-online.target" ]; | ||
| wantedBy = [ "multi-user.target" ]; | ||
| inherit (cfg) environment; | ||
|
|
||
| serviceConfig = commonServiceConfig // { | ||
| ExecStart = "${lib.getExe cfg.package} server"; | ||
| EnvironmentFile = cfg.secretsFile; | ||
| }; | ||
| }; | ||
|
|
||
| systemd.services.authentik-worker = { | ||
| description = "Authentik worker component"; | ||
| after = [ "network-online.target" ]; | ||
| wantedBy = [ "multi-user.target" ]; | ||
| inherit (cfg) environment; | ||
|
|
||
| serviceConfig = commonServiceConfig // { | ||
| ExecStart = "${lib.getExe cfg.package} worker"; | ||
| EnvironmentFile = cfg.secretsFile; | ||
| }; | ||
| }; | ||
|
|
||
| services.postgresql = mkIf cfg.database.enable { | ||
| enable = true; | ||
| ensureDatabases = mkIf cfg.database.createDB [ cfg.database.name ]; | ||
| ensureUsers = mkIf cfg.database.createDB [ | ||
| { | ||
| name = cfg.database.user; | ||
| ensureDBOwnership = true; | ||
| ensureClauses.login = true; | ||
| } | ||
| ]; | ||
| }; | ||
|
|
||
| services.authentik.environment = { | ||
| AUTHENTIK_CACHE__URL = mkIf isRedisUnixSocket "unix://${cfg.redis.host}"; | ||
| AUTHENTIK_CHANNEL__URL = mkIf isRedisUnixSocket "unix://${cfg.redis.host}"; | ||
| AUTHENTIK_RESULT_BACKEND__URL = mkIf isRedisUnixSocket "redis+socket://${cfg.redis.host}"; | ||
| AUTHENTIK_BROKER__URL = mkIf isRedisUnixSocket "redis+socket://${cfg.redis.host}"; | ||
| AUTHENTIK_REDIS__HOST = mkIf (!isRedisUnixSocket) cfg.redis.host; | ||
| AUTHENTIK_REDIS__PORT = mkIf (!isRedisUnixSocket) (toString cfg.redis.port); | ||
| AUTHENTIK_POSTGRESQL__HOST = cfg.database.host; | ||
| AUTHENTIK_POSTGRESQL__NAME = cfg.database.name; | ||
| AUTHENTIK_POSTGRESQL__USER = cfg.database.user; | ||
| AUTHENTIK_POSTGRESQL__PORT = toString cfg.database.port; | ||
| AUTHENTIK_LISTEN_HTTP = "${cfg.host}:${toString cfg.httpPort}"; | ||
| AUTHENTIK_LISTEN_HTTPS = "${cfg.host}:${toString cfg.httpsPort}"; | ||
| }; | ||
|
|
||
| services.redis.servers = mkIf cfg.redis.enable { | ||
| authentik = { | ||
| enable = true; | ||
| user = cfg.user; | ||
| port = cfg.redis.port; | ||
| bind = mkIf (!isRedisUnixSocket) cfg.redis.host; | ||
| }; | ||
| }; | ||
|
|
||
| users.users = mkIf (cfg.user == "authentik") { | ||
| authentik = { | ||
| name = "authentik"; | ||
| group = cfg.group; | ||
| isSystemUser = true; | ||
| }; | ||
| }; | ||
| users.groups = mkIf (cfg.group == "authentik") { authentik = { }; }; | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import ../make-test-python.nix ( | ||
| { ... }: | ||
| { | ||
| name = "authentik-nixos"; | ||
|
|
||
| nodes.machine = | ||
| { pkgs, ... }: | ||
| { | ||
| environment.systemPackages = with pkgs; [ openssl ]; | ||
|
|
||
| services.authentik = { | ||
| enable = true; | ||
| secretsFile = "/run/secrets/authentik"; | ||
| environment.AUTHENTIK_LOG_LEVEL = "debug"; | ||
| }; | ||
| }; | ||
|
|
||
| testScript = '' | ||
| machine.succeed("mkdir -p /run/secrets ; echo \"AUTHENTIK_SECRET_KEY=$(openssl rand -base64 60 | tr -d '\n')\" > /run/secrets/authentik ; echo \"AUTHENTIK_BOOTSTRAP_PASSWORD=admin\" >> /run/secrets/authentik") | ||
|
|
||
| machine.wait_for_unit("authentik-server.service") | ||
|
|
||
| machine.wait_for_open_port(9000) | ||
| machine.wait_until_succeeds("curl --fail http://localhost:9000/api/v3/root/config", 100) | ||
| ''; | ||
| } | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,6 @@ | ||
| { callPackage }: { | ||
| ldap = callPackage ./ldap.nix { }; | ||
| radius = callPackage ./radius.nix { }; | ||
| { callPackage, authentik }: | ||
| { | ||
| ldap = callPackage ./ldap.nix { inherit authentik; }; | ||
| radius = callPackage ./radius.nix { inherit authentik; }; | ||
| proxy = callPackage ./proxy.nix { inherit authentik; }; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any benefit to adding support for running outposts as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Long term yes, but I want to do this in a later PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough