Skip to content

Commit aacddef

Browse files
committed
Updated OpenLDAP
1 parent 1f67b1e commit aacddef

File tree

6 files changed

+94
-71
lines changed

6 files changed

+94
-71
lines changed

_examples/openldap.tf

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ module "openldap" {
44
source = "github.com/mutablelogic/tf-nomad//openldap"
55

66
// Required parameters
7-
dc = "datacenter" // Nomad datacenter for the cluster
8-
hosts = ["server1", "server2"] // Host constraint for the job
9-
basedn = "dc=mutablelogic,dc=com" // Distinquished name for the LDAP server
10-
admin_password = local.LDAP_ADMIN_PASSWORD // Password for the LDAP 'admin' user
7+
dc = "datacenter" // Nomad datacenter for the cluster
8+
hosts = ["server1", "server2"] // Host constraint for the job
9+
organization = "My Organization" // Distinquished name for the LDAP server
10+
domain = "example.com" // Domain for the LDAP server
11+
admin_password = local.LDAP_ADMIN_PASSWORD // Password for the LDAP 'admin' user
12+
config_password = local.LDAP_ADMIN_PASSWORD // Password for the LDAP 'config' user
1113

1214
// Optional parameters
13-
enabled = true // If false, no-op
14-
namespace = "default" // Nomad namespace for the nomad job
15-
docker_tag = "latest" // Pull the latest version of the docker image every job restart
16-
port = 389 // plaintext port to expose
17-
18-
// When persisting data, set uid and gid to 1000 for the container to
19-
// have write access to the data directory
20-
data = "/var/lib/ldap"
15+
enabled = true // If false, no-op
16+
namespace = "default" // Nomad namespace for the nomad job
17+
docker_tag = "latest" // Pull the latest version of the docker image every job restart
18+
port = 389 // plaintext port to expose
19+
replication_hosts = ["ldap://server1:389/", "ldap://server2:389/"] // LDAP urls for replication
20+
data = "/var/lib/ldap" // Directory for data persistence
2121
}

