Skip to content

Commit 001f679

Browse files
committed
adding godaddy tests
1 parent 0c954ed commit 001f679

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

enos/modules/verify_secrets_engines/modules/read/ldap.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ resource "enos_remote_exec" "ldap_verify_configs" {
1010

1111
environment = {
1212
MOUNT = "${var.create_state.ldap.ldap_mount}"
13+
LDAP_SERVER = "${var.create_state.ldap.host.private_ip}"
14+
LDAP_PORT = "${var.create_state.ldap.port}"
1315
LDAP_USERNAME = "${var.create_state.ldap.username}"
1416
LDAP_ADMIN_PW = "${var.create_state.ldap.pw}"
1517
VAULT_ADDR = var.vault_addr

enos/modules/verify_secrets_engines/scripts/ldap-configs.sh

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,29 @@ cat << EOF > ${GROUP_LDIF}
3333
dn: ou=users,dc=$LDAP_USERNAME,dc=com
3434
objectClass: organizationalUnit
3535
ou: users
36+
37+
dn: ou=groups,dc=$LDAP_USERNAME,dc=com
38+
objectClass: organizationalUnit
39+
ou: groups
3640
EOF
3741
ldapadd -x -H "ldap://${LDAP_SERVER}:${LDAP_PORT}" -D "cn=admin,dc=${LDAP_USERNAME},dc=com" -w "${LDAP_ADMIN_PW}" -f ${GROUP_LDIF}
3842

3943
echo "OpenLDAP: Creating User LDIF file and adding user to LDAP"
4044
USER_LDIF="user.ldif"
4145
cat << EOF > ${USER_LDIF}
46+
# User: enos
4247
dn: uid=$LDAP_USERNAME,ou=users,dc=$LDAP_USERNAME,dc=com
4348
objectClass: inetOrgPerson
44-
sn: user
49+
sn: $LDAP_USERNAME
4550
cn: $LDAP_USERNAME user
4651
uid: $LDAP_USERNAME
4752
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
4859
EOF
4960
ldapadd -x -H "ldap://${LDAP_SERVER}:${LDAP_PORT}" -D "cn=admin,dc=${LDAP_USERNAME},dc=com" -w "${LDAP_ADMIN_PW}" -f ${USER_LDIF}
5061

@@ -62,7 +73,6 @@ echo "Vault: Creating ldap auth and creating auth/ldap/config route"
6273
insecure_tls=true
6374

6475
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"
6676
"$binpath" write "auth/${MOUNT}/config" \
6777
url="ldap://${LDAP_SERVER}:${LDAP_PORT}" \
6878
binddn="cn=admin,dc=${LDAP_USERNAME},dc=com" \
@@ -81,5 +91,17 @@ path "secret/data/*" {
8191
capabilities = ["read", "list"]
8292
}
8393
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}"

enos/modules/verify_secrets_engines/scripts/ldap-verify-configs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ fail() {
1010
}
1111

1212
[[ -z "$MOUNT" ]] && fail "MOUNT env variable has not been set"
13+
[[ -z "$LDAP_SERVER" ]] && fail "LDAP_SERVER env variable has not been set"
14+
[[ -z "$LDAP_PORT" ]] && fail "LDAP_PORT env variable has not been set"
1315
[[ -z "$LDAP_USERNAME" ]] && fail "LDAP_USERNAME env variable has not been set"
1416
[[ -z "$LDAP_ADMIN_PW" ]] && fail "LDAP_ADMIN_PW env variable has not been set"
1517
[[ -z "$VAULT_ADDR" ]] && fail "VAULT_ADDR env variable has not been set"
@@ -21,5 +23,19 @@ test -x "$binpath" || fail "unable to locate vault binary at $binpath"
2123

2224
export VAULT_FORMAT=json
2325

24-
# Authenticate Using LDAP
25-
"$binpath" login -method=${MOUNT} username=${LDAP_USERNAME} password=${LDAP_ADMIN_PW}
26+
# Verifying LDAP Server Configs
27+
LDAP_UID=$(ldapsearch -x -LLL -H "ldap://${LDAP_SERVER}:${LDAP_PORT}" -b "dc=${LDAP_USERNAME},dc=com" -D "cn=admin,dc=${LDAP_USERNAME},dc=com" -w "${LDAP_ADMIN_PW}" "(uid=${LDAP_USERNAME})" 2>/dev/null)
28+
[[ -z "$LDAP_UID" ]] && fail "Could not search ldap server for uid: ${LDAP_USERNAME}"
29+
30+
# Authenticate Using Vault LDAP login
31+
VAULT_LDAP_LOGIN=$("$binpath" login -method=${MOUNT} username=${LDAP_USERNAME} password=${LDAP_ADMIN_PW})
32+
33+
# Verifying Vault LDAP Login Token
34+
VAULT_LDAP_TOKEN=$(echo $VAULT_LDAP_LOGIN | jq -r ".auth.client_token")
35+
[[ -z "$VAULT_LDAP_TOKEN" ]] && fail "Vault LDAP could not log in correctly: ${VAULT_LDAP_TOKEN}"
36+
37+
# Verifying Vault LDAP Policies
38+
VAULT_POLICY_COUNT=$(echo $VAULT_LDAP_LOGIN | jq -r ".auth.policies | length")
39+
[[ -z "$VAULT_POLICY_COUNT" ]] && fail "Vault LDAP number of policies does not look correct: ${VAULT_POLICY_COUNT}"
40+
41+
echo "${VAULT_LDAP_LOGIN}"

0 commit comments

Comments
 (0)