Sentry & Keycloak SAML2 Integration
This guide explains how to integrate Keycloak (as Identity Provider) with Sentry (as Service Provider) using SAML2 authentication, for secure and controlled Single Sign-On (SSO) within the TechFinite infrastructure.
๐ง Prerequisites
โ Keycloak server running at
https://keycloak.techfinite.com
โ Sentry (self-hosted) running at
https://sentry.techfinite.com
โ Admin access to both systems
โ Docker & Docker Compose set up for Sentry
๐ ๏ธ Step 1: Create SAML Client in Keycloak
Login to Keycloak Admin Console.
Navigate to your Realm โ Clients โ Create.
Set:
Client ID:
https://<sentry-host>/saml/metadata/<org-slug name>/
Client Protocol:
saml
Click Save.
Client Settings:
Field | Value |
---|---|
Sign Assertions | OFF |
Encrypt Assertions | OFF |
Client Signature Required | OFF |
Force POST Binding | ON |
Name ID Format |
|
Valid Redirect URIs |
|
Assertion Consumer Service URL |
|
Logout Service POST URL |
|
๐งฉ Step 2: Setup Attribute Mapper in Keycloak
Delete default "role list" mapper.
Go to Mappers โ Add Builtin โ X500 Email.
Edit the new mapper:
SAML Attribute Name:
user_email
๐ฏ Step 3: Configure SAML2 in Sentry
Open Sentry web UI โ Organization Settings โ Auth โ SAML2.
Use Metadata URL:
ruby https://<Keycloak-host>/realms/<realm-name>/protocol/saml/descriptor
Set Attribute Mappings:
IdP User ID:
user_email
User Email:
user_email
โ๏ธ Step 4: Configure Sentry Server (.env
+ sentry.conf.py
)
Edit .env
in ~/self-hosted/
:
env
SENTRY_SSO_DEFAULT_LOGIN=false
SENTRY_SSO_AUTO_LINK=false
Edit /etc/sentry/sentry.conf.py
inside the container:
bash
docker compose exec web bash
echo "SENTRY_FEATURES['auth:register'] = False" >> /etc/sentry/sentry.conf.py
Optional (for password login backup):
python
SENTRY_FEATURES['auth:login'] = True
Then restart:
bash
docker compose restart web
๐งช Step 5: Testing
โ Expected
Scenario | Result |
---|---|
Invited user logs in via SAML | Login successful |
Uninvited user logs in via SAML | Login blocked |
Admin uses password | Login successful (if enabled) |
๐งจ Common Errors & Fixes
Problem | Solution |
---|---|
SAML creates user without invite | Set |
Only SAML login visible | Add dummy Google provider or enable |
Invalid request in Keycloak | Use correct Client ID & Metadata URL |
SAML auto-logs into admin | Disable auto-link: |
SAML login fails silently | Check attribute mapping & Keycloak email presence |