Neo4j has a Role-Based Access Control (RBAC) model that lets you manage users, roles, and permissions in the database. This is essential when you want to control who can read/write/delete which parts of the graph.
🔑 Neo4j Security: Users, Roles & Permissions
1. Users
A user has:
-
username
-
password
-
roles (one or more)
-
-
Users authenticate with
username/password
.
📌 Example:
2. Roles
-
Roles are collections of privileges.
-
A user can belong to multiple roles.
-
Built-in roles come with Neo4j, and you can also create custom roles.
📌 Assign role to a user:
3. Built-in Roles
Neo4j comes with some predefined roles:
Role | Permissions |
---|---|
reader | Can only read data (MATCH queries, no writes). |
publisher | Can read & write data (CREATE, MERGE, DELETE nodes/relationships). |
architect | Can do everything publisher can + create indexes & constraints. |
admin | Full access: manage users, roles, DB settings, all privileges. |
PUBLIC | All users have this role by default (minimal access, usually none). |
4. Privileges (Fine-grained access control)
If you use Neo4j Enterprise Edition, you get granular privileges.
Examples:
-
Read-only access to certain labels
-
Allow writes to specific labels
-
Restrict deletes
-
Allow procedure execution
5. Custom Roles
You can define your own roles to match business needs.
📌 Example: Create a developer
role with write access only to Project
nodes
📌 Assign to user:
6. Managing Users & Roles
-
List users
-
List roles
-
See role assignments
✅ Example Use Case: Social Network App
-
admin
→ can manage everything. -
analyst
→ can runMATCH
queries for reports. -
developer
→ canCREATE
/UPDATE
User
andPost
nodes, but cannot delete. -
moderator
→ can deletePost
nodes but notUser
nodes.
👉 In summary:
-
Users authenticate.
-
Roles define permissions.
-
You can use built-in roles or fine-grained custom privileges (Enterprise).
securing Neo4j connections with SSL/TLS is critical when running in production, especially if clients connect remotely.
Here’s a clear breakdown:
🔒 Securing Connections in Neo4j with SSL/TLS
Neo4j supports TLS/SSL encryption for:
-
Bolt protocol (used by drivers and Neo4j Browser)
-
HTTPS protocol (Neo4j Browser & REST API)
1. Generate Certificates
Neo4j requires certificates in X.509 format.
Options:
-
Use a trusted CA certificate (recommended for production).
-
Or use a self-signed certificate (for dev/test).
📌 Example: Generate a self-signed certificate
-
private.key
→ your private key -
public.crt
→ public certificate
Place them in the Neo4j certificates directory:
2. Certificate Directory Structure
Neo4j expects:
-
bolt/
→ used for driver connections -
https/
→ used for browser/REST API
3. Enable SSL in neo4j.conf
Edit conf/neo4j.conf
:
Values for dbms.connector.bolt.tls_level
:
-
DISABLED
→ no encryption -
OPTIONAL
→ supports both encrypted & unencrypted connections -
REQUIRED
→ only encrypted connections allowed (recommended for production)
4. Restart Neo4j
After updating config:
Neo4j now listens:
-
Bolt TLS:
bolt+s://localhost:7687
-
HTTPS TLS:
https://localhost:7473
5. Client Connection
When using drivers, specify secure scheme:
-
Python:
-
Java:
6. Production Best Practices
✅ Use CA-signed certs (not self-signed).
✅ Store private keys securely (permissions 600).
✅ Rotate certs before expiry.
✅ Disable unencrypted HTTP (dbms.connector.http.enabled=false
).
✅ Consider mutual TLS (client certs) if higher security is needed.
⚡ In short:
-
Put certs in
certificates/bolt
&certificates/https
. -
Configure
neo4j.conf
for TLS. -
Use
bolt+s
andhttps
schemes for secure connections.
Let’s go through Authentication & Authorization best practices for Neo4j, especially with a production deployment (like in Kubernetes/OpenShift).
🔑 Authentication & Authorization in Neo4j
Neo4j has built-in security features that you should enable and configure for production.
1. Enable Authentication
By default, authentication is enabled (auth-enabled=true
). Never disable it in production.
📌 In neo4j.conf
:
-
Default user is
neo4j
(you’ll be forced to set a password on first login). -
Use strong passwords and consider rotating them periodically.
2. Use Role-Based Access Control (RBAC)
Neo4j has predefined roles + custom roles (Enterprise Edition).
Predefined roles:
-
reader → read-only access
-
publisher → can read/write data
-
architect → can create/drop schema (indexes, constraints)
-
admin → full access, manage users/roles
📌 Example: Create a user and assign role:
👉 In OpenShift, you should store passwords in Kubernetes Secrets instead of hardcoding them.
3. Custom Roles (Enterprise Feature)
If you need fine-grained access:
✅ This way, Bob can only read Person nodes & KNOWS relationships, nothing else.
4. Principle of Least Privilege
-
Don’t give everyone
admin
. -
Developers → use
publisher
or a custom limited role. -
BI tools or dashboards → use
reader
. -
Automation pipelines → use separate service accounts with only the needed privileges.
5. Secure Password & Credential Handling
-
Store secrets in Kubernetes/OpenShift Secrets, mount them into pods as env vars.
-
Rotate credentials regularly.
-
For multiple apps using Neo4j, create separate service accounts (per-app isolation).
6. Enable TLS for Authentication
Combine with SSL/TLS setup (we discussed earlier):
-
Prevents password sniffing in plain text.
-
Use
bolt+s://
orhttps://
schemes.
7. Audit & Monitoring
-
Enable query logging and security logs.
Inneo4j.conf
:
-
Integrate logs with OpenShift logging stack (EFK or Loki).
8. Kubernetes/OpenShift Deployment Tips
-
Use K8s RBAC to restrict who can access Neo4j Secrets/ConfigMaps.
-
Run Neo4j pods with non-root users.
-
Set resource requests/limits for predictability.
-
Use NetworkPolicies in OpenShift to restrict Neo4j to only trusted services/namespaces.
✅ Summary:
-
Always enable
auth_enabled
. -
Use RBAC (built-in or custom roles).
-
Store secrets in K8s/OpenShift Secrets, not in config.
-
Use TLS for encrypted auth.
-
Apply least-privilege principle.
-
Enable security logs for audits.
Comments
Post a Comment