Skip to content

Commit e63e1e4

Browse files
author
Joël-Franck HOSSIE
committed
Fix ldap search with pagination bug
When making a ldap search, the pagination was managed both by the ldap search library and the calling code. This lead to a fatal error when the number of results exceeded the page size. This issue has been fixed by removing the pagination management in the calling code. The pagination is thus managed only by the ldap library
1 parent ad95bbf commit e63e1e4

File tree

7 files changed

+70
-633
lines changed

7 files changed

+70
-633
lines changed

internal/ldap/calls.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,11 @@ func (c *LDAPClient) Query(request ldap.SearchRequest) ([]*ldap.Entry, error) {
7575
}
7676
defer conn.Close()
7777

78-
var allResults []*ldap.Entry
79-
for {
80-
results, err := conn.SearchWithPaging(&request, c.PageSize)
81-
if err != nil {
82-
return nil, fmt.Errorf("error searching in LDAP with request %v, %v", request, err)
83-
}
84-
allResults = append(allResults, results.Entries...)
85-
if len(results.Entries) < int(c.PageSize) {
86-
break
87-
}
88-
request.Controls = results.Controls
78+
results, err := conn.SearchWithPaging(&request, c.PageSize)
79+
if err != nil {
80+
return nil, fmt.Errorf("error searching in LDAP with request %v, %v", request, err)
8981
}
90-
return allResults, nil
82+
return results.Entries, err
9183
}
9284

