git.iko.soy/typeable/nixpkgs
on master help sign in
oauth2_proxy: add keyFile, make some options optional
commita037cbd46bab2553921c5d5de51641bfdcf902a9 authorYorick van Pelt <yorick@yorickvanpelt.nl> dateMon 16 Apr 2018, 14:06 (9 years ago) parentb901c40
1 file changed+33−4
nixos/modules/services/security/oauth2_proxy.nix+33−4
nixos/modules/services/security/oauth2_proxy.nix+33−4
@@ -20,7 +20,7 @@ let
2020 inherit (cfg.github) org team;
2121 }; };
2222
23− google = cfg: { google = with cfg.google; {
23+ google = cfg: { google = with cfg.google; optionalAttrs (groups != []) {
2424 admin-email = adminEmail;
2525 service-account = serviceAccountJSON;
2626 group = groups;
@@ -57,6 +57,7 @@ let
5757 inherit (cookie) domain secure expire name secret refresh;
5858 httponly = cookie.httpOnly;
5959 };
60+ set-xauthrequest = setXauthrequest;
6061 } // lib.optionalAttrs (!isNull cfg.email.addresses) {
6162 authenticated-emails-file = authenticatedEmailsFile;
6263 } // lib.optionalAttrs (cfg.passBasicAuth) {
@@ -120,7 +121,7 @@ in
120121 };
121122
122123 clientID = mkOption {
123− type = types.str;
124+ type = types.nullOr types.str;
124125 description = ''
125126 The OAuth Client ID.
126127 '';
@@ -128,7 +129,7 @@ in
128129 };
129130
130131 clientSecret = mkOption {
131− type = types.str;
132+ type = types.nullOr types.str;
132133 description = ''
133134 The OAuth Client Secret.
134135 '';
@@ -282,7 +283,8 @@ in
282283 ####################################################
283284 # UPSTREAM Configuration
284285 upstream = mkOption {
285− type = types.commas;
286+ type = with types; coercedTo string (x: [x]) (listOf string);
287+ default = [];
286288 description = ''
287289 The http url(s) of the upstream endpoint or <literal>file://</literal>
288290 paths for static files. Routing is based on the path.
@@ -504,6 +506,14 @@ in
504506 '';
505507 };
506508
509+ setXauthrequest = mkOption {
510+ type = types.nullOr types.bool;
511+ default = null;
512+ description = ''
513+ Set X-Auth-Request-User and X-Auth-Request-Email response headers (useful in Nginx auth_request mode).
514+ '';
515+ };
516+
507517 extraConfig = mkOption {
508518 default = {};
509519 description = ''
@@ -511,10 +521,28 @@ in
511521 '';
512522 };
513523
524+ keyFile = mkOption {
525+ type = types.nullOr types.string;
526+ default = null;
527+ description = ''
528+ oauth2_proxy allows passing sensitive configuration via environment variables.
529+ Make a file that contains lines like
530+ OAUTH2_PROXY_CLIENT_SECRET=asdfasdfasdf.apps.googleuserscontent.com
531+ and specify the path here.
532+ '';
533+ example = "/run/keys/oauth2_proxy";
534+ };
535+
514536 };
515537
516538 config = mkIf cfg.enable {
517539
540+ services.oauth2_proxy = mkIf (!isNull cfg.keyFile) {
541+ clientID = mkDefault null;
542+ clientSecret = mkDefault null;
543+ cookie.secret = mkDefault null;
544+ };
545+
518546 users.extraUsers.oauth2_proxy = {
519547 description = "OAuth2 Proxy";
520548 };
@@ -529,6 +557,7 @@ in
529557 User = "oauth2_proxy";
530558 Restart = "always";
531559 ExecStart = "${cfg.package.bin}/bin/oauth2_proxy ${configString}";
560+ EnvironmentFile = mkIf (cfg.keyFile != null) cfg.keyFile;
532561 };
533562 };
534563