Can't filter or retrieve by custom attribute in LDAP using ldapsearch

Solution 1:

I needed to mount a schema file to /container/service/slapd/assets/config/bootstrap/schema/custom with the custom attributes. I made a file schema/custom.schema with the following contents:

attributetype ( 2.25.1 NAME 'rank' DESC 'User Rank' EQUALITY integerMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.27 ) 
objectclass ( 2.25 NAME 'rankPerson' DESC 'A user with a rank' SUP inetOrgPerson STRUCTURAL MUST ( rank ) )

And then I mounted it into my docker container

docker run \
        --env LDAP_DOMAIN="example.com" \
        -p 389:389 -p 636:636 \
        --volume ldif:/container/service/slapd/assets/config/bootstrap/ldif/custom \
        --volume schema:/container/service/slapd/assets/config/bootstrap/schema/custom \
        --name my-openldap-container   osixia/openldap:1.5.0 --copy-service --loglevel debug

And now I can filter by rank

~/% docker exec my-openldap-container ldapsearch -x -H ldap://localhost -b dc=example,dc=com -D "cn=admin,dc=example,dc=com" -w admin "(rank=3)"
# extended LDIF
#
# LDAPv3
# base <dc=example,dc=com> with scope subtree
# filter: (rank=3)
# requesting: ALL
#

# developer, example.com
dn: cn=developer,dc=example,dc=com
objectClass: rankPerson
cn: developer
givenName: developer
sn: Developer
displayName: Developer User
mail: [email protected]
userPassword:: ZGV2ZWxvcGVyX3Bhc3M=
rank: 3

# search result
search: 2
result: 0 Success

# numResponses: 2
# numEntries: 1