summary refs log tree commit diff
path: root/nixos/modules/services/security/hologram-server.nix
blob: 4acf6ae0e2182004f0a9f9dca75732262bba2bb7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
{pkgs, config, lib, ...}:

with lib;

let
  cfg = config.services.hologram-server;

  cfgFile = pkgs.writeText "hologram-server.json" (builtins.toJSON {
    ldap = {
      host = cfg.ldapHost;
      bind = {
        dn       = cfg.ldapBindDN;
        password = cfg.ldapBindPassword;
      };
      insecureldap    = cfg.ldapInsecure;
      userattr        = cfg.ldapUserAttr;
      baseDN          = cfg.ldapBaseDN;
      enableldapRoles = cfg.enableLdapRoles;
      roleAttr        = cfg.roleAttr;
      groupClassAttr  = cfg.groupClassAttr;
    };
    aws = {
      account     = cfg.awsAccount;
      defaultrole = cfg.awsDefaultRole;
    };
    stats        = cfg.statsAddress;
    listen       = cfg.listenAddress;
    cachetimeout = cfg.cacheTimeoutSeconds;
  });
in {
  options = {
    services.hologram-server = {
      enable = mkOption {
        type = types.bool;
        default = false;
        description = "Whether to enable the Hologram server for AWS instance credentials";
      };

      listenAddress = mkOption {
        type        = types.str;
        default     = "0.0.0.0:3100";
        description = "Address and port to listen on";
      };

      ldapHost = mkOption {
        type        = types.str;
        description = "Address of the LDAP server to use";
      };

      ldapInsecure = mkOption {
        type        = types.bool;
        default     = false;
        description = "Whether to connect to LDAP over SSL or not";
      };

      ldapUserAttr = mkOption {
        type        = types.str;
        default     = "cn";
        description = "The LDAP attribute for usernames";
      };

      ldapBaseDN = mkOption {
        type        = types.str;
        description = "The base DN for your Hologram users";
      };

      ldapBindDN = mkOption {
        type        = types.str;
        description = "DN of account to use to query the LDAP server";
      };

      ldapBindPassword = mkOption {
        type        = types.str;
        description = "Password of account to use to query the LDAP server";
      };

      enableLdapRoles = mkOption {
        type        = types.bool;
        default     = false;
        description = "Whether to assign user roles based on the user's LDAP group memberships";
      };

      groupClassAttr = mkOption {
        type = types.str;
        default = "groupOfNames";
        description = "The objectclass attribute to search for groups when enableLdapRoles is true";
      };

      roleAttr = mkOption {
        type        = types.str;
        default     = "businessCategory";
        description = "Which LDAP group attribute to search for authorized role ARNs";
      };

      awsAccount = mkOption {
        type        = types.str;
        description = "AWS account number";
      };

      awsDefaultRole = mkOption {
        type        = types.str;
        description = "AWS default role";
      };

      statsAddress = mkOption {
        type        = types.str;
        default     = "";
        description = "Address of statsd server";
      };

      cacheTimeoutSeconds = mkOption {
        type        = types.int;
        default     = 3600;
        description = "How often (in seconds) to refresh the LDAP cache";
      };
    };
  };

  config = mkIf cfg.enable {
    systemd.services.hologram-server = {
      description = "Provide EC2 instance credentials to machines outside of EC2";
      after       = [ "network.target" ];
      wantedBy    = [ "multi-user.target" ];

      serviceConfig = {
        ExecStart = "${pkgs.hologram}/bin/hologram-server --debug --conf ${cfgFile}";
      };
    };
  };
}