9385
func (c *LDAPClient) getGroupsContainingUser(userDN string) ([]*ldap.Entry, error) {

internal/ldap/projectname-from-ldap.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ func (c *LDAPClient) getProjectGroups() ([]string, error) {
1212
BaseDN: c.GroupBase,
1313
Scope: ldap.ScopeWholeSubtree,
1414
DerefAliases: ldap.NeverDerefAliases,
15-
SizeLimit: 0, // limit number of entries in result, 0 values means no limitations
1615
TimeLimit: 30,
1716
TypesOnly: false,
1817
Filter: "(|(objectClass=groupOfNames)(objectClass=group))", // filter default format : (&(objectClass=groupOfNames)(member=%s))

test/e2e/bootstrap-fixtures-test-e2e.sh

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ if [ ! "$GITHUB_ACTIONS" = "true" ]; then
1313
export http_proxy=${PROXY_URL}
1414
export https_proxy=${PROXY_URL}
1515
fi
16+
#Ldap
17+
18+
LDAP_IMAGE="docker-remote.registry.saas.cagip.group.gca/bitnamilegacy/openldap:2.6.10-debian-12-r4"
19+
docker pull ${LDAP_IMAGE}
20+
1621

1722
# KIND CLUSTER CREATION
1823
kind delete cluster --name test-e2e-kubi
@@ -22,9 +27,11 @@ kind create cluster --name test-e2e-kubi --config test/e2e/conf/kind/cluster-kin
2227
helm repo add helm-openldap https://jp-gouin.github.io/helm-openldap/
2328

2429
# Create configmap containing ldif file
25-
kubectl -n kube-system apply -f test/e2e/conf/openldap/config.yaml
26-
helm upgrade --install openldap helm-openldap/openldap-stack-ha -f test/e2e/conf/openldap/myvalues.yaml --namespace kube-system
27-
# We wait 30s for Openldap to pop otherwise, Kubi tries to connect to it directly,
30+
kind load docker-image --name test-e2e-kubi ${LDAP_IMAGE}
31+
INSTALL_FOLDER_LDAP="test/e2e/conf/openldap"
32+
kubectl apply -f ${INSTALL_FOLDER_LDAP}/config.yaml
33+
kubectl apply -f ${INSTALL_FOLDER_LDAP}/deploy.yaml
34+
# We wait 60s for Openldap to pop otherwise, Kubi tries to connect to it directly,
2835
# fails to open a connection and waits for a new reconciliation loop to occur,
2936
# which makes the fail test, due to 30s timeout (in e2e_test.go file.)
3037

@@ -37,7 +44,7 @@ sleep 60
3744
# kubi-encryption-secret -> the PKI which signs the tokens
3845
# kubi -> i think it's the authn cert to api server. Unsure
3946

40-
kubectl -n kube-system create secret generic kubi-secret --from-literal ldap_passwd='Not@SecurePassw0rd'
47+
kubectl -n kube-system create secret generic kubi-secret --from-literal ldap_passwd='adminpassword'
4148
./scripts/generate_ecdsa_keys.sh
4249
kubectl -n kube-system create secret generic kubi-encryption-secret --from-file=/tmp/kubi/ecdsa/ecdsa-key.pem --from-file=/tmp/kubi/ecdsa/ecdsa-public.pem
4350

test/e2e/conf/kubi/configmap.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ data:
55
LDAP_ADMIN_GROUPBASE: CN=ADMIN_KUBERNETES,OU=TEAMS,OU=Groups,DC=example,DC=org
66
LDAP_ADMIN_USERBASE: OU=Users,DC=example,DC=org
77
LDAP_APP_GROUPBASE: CN=CAGIP_MEMBERS,OU=TEAMS,OU=Groups,DC=example,DC=org
8-
LDAP_BINDDN: CN=admin,DC=example,DC=org # Not like that , should container O=Example but does not work for some reason
8+
LDAP_BINDDN: CN=admin,DC=example,DC=org # Not like that , should container O=Example but does not work for some reason
99
LDAP_CUSTOMER_OPS_GROUPBASE: CN=DL_KUB_CAGIPHP_OPS,OU=HORS-PROD,OU=CAGIP,OU=CONTAINER,OU=Groups,DC=example,DC=org
1010
LDAP_GROUPBASE: OU=HORS-PROD,OU=CAGIP,OU=CONTAINER,OU=Groups,DC=example,DC=org
1111
LDAP_OPS_GROUPBASE: CN=CLOUDOPS_KUBERNETES,OU=TEAMS,OU=Groups,DC=example,DC=org
1212
LDAP_PORT: "389"
1313
LDAP_ELIGIBLE_GROUPS_PARENTS: OU=CONTAINER,OU=Groups,DC=example,DC=org|OU=TEAMS,OU=Groups,DC=example,DC=org
14-
LDAP_PAGE_SIZE: "500"
14+
LDAP_PAGE_SIZE: "2"
1515
LDAP_SERVER: openldap.kube-system.svc.cluster.local
1616
LDAP_SERVICE_GROUPBASE: CN=DL_KUB_TRANSVERSAL_SERVICE,OU=CONTAINER,OU=Groups,DC=example,DC=org
1717
LDAP_USE_SSL: "false"

test/e2e/conf/openldap/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,4 +384,5 @@ data:
384384
kind: ConfigMap
385385
metadata:
386386
name: ldapconf
387+
namespace: kube-system
387388

test/e2e/conf/openldap/deploy.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
labels:
5+
app: openldap
6+
name: openldap
7+
namespace: kube-system
8+
spec:
9+
replicas: 1
10+
selector:
11+
matchLabels:
12+
app: openldap
13+
strategy: {}
14+
template:
15+
metadata:
16+
labels:
17+
app: openldap
18+
spec:
19+
volumes:
20+
- name: "ldapconfig"
21+
configMap:
22+
name: ldapconf
23+
containers:
24+
- image: docker-remote.registry.saas.cagip.group.gca/bitnamilegacy/openldap:2.6.10-debian-12-r4
25+
imagePullPolicy: IfNotPresent
26+
name: openldap
27+
env:
28+
- name: LDAP_ROOT
29+
value: "dc=example,dc=org"
30+
volumeMounts:
31+
- name: ldapconfig
32+
mountPath: /ldifs
33+
resources: {}
34+
35+
---
36+
37+
apiVersion: v1
38+
kind: Service
39+
metadata:
40+
labels:
41+
app: openldap
42+
name: openldap
43+
namespace: kube-system
44+
spec:
45+
ports:
46+
- port: 389
47+
protocol: TCP
48+
targetPort: 1389
49+
selector:
50+
app: openldap
51+
status:
52+
loadBalancer: {}

0 commit comments

Comments
 (0)