Skip to content

Commit ca8ffa2

Browse files
authored
Added a script and yaml file to setup ds389 in rancher (#22)
* Added a script and yaml file to setup ds389 in rancher * changed to helm chart * turned into a library --------- Co-authored-by: rmahique-github <>
1 parent 67d7676 commit ca8ffa2

File tree

8 files changed

+320
-0
lines changed

8 files changed

+320
-0
lines changed

charts/ds389/Chart.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: v2
2+
name: ds389-helm-chart
3+
description: A Helm chart for deploying the 389 Directory Server
4+
version: 1.0.0
5+
appVersion: "1.0"
6+
maintainers:
7+
- name: rmahique
8+
9+
keywords:
10+
- ldap
11+
- '389'
12+
- '636'

charts/ds389/templates/secrets.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
apiVersion: v1
3+
kind: Secret
4+
metadata:
5+
name: dirsrv-tls-secret
6+
# namespace: {{ .Values.ds389.nsName }}
7+
data:
8+
tls.key: {{ .Values.ds389.tlsKey | b64enc | quote }}
9+
tls.crt: {{ .Values.ds389.tlsCert | b64enc | quote }}
10+
---
11+
apiVersion: v1
12+
kind: Secret
13+
metadata:
14+
name: dirsrv-dm-password
15+
# namespace: {{ .Values.ds389.nsName }}
16+
data:
17+
dm-password: {{ .Values.ds389.dmPassword | quote }}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
labels:
5+
app: {{ .Values.ds389.name }}
6+
name: {{ .Values.ds389.name }}-external-svc
7+
# namespace: {{ .Values.ds389.nsName }}
8+
spec:
9+
ports:
10+
- name: {{ .Values.ds389.name }}-port
11+
port: {{ .Values.ds389.internalPort }}
12+
protocol: TCP
13+
targetPort: {{ .Values.ds389.internalPort }}
14+
nodePort: {{ .Values.ds389.nodePort }}
15+
- name: {{ .Values.ds389.name }}-tls-port
16+
port: {{ .Values.ds389.tlsPort }}
17+
protocol: TCP
18+
targetPort: {{ .Values.ds389.tlsPort }}
19+
nodePort: {{ .Values.ds389.nodePortTls }}
20+
selector:
21+
app: {{ .Values.ds389.name }}
22+
type: NodePort
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
labels:
5+
app: {{ .Values.ds389.name }}
6+
name: {{ .Values.ds389.name }}-internal-svc
7+
# namespace: {{ .Values.ds389.nsName }}
8+
spec:
9+
clusterIP: None
10+
ports:
11+
- name: {{ .Values.ds389.name }}-port
12+
port: {{ .Values.ds389.internalPort }}
13+
protocol: TCP
14+
targetPort: {{ .Values.ds389.internalPort }}
15+
- name: {{ .Values.ds389.name }}-tls-port
16+
port: {{ .Values.ds389.tlsPort }}
17+
protocol: TCP
18+
targetPort: {{ .Values.ds389.tlsPort }}
19+
selector:
20+
app: {{ .Values.ds389.name }}
21+
type: ClusterIP
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v1
2+
kind: ServiceAccount
3+
metadata:
4+
name: {{ .Values.ds389.name }}-sa
5+
# namespace: {{ .Values.ds389.nsName }}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
apiVersion: apps/v1
2+
kind: StatefulSet
3+
metadata:
4+
name: {{ .Values.ds389.name }}
5+
# namespace: {{ .Values.ds389.nsName }}
6+
spec:
7+
serviceName: {{ .Values.ds389.name }}-internal-svc
8+
replicas: 1
9+
selector:
10+
matchLabels:
11+
app: {{ .Values.ds389.name }}
12+
template:
13+
metadata:
14+
labels:
15+
app: {{ .Values.ds389.name }}
16+
spec:
17+
serviceAccountName: {{ .Values.ds389.name }}-sa
18+
securityContext:
19+
fsGroup: 499
20+
initContainers:
21+
- name: {{ .Values.ds389.name }}-init-container
22+
image: busybox
23+
command: ["/bin/sh", "-c", "chown -R 499:499 /data"]
24+
volumeMounts:
25+
- name: {{ .Values.ds389.name }}-data
26+
mountPath: /data
27+
containers:
28+
- name: dirsrv-container
29+
image: {{ .Values.ds389.image }}
30+
lifecycle:
31+
postStart:
32+
exec:
33+
command: ["/bin/sh", "-c", "sleep 60;
34+
dsconf localhost backend create --suffix {{ .Values.ds389.rootDN }} --be-name userroot --create-suffix --create-entries ;
35+
dsconf localhost pwpolicy set --pwdscheme=CRYPT-SHA512 ;
36+
dsconf localhost config replace nsslapd-rootpwstoragescheme=CRYPT-SHA512 ;
37+
dsconf localhost config replace nsslapd-rootpw={{ .Values.ds389.dm_pwd }} ;
38+
dsconf localhost plugin referential-integrity enable ;
39+
dsconf localhost plugin memberof enable ;
40+
dsconf localhost config replace nsslapd-allow-anonymous-access=off ;
41+
dsidm localhost --basedn {{ .Values.ds389.rootDN }} user create --uid ldap_user --cn ldap_user --displayName ldap_user --uidNumber 1001 --gidNumber 1001 --homeDirectory /home/ldap_user ;
42+
dsidm localhost -b {{ .Values.ds389.rootDN }} account change_password uid=ldap_user,ou=people,{{ .Values.ds389.rootDN }} {{ .Values.ds389.users_pwd }} ;
43+
dsidm localhost --basedn {{ .Values.ds389.rootDN }} user create --uid developer --cn developer --displayName developer --uidNumber 1002 --gidNumber 1002 --homeDirectory /home/developer ;
44+
dsidm localhost -b {{ .Values.ds389.rootDN }} account change_password uid=developer,ou=people,{{ .Values.ds389.rootDN }} {{ .Values.ds389.users_pwd }} ;
45+
dsidm localhost --basedn {{ .Values.ds389.rootDN }} group create --cn developers;
46+
dsidm localhost -b {{ .Values.ds389.rootDN }} group add_member developers uid=developer,ou=people,{{ .Values.ds389.rootDN }}
47+
"]
48+
env:
49+
- name: DS_DM_PASSWORD
50+
valueFrom:
51+
secretKeyRef:
52+
name: dirsrv-dm-password
53+
key: dm-password
54+
- name: DS_SUFFIX_NAME
55+
value: "{{ .Values.ds389.rootDN }}"
56+
- name: DS_ERRORLOG_LEVEL
57+
value: "8192"
58+
- name: DS_MEMORY_PERCENTAGE
59+
value: "10"
60+
- name: DS_REINDEX
61+
value: "True"
62+
- name: DS_STARTUP_TIMEOUT
63+
value: "120"
64+
ports:
65+
- containerPort: {{ .Values.ds389.internalPort }}
66+
protocol: TCP
67+
- containerPort: {{ .Values.ds389.tlsPort }}
68+
protocol: TCP
69+
securityContext:
70+
runAsUser: 489
71+
volumeMounts:
72+
- name: {{ .Values.ds389.name }}-data
73+
mountPath: "/data"
74+
- name: dirsrv-tls
75+
mountPath: '/data/tls/'
76+
readOnly: true
77+
volumes:
78+
- name: dirsrv-tls
79+
secret:
80+
secretName: dirsrv-tls-secret
81+
items:
82+
- key: tls.key
83+
path: server.key
84+
- key: tls.crt
85+
path: server.crt
86+
volumeClaimTemplates:
87+
- metadata:
88+
name: {{ .Values.ds389.name }}-data
89+
spec:
90+
accessModes: [ "ReadWriteOnce" ]
91+
resources:
92+
requests:
93+
storage: {{ .Values.ds389.vcSize }}

charts/ds389/values.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Default values for ds389-helm-chart
2+
ds389:
3+
nsName: "ds389"
4+
name: "ds389"
5+
image: "docker.io/389ds/dirsrv"
6+
tlsKey: "LS0tLS1CRUdJTiBFTkNSWVBURUQgUFJJVkFURSBLRVktLS0tLQpNSUlKbnpCSkJna3Foa2lHOXcwQkJRMHdQREFiQmdrcWhraUc5dzBCQlF3d0RnUUlMZmtpMDkwcnZsb0NBZ2dBCk1CMEdDV0NHU0FGbEF3UUJLZy4uLkdOWWM3aTlTVkRCb0E9PQotLS0tLUVORCBFTkNSWVBURUQgUFJJVkFURSBLRVktLS0tLQ=="
7+
tlsCert: "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUZ4akNDQTY0Q0NRQ05UK2VQMnZqSnh6QU5CZ2txaGtpRzl3MEJBUXNGQURDQnBERUxNQWtHQTFVRUJoTUMKUmxJeEVqQVFCZ05WQkFnTUMuLi51ZEp3RTdIbm5BN2xwQQotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0t"
8+
dmPassword: "YWRtaW4xMjM="
9+
rootDN: "dc=mydemo,dc=lab"
10+
userPassword: "supersecret123"
11+
vcSize: "5Gi"
12+
internalPort: 3389
13+
tlsPort: 3636
14+
nodePort: 30389
15+
nodePortTls: 30636

scripts/authentication/ds389.sh

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#!/bin/bash
2+
# This library contains some functions to use and setup 389
3+
# directory server ( https://www.port389.org/index.html )
4+
# which is an "enterprise-class Open Source LDAP server for Linux.".
5+
# SPDX-License-Identifier: GPL-3.0-only or GPL-3.0-or-later
6+
#
7+
# Copyright (C) 2024 Raul Mahiques
8+
#
9+
# This program is free software: you can redistribute it and/or modify
10+
# it under the terms of the GNU General Public License as published by
11+
# the Free Software Foundation, either version 3 of the License, or
12+
# (at your option) any later version.
13+
#
14+
# This program is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU General Public License for more details.
18+
#
19+
# For more details find a copy of the license here:
20+
# https://www.gnu.org/licenses/gpl-3.0.txt
21+
#
22+
23+
24+
25+
#######################################
26+
# DS389 - restrict permissions:
27+
# - prevent normal users from reading the whole directory
28+
# Arguments:
29+
# 1 - _ldap_uri
30+
# 2 - _ldap_basedn
31+
# 3 - _admin_user
32+
# 4 - _admin_pwd
33+
# Examples:
34+
# ds389_restrict_permissions "<_ldap_uri>" "<_ldap_basedn>" "<_admin_user>" "<_admin_pwd>"
35+
#######################################
36+
function ds389_restrict_permissions() {
37+
local _ldap_uri="$1"
38+
local _ldap_basedn="$2"
39+
local _admin_user="$3"
40+
local _admin_pwd="$4"
41+
ldapmodify -D "${_admin_user}" -w "${_admin_pwd}" -x -H "${_ldap_uri}" << EOL
42+
dn: ou=people,${_ldap_basedn}
43+
changetype: modify
44+
delete: aci
45+
aci: (targetattr="objectClass || description || nsUniqueId || uid || displayName || loginShell || uidNumber || gidNumber || gecos || homeDirectory || cn || memberOf || mail || nsSshPublicKey || nsAccountLock || userCertificate")(targetfilter="(objectClass=posixaccount)")(version 3.0; acl "Enable anyone user read"; allow (read, search, compare)(userdn="ldap:///anyone");)
46+
47+
dn: ou=people,${_ldap_basedn}
48+
changetype: modify
49+
add: aci
50+
aci: (targetattr="objectClass || description || nsUniqueId || uid || displayName || loginShell || uidNumber || gidNumber || gecos || homeDirectory || cn || memberOf || mail || nsSshPublicKey || nsAccountLock || userCertificate")(targetfilter="(objectClass=posixaccount)")(version 3.0; acl "Enable self user read"; allow (read, search, compare)(userdn="ldap:///self");)
51+
EOL
52+
}
53+
54+
#######################################
55+
# DS389 - Grant user privileges to read the whole directory
56+
# Arguments:
57+
# 1 - _ldap_uri
58+
# 2 - _ldap_basedn
59+
# 3 - _admin_user
60+
# 4 - _admin_pwd
61+
# 5 - Username (Default: ldap_user)
62+
# Examples:
63+
# ds389_user_private_read "ldap://ldap.mydemo.lab:389" "dc=mydemo,dc=lab" "cn=Directory Manager" "secret" "ldap_user"
64+
#######################################
65+
function ds389_ldap_user_user_private_read() {
66+
local _ldap_uri="$1"
67+
local _ldap_basedn="$2"
68+
local _admin_user="$3"
69+
local _admin_pwd="$4"
70+
local ldap_user="$5"
71+
ldapmodify -D "${_admin_user}" -w "${_admin_pwd}" -x -H "${_ldap_uri}" << EOL
72+
dn: cn=user_private_read,ou=permissions,${_ldap_basedn}
73+
changetype: modify
74+
add: member
75+
member: uid=${ldap_user},ou=people,${_ldap_basedn}
76+
EOL
77+
}
78+
79+
#######################################
80+
# DS389 - Verify user has access
81+
# Arguments:
82+
# 1 - ldap user DN
83+
# 2 - ldap user pwd
84+
# 3 - _ldap_uri
85+
# 4 - _ldap_basedn
86+
# Examples:
87+
# ds389_ldap_user_access_check "cn=Directory Manager" "secret" "uid=ldap_user,ou=people,dc=mydemo,dc=lab" "mypassword"
88+
#######################################
89+
function ds389_ldap_user_access_check() {
90+
local _ldap_user_dn="${1}"
91+
local _ldap_user_pwd="${2}"
92+
local _ldap_uri="${3}"
93+
local _ldap_basedn="${4}"
94+
ldapsearch -x -D "${_ldap_user_dn}" -w "${_ldap_user_pwd}" -H "${_ldap_uri}" -b "${_ldap_basedn}"
95+
}
96+
97+
#######################################
98+
# DS389 - Install 389 Directory server
99+
# Arguments:
100+
# 1 - _ldap_uri
101+
# 2 - _ldap_basedn
102+
# 3 - _admin_user
103+
# 4 - _admin_pwd
104+
# Examples:
105+
# ds389_install "ldap://ldap.mydemo.lab:389" "dc=mydemo,dc=lab" "cn=Directory Manager" "secret"
106+
#######################################
107+
function ds389_install() {
108+
local _ldap_uri="${1}"
109+
local _ldap_basedn="${2}"
110+
local _admin_user="${3}"
111+
local _admin_pwd="${4}"
112+
# add the repo
113+
helm repo add suse-lab-setup https://opensource.suse.com/lab-setup
114+
helm repo update
115+
# installs the chart with default parameters
116+
if [[ -f values.yaml ]]
117+
then
118+
helm upgrade --install ds389 --namespace ds389 suse-lab-setup/ds389 -f values.yaml
119+
else
120+
helm upgrade --install ds389 --namespace ds389 suse-lab-setup/ds389
121+
fi
122+
sleep 60
123+
ds389_restrict_permissions "${_ldap_uri}" "${_ldap_basedn}" "${_admin_user}" "${_admin_pwd}"
124+
ds389_ldap_user_user_private_read "${_ldap_uri}" "${_ldap_basedn}" "${_admin_user}" "${_admin_pwd}" "ldap_user"
125+
}
126+
127+
#######################################
128+
# DS389 - Uninstall 389 Directory server
129+
# Examples:
130+
# ds389_uninstall
131+
#######################################
132+
function ds389_uninstall() {
133+
helm uninstall ds389
134+
sleep 15
135+
}

0 commit comments

Comments
 (0)