git.iko.soy/typeable/nixpkgs
on master help sign in
nixos/gitlab: Extract arbitrary secrets from extraConfig

Adds the ability to make any parameter specified in extraConfig secret by defining it an attrset containing the attr _secret, which in turn is a path to a file containing the actual secret.

commit240649a5100fcb5ea6f18bc5bc87acc3ce216646 authortalyz <kim.lindberger@gmail.com> dateWed 7 Aug 2019, 11:26 (7 years ago) parent64358cb
1 file changed+53−9
nixos/modules/services/misc/gitlab.nix+53−9
nixos/modules/services/misc/gitlab.nix+53−9
@@ -1,4 +1,4 @@
1−{ config, lib, pkgs, ... }:
1+{ config, lib, pkgs, utils, ... }:
22
33# TODO: support non-postgresql
44
@@ -492,16 +492,56 @@ in {
492492 extraConfig = mkOption {
493493 type = types.attrs;
494494 default = {};
495− example = {
496− gitlab = {
497− default_projects_features = {
498− builds = false;
495+ example = literalExample ''
496+ {
497+ gitlab = {
498+ default_projects_features = {
499+ builds = false;
500+ };
501+ };
502+ omniauth = {
503+ enabled = true;
504+ auto_sign_in_with_provider = "openid_connect";
505+ allow_single_sign_on = ["openid_connect"];
506+ block_auto_created_users = false;
507+ providers = [
508+ {
509+ name = "openid_connect";
510+ label = "OpenID Connect";
511+ args = {
512+ name = "openid_connect";
513+ scope = ["openid" "profile"];
514+ response_type = "code";
515+ issuer = "https://keycloak.example.com/auth/realms/My%20Realm";
516+ discovery = true;
517+ client_auth_method = "query";
518+ uid_field = "preferred_username";
519+ client_options = {
520+ identifier = "gitlab";
521+ secret = { _secret = "/var/keys/gitlab_oidc_secret"; };
522+ redirect_uri = "https://git.example.com/users/auth/openid_connect/callback";
523+ };
524+ };
525+ }
526+ ];
499527 };
500528 };
501− };
529+ '';
502530 description = ''
503− Extra options to be merged into config/gitlab.yml as nix
504− attribute set.
531+ Extra options to be added under
532+ <literal>production</literal> in
533+ <filename>config/gitlab.yml</filename>, as a nix attribute
534+ set.
535+
536+ Options containing secret data should be set to an attribute
537+ set containing the attribute <literal>_secret</literal> - a
538+ string pointing to a file containing the value the option
539+ should be set to. See the example to get a better picture of
540+ this: in the resulting
541+ <filename>config/gitlab.yml</filename> file, the
542+ <literal>production.omniauth.providers[0].args.client_options.secret</literal>
543+ key will be set to the contents of the
544+ <filename>/var/keys/gitlab_oidc_secret</filename> file.
505545 '';
506546 };
507547 };
@@ -620,7 +660,6 @@ in {
620660
621661 "L+ /run/gitlab/shell-config.yml - - - - ${pkgs.writeText "config.yml" (builtins.toJSON gitlabShellConfig)}"
622662
623− "L+ ${cfg.statePath}/config/gitlab.yml - - - - ${pkgs.writeText "gitlab.yml" (builtins.toJSON gitlabConfig)}"
624663 "L+ ${cfg.statePath}/config/unicorn.rb - - - - ${./defaultUnicornConfig.rb}"
625664 "L+ ${cfg.statePath}/config/initializers/extra-gitlab.rb - - - - ${extraGitlabRb}"
626665 ];
@@ -753,6 +792,11 @@ in {
753792 ''
754793 }
755794
795+ ${utils.genJqSecretsReplacementSnippet
796+ gitlabConfig
797+ "${cfg.statePath}/config/gitlab.yml"
798+ }
799+
756800 if [[ -h '${cfg.statePath}/config/secrets.yml' ]]; then
757801 rm '${cfg.statePath}/config/secrets.yml'
758802 fi