how to configure superset with keycloak #13915
-
I am trying to add keycloak authentication any recommendation |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 29 replies
-
Hi @ouadhi there aren't any templates off-hand for this in the Superset documentation (superset.apache.org/docs) but this StackOverflow answer might be helpful: https://stackoverflow.com/a/47787279/963203 If you end up getting it working, we'd love to see you contribute the recipe to the documentation! |
Beta Was this translation helpful? Give feedback.
-
hi @srinify , it works perfectly now , rom flask_appbuilder.security.manager import AUTH_OID
from superset.security import SupersetSecurityManager
from flask_oidc import OpenIDConnect
from flask_appbuilder.security.views import AuthOIDView
from flask_login import login_user
from urllib.parse import quote
from flask_appbuilder.views import ModelView, SimpleFormView, expose
import logging
class OIDCSecurityManager(SupersetSecurityManager):
def __init__(self, appbuilder):
super(OIDCSecurityManager, self).__init__(appbuilder)
if self.auth_type == AUTH_OID:
self.oid = OpenIDConnect(self.appbuilder.get_app)
self.authoidview = AuthOIDCView
class AuthOIDCView(AuthOIDView):
@expose('/login/', methods=['GET', 'POST'])
def login(self, flag=True):
sm = self.appbuilder.sm
oidc = sm.oid
@self.appbuilder.sm.oid.require_login
def handle_login():
user = sm.auth_user_oid(oidc.user_getfield('email'))
if user is None:
info = oidc.user_getinfo(['preferred_username', 'given_name', 'family_name', 'email'])
user = sm.add_user(info.get('preferred_username'), info.get('given_name'), info.get('family_name'),
info.get('email'), sm.find_role('Gamma'))
login_user(user, remember=False)
return redirect(self.appbuilder.get_url_for_index)
return handle_login()
@expose('/logout/', methods=['GET', 'POST'])
def logout(self):
oidc = self.appbuilder.sm.oid
oidc.logout()
super(AuthOIDCView, self).logout()
redirect_url = request.url_root.strip('/') + self.appbuilder.get_url_for_login
return redirect(
oidc.client_secrets.get('issuer') + '/protocol/openid-connect/logout?redirect_uri=' + quote(redirect_url)) create another json file "client_secret.json" contains keycloack configuration {
"web": {
"issuer": "http://keyclaokdomain/auth/realms/<realmName>",
"auth_uri": "http://keyclaokdomain/auth/realms/<realmName>/protocol/openid-connect/auth",
"client_id": "<ClientID>",
"client_secret": "<Client Secret>",
"redirect_uris": [
"http://domaineApp/*"
],
"userinfo_uri": "http://keyclaokdomain/auth/realms/<realmName>/protocol/openid-connect/userinfo",
"token_uri": "http://keyclaokdomain/auth/realms/<realmName>/protocol/openid-connect/token",
"token_introspection_uri": "http://keyclaokdomain/auth/realms/<realmName>/protocol/openid-connect/token/introspect"
}
}
finally in superset_config.py add lines from kyecloack_securtiy_manager import OIDCSecurityManager
from flask_appbuilder.security.manager import AUTH_OID, AUTH_REMOTE_USER, AUTH_DB, AUTH_LDAP, AUTH_OAUTH
import os
'''
---------------------------KEYCLOACK ----------------------------
'''
curr = os.path.abspath(os.getcwd())
AUTH_TYPE = AUTH_OID
SECRET_KEY: 'SomethingNotEntirelySecret'
OIDC_CLIENT_SECRETS = curr + '/pythonpath/client_secret.json'
OIDC_ID_TOKEN_COOKIE_SECURE = False
OIDC_REQUIRE_VERIFIED_EMAIL = False
OIDC_OPENID_REALM: 'realm1'
OIDC_INTROSPECTION_AUTH_METHOD: 'client_secret_post'
CUSTOM_SECURITY_MANAGER = OIDCSecurityManager
AUTH_USER_REGISTRATION = True
AUTH_USER_REGISTRATION_ROLE = 'Gamma'
'''
--------------------------------------------------------------
''' |
Beta Was this translation helpful? Give feedback.
-
@ouadhi I followed the same but when I visit the http://:8088/login it is not redirecting me to keycloack for openId auth rather its appending URL like http://:8088/login/<keycloak_domain>:8080/. are there any specific config needed n keyclaok because the oidc callback url is not redirecting to superset home page. |
Beta Was this translation helpful? Give feedback.
-
Hi! Is there anyone here who have tried pass:
The whole flow of keycloak works well, I've tried to add |
Beta Was this translation helpful? Give feedback.
-
I may have done something wrong, but to get around an error:
I added this line:
in the docker-bootstrap.sh file about here: To check it is running, add an echo before it like:
Hope that helps someone else. Or if someone can tell me why I don't need to do that and should instead do another thing, please let me know. Otherwise, I'm able to login with keycloak and it adds my user from the login. |
Beta Was this translation helpful? Give feedback.
-
I managed to solve the integration and Its working like a charm, check the code in github superset-keycloak |
Beta Was this translation helpful? Give feedback.
hi @srinify , it works perfectly now ,
first , i add flask-oidc==1.3.0 in requirement.test
in docker/pythonpath_dev create file kyecloack_securtiy_manager.py and add this code