@@ -33,18 +33,29 @@ cat << EOF > ${GROUP_LDIF}
33
33
dn: ou=users,dc=$LDAP_USERNAME ,dc=com
34
34
objectClass: organizationalUnit
35
35
ou: users
36
+
37
+ dn: ou=groups,dc=$LDAP_USERNAME ,dc=com
38
+ objectClass: organizationalUnit
39
+ ou: groups
36
40
EOF
37
41
ldapadd -x -H " ldap://${LDAP_SERVER} :${LDAP_PORT} " -D " cn=admin,dc=${LDAP_USERNAME} ,dc=com" -w " ${LDAP_ADMIN_PW} " -f ${GROUP_LDIF}
38
42
39
43
echo " OpenLDAP: Creating User LDIF file and adding user to LDAP"
40
44
USER_LDIF=" user.ldif"
41
45
cat << EOF > ${USER_LDIF}
46
+ # User: enos
42
47
dn: uid=$LDAP_USERNAME ,ou=users,dc=$LDAP_USERNAME ,dc=com
43
48
objectClass: inetOrgPerson
44
- sn: user
49
+ sn: $LDAP_USERNAME
45
50
cn: $LDAP_USERNAME user
46
51
uid: $LDAP_USERNAME
47
52
userPassword: $LDAP_ADMIN_PW
53
+
54
+ # Group: devs
55
+ dn: cn=devs,ou=groups,dc=$LDAP_USERNAME ,dc=com
56
+ objectClass: groupOfNames
57
+ cn: devs
58
+ member: uid=$LDAP_USERNAME ,ou=users,dc=$LDAP_USERNAME ,dc=com
48
59
EOF
49
60
ldapadd -x -H " ldap://${LDAP_SERVER} :${LDAP_PORT} " -D " cn=admin,dc=${LDAP_USERNAME} ,dc=com" -w " ${LDAP_ADMIN_PW} " -f ${USER_LDIF}
50
61
@@ -62,7 +73,6 @@ echo "Vault: Creating ldap auth and creating auth/ldap/config route"
62
73
insecure_tls=true
63
74
64
75
echo " Vault: Updating ldap auth and creating auth/ldap/config route"
65
- " $binpath " auth enable " ${MOUNT} " > /dev/null 2>&1 || echo " Warning: Vault ldap auth already enabled"
66
76
" $binpath " write " auth/${MOUNT} /config" \
67
77
url=" ldap://${LDAP_SERVER} :${LDAP_PORT} " \
68
78
binddn=" cn=admin,dc=${LDAP_USERNAME} ,dc=com" \
@@ -81,5 +91,17 @@ path "secret/data/*" {
81
91
capabilities = ["read", "list"]
82
92
}
83
93
EOF
84
- " $binpath " policy write reader " ${VAULT_LDAP_POLICY} "
85
- " $binpath " write " auth/${MOUNT} /users/${LDAP_USERNAME} " policies=" reader"
94
+ LDAP_READER_POLICY=" reader-policy"
95
+ " $binpath " policy write ${LDAP_READER_POLICY} " ${VAULT_LDAP_POLICY} "
96
+ " $binpath " write " auth/${MOUNT} /users/${LDAP_USERNAME} " policies=" ${LDAP_READER_POLICY} "
97
+
98
+ echo " Vault: Creating Vault Policy for LDAP DEV and assigning user to policy"
99
+ VAULT_LDAP_DEV_POLICY=" ldap_dev.hcl"
100
+ cat << EOF > ${VAULT_LDAP_DEV_POLICY}
101
+ path "secret/data/dev/*" {
102
+ capabilities = ["read", "list"]
103
+ }
104
+ EOF
105
+ LDAP_DEV_POLICY=" dev-policy"
106
+ " $binpath " policy write ${LDAP_DEV_POLICY} " ${VAULT_LDAP_DEV_POLICY} "
107
+ " $binpath " write " auth/${MOUNT} /groups/devs" policies=" ${LDAP_DEV_POLICY} "
0 commit comments