The Simplest Way to Make Keycloak and Neo4j Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Using keycloak and neo4j together lets teams log in to graph databases with single sign-on. Keycloak checks user identity and passes role claims to Neo4j to control data permissions. This setup removes local database accounts from your production workflows. Engineers use one central login to read or change graph data. Your security team manages all user groups in one place. How keycloak and neo4j handle logins and roles Keycloak acts as your central identity provider using standard web protoc

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

Using keycloak and neo4j together lets teams log in to graph databases with single sign-on. Keycloak checks user identity and passes role claims to Neo4j to control data permissions. This setup removes local database accounts from your production workflows. Engineers use one central login to read or change graph data. Your security team manages all user groups in one place.

How keycloak and neo4j handle logins and roles

Keycloak acts as your central identity provider using standard web protocols. A user or app logs in to Keycloak first. Keycloak checks the user credentials and group memberships. Then it issues a signed token that holds those group names. The user sends this token to the Neo4j database server. Neo4j checks the digital signature against the public keys from Keycloak.

Next, the database reads the group claims inside the token. Neo4j maps those external groups to its own internal database roles. A read-only group maps to a reader role in the graph. An admin group maps to a role that can change nodes. This flow keeps password rules and multi-factor checks inside Keycloak. The database only handles graph queries and role checks.

When a person leaves the team, you block them in Keycloak. They lose database permissions right away without touching the graph server. You do not need to hunt down local accounts across clusters. Every database node trusts the same identity server for user checks.

Common risks with shared accounts and broad tokens

Many teams skip token mapping when they rush to ship apps. They create one shared database account with full admin rights instead. Every developer and backend service uses that same password. When a bad query deletes nodes, the audit log shows one shared name. You cannot tell which person or script ran the destructive command.

Broad tokens create another big problem for production graph databases. If a token lasts for days, a leaked token gives attackers plenty of time. If every group maps to the main admin role, any user can drop data. Graph queries can also return sensitive properties like emails, phone numbers, or card numbers. Standard role checks grant or block whole labels, not single fields in a result.

Keycloak + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

To fix this, scope your Keycloak groups to match real job tasks. Give most engineers a role that only reads graph structure and safe fields. Keep write permissions for specific migration tasks or backend apps. Set short lifetimes on all tokens issued by your identity server. Make sure your network rules only allow database traffic from approved subnets.

Auditing graph queries and masking sensitive fields

Role mapping alone does not solve every audit need in production. Standard identity tokens only verify who starts a database session. They do not record the exact Cypher queries a user runs after logging in. Security teams often need a clear log of every query and its user. They also need a way to protect private data during fixing.

Production graphs often store user profiles with national IDs or phone numbers. Developers need to test graph traversals without exposing those raw values. Data masking rewrites matched fields in query results before they reach the screen. This lets engineers fix query performance while keeping private user details safe. Combining identity checks with query logs and field masking completes your setup.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

How does Neo4j verify tokens from Keycloak?

Neo4j fetches public keys from the Keycloak discovery endpoint. It uses these keys to check the signature and expiration time on each login token.

Can we map multiple Keycloak groups to different graph roles?

Yes, you can map several external groups to specific database roles. If a user belongs to multiple groups, Neo4j combines the permissions from each mapped role.

How do we protect emails and card numbers in graph query results?

Database roles control node and property permissions at a broad level. To hide emails or card numbers in live results, use data masking to rewrite matched fields.

The query runs. The emails stay hidden.