
KcMapper is a security auditing tool for Keycloak. It exports your Keycloak configuration (realms, clients, users, roles, etc.) into a Neo4j graph database. This representation enables complex relationship analysis and security auditing through a built-in interactive web UI with pre-defined queries.
KcMapper is a tool for exporting Keycloak configuration data into a Neo4j graph database. This representation allows for the analysis of relationships between realms, clients, users, groups, and roles. The tool includes a web interface to run pre-defined Cypher queries for analysis and security auditing.
webapp/queries.json file.This guide covers the local installation of KcMapper. This method requires you to install Python and Neo4j on your machine.
You can install Neo4j Community Edition by following these steps:
# Add the Neo4j GPG key
wget -O - https://debian.neo4j.com/neotechnology.gpg.key | sudo apt-key add -
# Add the Neo4j repository
echo 'deb https://debian.neo4j.com stable 5' | sudo tee /etc/apt/sources.list.d/neo4j.list
# Update packages and install Neo4j
sudo apt-get update
sudo apt-get install neo4j -y
# Start the Neo4j service
sudo systemctl start neo4j
After installation, navigate to http://localhost:7474 in your browser and set the initial password (the default is neo4j/neo4j).
For other systems (Windows, macOS, etc.):
Clone the repository
git clone https://github.com/synacktiv/kcmapper.git
cd kcmapper
Set up a Python virtual environment (recommended)
python -m venv venv
source venv/bin/activate # On Windows, use `venv\Scripts\activate`
Install dependencies
pip install -r requirements.txt
Configure environment variables
Copy the .env.example file to .env.
cp .env.example .env
Modify the .env file to point to your Keycloak instance and your local Neo4j database.
# --- Keycloak Connection ---
KEYCLOAK_URL=http://your-keycloak-server:8080/
KEYCLOAK_USER=admin
KEYCLOAK_PASSWORD=your_keycloak_admin_password
# Optional - for confidential clients
KEYCLOAK_CLIENT_SECRET=
# Optional - for users with 2FA enabled
KEYCLOAK_TOTP=
# Optional - for mTLS authentication
KEYCLOAK_CERT_PATH=
# --- Neo4j Connection (for local environment) ---
NEO4J_URI=bolt://localhost:7687
NEO4J_USER=neo4j
NEO4J_PASSWORD=your_local_neo4j_password
Export Data
Run the export command to populate your Neo4j database.
python kcmapper_cli.py export
--clean option:
python kcmapper_cli.py export --clean
Analyze Data Once the export is complete, launch the web analysis interface.
python kcmapper_cli.py analyze
kcmapper_cli.py: Main command-line entry point./processors: Contains the extraction and loading logic for each Keycloak object type./utils: Utility functions, primarily for Neo4j connection and data cleaning./webapp: Contains the Flask web application for data analysis.Contributions are welcome. Please feel free to open an issue to report a bug or suggest a new feature. To add new analysis queries, modify the webapp/queries.json file and submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.