Skip to main content
Version: 1.4.0

Authentication and authorization (Enterprise)

In large organizations it is often difficult to manage permissions that staff members have in the organization. Organizations typically use an LDAP server to hold and manage the permissions. Because LDAP servers are already set-up in most large organizations, it is convenient for the organization to allow all staff members to have access to the database using the already available centralized user management system.

For this guide let's assume that we have an LDAP server that is serving the following data:

# Users root entrydn: ou=people,dc=memgraph,dc=comobjectclass: organizationalUnitobjectclass: topou: people
# User dbadn: cn=dba,ou=people,dc=memgraph,dc=comcn: dbaobjectclass: personobjectclass: topsn: useruserpassword: dba
# User alicedn: cn=alice,ou=people,dc=memgraph,dc=comcn: aliceobjectclass: personobjectclass: topsn: useruserpassword: alice
# User bobdn: cn=bob,ou=people,dc=memgraph,dc=comcn: bobobjectclass: personobjectclass: topsn: useruserpassword: bob
# User caroldn: cn=carol,ou=people,dc=memgraph,dc=comcn: carolobjectclass: personobjectclass: topsn: useruserpassword: carol
# User davedn: cn=dave,ou=people,dc=memgraph,dc=comcn: daveobjectclass: personobjectclass: topsn: useruserpassword: dave
# Roles root entrydn: ou=roles,dc=memgraph,dc=comobjectclass: organizationalUnitobjectclass: topou: roles
# Role moderatordn: cn=moderator,ou=roles,dc=memgraph,dc=comcn: moderatormember: cn=alice,ou=people,dc=memgraph,dc=comobjectclass: groupOfNamesobjectclass: top
# Role admindn: cn=admin,ou=roles,dc=memgraph,dc=comcn: adminmember: cn=carol,ou=people,dc=memgraph,dc=commember: cn=dave,ou=people,dc=memgraph,dc=comobjectclass: groupOfNamesobjectclass: top

To summarize, in this dataset we have the following data:

  • ou=people,dc=memgraph,dc=com - entry that holds all users
    • cn=dba,ou=people,dc=memgraph,dc=com - user dba that will be used as the database administrator
    • cn=alice,ou=people,dc=memgraph,dc=com - regular user alice
    • cn=bob,ou=people,dc=memgraph,dc=com - regular user bob
    • cn=carol,ou=people,dc=memgraph,dc=com - regular user carol
    • cn=dave,ou=people,dc=memgraph,dc=com - regular user dave
  • ou=roles,dc=memgraph,dc=com - entry that holds all roles
    • cn=moderator,ou=roles,dc=memgraph,dc=com - role moderator that has alice as its member
    • cn=admin,ou=roles,dc=memgraph,dc=com - role admin that has carol and dave as its members

For detailed information about the LDAP integration you should first see the reference guide: LDAP security.


Before enabling LDAP authentication, Memgraph should be prepared for the integration. Here we assume that you have an already running Memgraph instance that doesn't have any users in its local authentication storage. For more details on how the native authentication storage works in Memgraph you should see: User privileges.

First you should create the user that should be the database administrator. It is important to have in mind that the username that you create must exist in the LDAP directory. For the described LDAP directory we will connect to the database and issue the following queries all in the same connection:


After the user is created and all privileges are granted, it is safe to disconnect from the database and proceed with LDAP integration.

To enable LDAP integration you should specify the following flag to Memgraph:


You should also have the following LDAP module configuration in /etc/memgraph/auth_module/ldap.yaml:

server:  host: "<LDAP_SERVER_HOSTNAME>"  port: <LDAP_SERVER_PORT>  encryption: "disabled"  cert_file: ""  key_file: ""  ca_file: ""  validate_cert: false
users:  prefix: "cn="  suffix: ",ou=people,dc=memgraph,dc=com"
roles:  root_dn: ""  root_objectclass: ""  user_attribute: ""  role_attribute: ""

You should adjust the security settings according to your LDAP server security settings.

After setting these configuration options you should restart your Memgraph instance.

Now you can verify that you can still log in to the database using username dba and password dba.

Issuing SHOW USERS; should list that currently only user dba exists. This is normal. It means that LDAP authentication is successfully enabled (because you were able to log in) and no other users have yet logged in.

You should now be able to log in using username alice and password alice. Because Alice has never before logged in to the database a new user will be created for Alice and she won't have any privileges (yet).

Using user dba we modify Alice's privileges to include the MATCH privilege.


After Alice logs in again into the database (to refresh her privileges) she will be able to execute the following query:


Issuing SHOW USERS; as dba should now yield both dba and alice.

Users Bob, Carol and Dave will also be able to log in to the database using their LDAP password. As with Alice, their users will be created and won't have any privileges.

If automatic user account creation is disabled using the database flag:


The database administrator (user dba) will first have to explicitly create the users that he wishes to allow to connect to the database:


In this scenario only Alice and Bob will be allowed to log in to the database because they already have existing user accounts, but users Carol and Dave won't be able to log in.


In the previous example users could only authenticate using LDAP. In this example we will explain how to set-up the LDAP auth module to deduce the user's role using LDAP search queries.

First, you should enable and verify that user authentication works. To enable role mapping for the described LDAP schema, we will modify the LDAP auth module configuration file, specifically the section roles, to have the following content:

roles:  root_dn: "ou=roles,dc=memgraph,dc=com"  root_objectclass: "groupOfNames"  user_attribute: "member"  role_attribute: "cn"

This configuration tells the LDAP module that all role mapping entries are children of the ou=roles,dc=memgraph,dc=com entry, that the children have user DNs specified in their member attribute and that the cn attribute should be used to determine the role name.

When a user logs in to the database, the LDAP auth module will go through all role mapping entries and will try to find out which role mapping entry has the user as its member.

So now when Alice logs in, the LDAP auth module will go through the following entries: cn=admin,ou=roles,dc=memgraph,dc=com and cn=moderator,ou=roles,dc=memgraph,dc=com. Because Alice is a member of the moderator role mapping, the LDAP auth module will assign role moderator to Alice.

Now as the user dba we can issue SHOW ROLE FOR alice; and we will see that indeed Alice now has the role moderator.

Permissions for users and roles are still managed through Memgraph, they can't be managed through the LDAP server.

If automatic role creation is disabled using the flag:


The database administrator (user dba) will first have to explicitly create the role for users that he wishes to allow to connect to the database:

CREATE ROLE moderator;

In this scenario only Alice and Bob will be allowed to log in. Alice will be allowed to log in because her role (moderator) already exists. Bob will be allowed to log in because he doesn't have any role. Carol and Dave won't be allowed to log in because their role (administrator) doesn't exist.

If both automatic role creation and automatic user creation are disabled, then both the user and the role must exist for a user to successfully log in to the database.

Where to next?#

To learn more about Memgraph's functionalities, visit the Reference guide. For real-world examples of how to use Memgraph, we strongly suggest going through one of the available Tutorials.