openldap/input.tf

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ variable "port" {
6161
variable "data" {
6262
type = string
6363
description = "Directory for data persistence"
64-
default = ""
64+
default = ""
6565
}
6666

6767
variable "admin_password" {
@@ -70,12 +70,23 @@ variable "admin_password" {
7070
sensitive = true
7171
}
7272

73-
variable "basedn" {
74-
description = "LDAP distinguished name (required)"
73+
variable "config_password" {
74+
description = "LDAP config password"
7575
type = string
7676
}
7777

78+
variable "replication_hosts" {
79+
description = "LDAP urls for replication"
80+
type = list(string)
81+
default = []
82+
}
83+
7884
variable "organization" {
79-
description = "Organization name (required)"
85+
description = "Organization name"
86+
type = string
87+
}
88+
89+
variable "domain" {
90+
description = "Organization domain"
8091
type = string
8192
}

openldap/ldif/root.ldif

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
11

2-
# Root
3-
dn: {{ env "NOMAD_META_basedn" }}
4-
objectClass: top
5-
objectClass: domain
6-
dc: {{ env "NOMAD_META_organization" }}
7-
description: Organization
8-
92
# Groups
103
dn: ou={{ env "NOMAD_META_groups" }},{{ env "NOMAD_META_basedn" }}
114
ou: {{ env "NOMAD_META_groups" }}
125
objectClass: top
136
objectClass: organizationalUnit
14-
description: User groups
7+
description: Groups
158

169
# Users
1710
dn: ou={{ env "NOMAD_META_users" }},{{ env "NOMAD_META_basedn" }}

openldap/locals.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

22
locals {
3-
docker_image = "bitnami/openldap:${var.docker_tag}"
3+
docker_image = "osixia/openldap:${var.docker_tag}"
44
docker_always_pull = var.docker_tag == "latest" ? true : false
55
}

openldap/main.tf

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,19 @@ resource "nomad_job" "openldap" {
1616
service_dns = jsonencode(var.service_dns)
1717
service_type = var.service_type
1818

19-
port = var.port
20-
data = var.data
21-
admin_password = var.admin_password
22-
basedn = var.basedn
23-
organization = var.organization
19+
port = var.port
20+
data = var.data
21+
admin_password = var.admin_password
22+
config_password = var.config_password
23+
replication_hosts = jsonencode(var.replication_hosts)
24+
organization = var.organization
25+
domain = var.domain
2426

2527
# LDIF templates which are only applied when the data directory is empty (first run)
2628
ldif = jsonencode({
2729
"root" = file("${path.module}/ldif/root.ldif")
2830
})
29-
schema = jsonencode({
30-
"memberOf" = file("${path.module}/schema/memberOf.ldif"),
31-
"rfc2307bis" = file("${path.module}/schema/rfc2307bis.ldif")
32-
})
31+
schema = jsonencode({})
3332
}
3433
}
3534
}

openldap/nomad/openldap.hcl

Lines changed: 57 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
// OpenLDAP server
3-
// Docker Image: https://bitnami.com/stack/openldap
3+
// Docker Image: https://github.com/osixia/docker-openldap
44

55
///////////////////////////////////////////////////////////////////////////////
66
// VARIABLES
@@ -31,7 +31,7 @@ variable "service_provider" {
3131
variable "service_name" {
3232
description = "Service name"
3333
type = string
34-
default = "coredns-dns"
34+
default = "openldap-ldap"
3535
}
3636

3737
variable "service_dns" {
@@ -65,49 +65,65 @@ variable "port" {
6565
default = 389
6666
}
6767

68+
variable "tls_port" {
69+
description = "Port for TLS connections"
70+
type = number
71+
default = 636
72+
}
73+
6874
variable "data" {
6975
description = "Data persistence directory"
7076
type = string
7177
default = ""
7278
}
7379

74-
variable "ldif" {
75-
description = "Custom LDIF rules, optional"
76-
type = map(string)
80+
variable "admin_password" {
81+
description = "LDAP admin password"
82+
type = string
7783
}
7884

79-
variable "schema" {
80-
description = "Custom schemas, optional"
81-
type = map(string)
85+
variable "config_password" {
86+
description = "LDAP config password"
87+
type = string
8288
}
8389

84-
variable "extra_schemas" {
85-
description = "Extra schemas, optional"
86-
type = string
87-
default = "cosine,inetorgperson"
90+
variable "replication_hosts" {
91+
description = "LDAP urls for replication"
92+
type = list(string)
8893
}
8994

90-
variable "admin_password" {
91-
description = "LDAP admin password"
95+
variable "organization" {
96+
description = "Organization name"
9297
type = string
9398
}
9499

95-
variable "basedn" {
96-
description = "Distinguished name"
100+
variable "domain" {
101+
description = "Organization domain"
97102
type = string
98103
}
99104

100-
variable "organization" {
101-
description = "Organization name"
102-
type = string
105+
variable "ldif" {
106+
description = "Custom LDIF rules, optional"
107+
type = map(string)
108+
}
109+
110+
variable "schema" {
111+
description = "Custom schemas, optional"
112+
type = map(string)
113+
}
114+
115+
variable "debug" {
116+
description = "Debug output"
117+
type = bool
118+
default = false
103119
}
104120

105121
///////////////////////////////////////////////////////////////////////////////
106122
// LOCALS
107123

108124
locals {
109-
ldif_path = format("%s/data/ldif",NOMAD_ALLOC_DIR)
110-
schema_path = format("%s/data/schema",NOMAD_ALLOC_DIR)
125+
ldif_path = format("%s/data/ldif", NOMAD_ALLOC_DIR)
126+
schema_path = format("%s/data/schema", NOMAD_ALLOC_DIR)
111127
}
112128

113129
///////////////////////////////////////////////////////////////////////////////
@@ -143,6 +159,10 @@ job "openldap" {
143159
static = var.port
144160
to = 389
145161
}
162+
port "ldaps" {
163+
static = var.tls_port
164+
to = 636
165+
}
146166
}
147167

148168
service {
@@ -154,12 +174,12 @@ job "openldap" {
154174

155175
task "daemon" {
156176
driver = "docker"
157-
user = "root"
158177

159178
// Metadata for ldif and schema templates
160179
meta {
161-
basedn = var.basedn
162180
organization = var.organization
181+
domain = "{{ LDAP_DOMAIN }}"
182+
basedn = "{{ LDAP_BASE_DN }}"
163183
users = "users"
164184
groups = "groups"
165185
}
@@ -183,27 +203,27 @@ job "openldap" {
183203
}
184204

185205
env {
186-
LDAP_ADMIN_USERNAME = "admin"
187-
LDAP_ADMIN_PASSWORD = var.admin_password
188-
LDAP_PORT_NUMBER = NOMAD_PORT_ldap
189-
LDAP_ROOT = var.basedn
190-
LDAP_ADD_SCHEMAS = var.extra_schemas == "" ? "no" : "yes"
191-
LDAP_EXTRA_SCHEMAS = var.extra_schemas
192-
LDAP_SKIP_DEFAULT_TREE = "yes"
193-
LDAP_CUSTOM_LDIF_DIR = local.ldif_path
194-
//LDAP_CUSTOM_SCHEMA_DIR = local.schema_path
195-
LDAP_CONFIGURE_PPOLICY = "yes"
196-
LDAP_ALLOW_ANON_BINDING = "no"
197-
BITNAMI_DEBUG = "true"
206+
LDAP_DOMAIN = var.domain
207+
LDAP_ORGANISATION = var.organization
208+
LDAP_ADMIN_PASSWORD = var.admin_password
209+
LDAP_CONFIG_PASSWORD = var.config_password
210+
LDAP_RFC2307BIS_SCHEMA = "true"
211+
LDAP_REMOVE_CONFIG_AFTER_SETUP = "false"
212+
LDAP_SEED_INTERNAL_LDIF_PATH = length(var.ldif) == 0 ? "" : local.ldif_path
213+
LDAP_SEED_INTERNAL_SCHEMA_PATH = length(var.schema) == 0 ? "" : local.schema_path
214+
LDAP_REPLICATION_HOSTS = length(var.replication_hosts) == 0 ? "" : format("#PYTHON2BASH:%s", jsonencode(var.replication_hosts))
215+
LDAP_TLS = "false"
198216
}
199217

200218
config {
201219
image = var.docker_image
202220
force_pull = var.docker_always_pull
203-
ports = ["ldap"]
221+
ports = ["ldap", "ldaps"]
204222
dns_servers = var.service_dns
223+
args = ["--copy-service", "--loglevel", var.debug ? "debug" : "info"]
205224
volumes = compact([
206-
var.data == "" ? "" : format("%s:/bitnami/openldap", var.data),
225+
var.data == "" ? "" : format("%s/data:/var/lib/ldap", var.data),
226+
var.data == "" ? "" : format("%s/slapd.d:/etc/ldap/slapd.d", var.data),
207227
])
208228
}
209229

0 commit comments

Comments
 (0)