无法通过 LDAP 使用本地用户

问题描述 投票:0回答:2

我正在尝试将 apache 超集与 LDAP 集成。通过下面我将提供的配置,我可以使用 LDAP 用户登录 superset web,但同时我无法使用本地用户(例如在安装过程中创建的 admin)登录。有什么问题吗?

另外,我正在尝试使用“AUTH_ROLES_MAPPING”分割权限角色,但还没有成功。我怎样才能做到这一点?

from flask_appbuilder.security.manager import AUTH_OID
from flask_appbuilder.security.manager import AUTH_REMOTE_USER
from flask_appbuilder.security.manager import AUTH_DB
from flask_appbuilder.security.manager import AUTH_LDAP
#AUTH_TYPE = AUTH_LDAP
#AUTH_USER_REGISTRATION = True
#AUTH_USER_REGISTRATION_ROLE = "Public"

#AUTH_LDAP_SERVER = "ldap://10.10.0.50"
#AUTH_LDAP_USE_TLS = False
#AUTH_LDAP_BIND_USER = "CN=Administrator,CN=Users,DC=gru,DC=lab"
#AUTH_LDAP_BIND_PASSWORD = "password"
#AUTH_LDAP_SEARCH = "DC=gru,DC=lab"
#AUTH_LDAP_GROUP_FIELS="CN=linuxadmins,DC=gru,DC=lab"
#AUTH_LDAP_SEARCH = "DC=gru,DC=lab"
#AUTH_LDAP_UID_FIELD = "sAMAccountName"
#AUTH_LDAP_FIRSTNAME_FIELD = "givenName"
#AUTH_LDAP_LASTNAME_FIELD = "sn"

更新——我尝试过“AUTH_TYPE = 1|2”,也尝试过“AUTH_TYPE = AUTH_DB, AUTH_LDAP”。不幸的是没有结果。

authentication ldap flask-login apache-superset
2个回答
1
投票

为了同时使用本地和 LDAP 用户,您应该创建一个自定义安全管理器类,该类扩展 SupersetSecurityManager,但也覆盖其中的 AuthLDAPView 类。

首先创建一个文件(例如:custom_security_manager.py),用一个新类覆盖AuthLDAPView,用户可以使用LDAP和本地数据库帐户登录。通过 authldapview 参数将其添加到自定义安全管理器中以覆盖 AuthLDAPView 类

custom_security_manager.py:

from superset.security import SupersetSecurityManager
from flask_appbuilder.security.views import AuthLDAPView
from flask_appbuilder.security.views import expose
from flask import g, redirect, flash
from flask_appbuilder.security.forms import LoginForm_db
from flask_login import login_user
from flask_appbuilder._compat import as_unicode

class AuthLocalAndLDAPView(AuthLDAPView):
    @expose("/login/", methods=["GET", "POST"])
    def login(self):
        if g.user is not None and g.user.is_authenticated:
            return redirect(self.appbuilder.get_url_for_index)
        form = LoginForm_db()
        if form.validate_on_submit():
            user = self.appbuilder.sm.auth_user_ldap(
                form.username.data, form.password.data
            )
            if not user:
                user = self.appbuilder.sm.auth_user_db(
                    form.username.data, form.password.data
                )
            if user:
                login_user(user, remember=False)
                return redirect(self.appbuilder.get_url_for_index)
            else:
                flash(as_unicode(self.invalid_login_message), "warning")
                return redirect(self.appbuilder.get_url_for_login)
        return self.render_template(
            self.login_template, title=self.title, form=form, appbuilder=self.appbuilder
        )


class CustomSecurityManager(SupersetSecurityManager):
    authldapview = AuthLocalAndLDAPView
    def __init__(self, appbuilder):
        super(CustomSecurityManager, self).__init__(appbuilder)

Tnen 将其导入 superset_config.py 并使用“CustomSecurityManager”类作为安全管理器

superset_config.py:

import os
from superset.security import SupersetSecurityManager
from flask_appbuilder.security.manager import AUTH_DB,AUTH_LDAP
from custom_security_manager import CustomSecurityManager

AUTH_TYPE = AUTH_LDAP 
AUTH_USER_REGISTRATION = True
AUTH_USER_REGISTRATION_ROLE = "Public" 
AUTH_LDAP_SERVER = "ldaps://server.yourdomain.com:636"
AUTH_LDAP_USE_TLS = False
AUTH_LDAP_BIND_USER = "CN=Surname\, Name,OU=ouSystemAccounts,DC=yourdomain,DC=com"
AUTH_LDAP_BIND_PASSWORD = "password"
AUTH_LDAP_SEARCH = "DC=your_domain,DC=com,DC=tr"
AUTH_LDAP_UID_FIELD = "sAMAccountName"
AUTH_LDAP_ALLOW_SELF_SIGNED=True
AUTH_LDAP_APPEND_DOMAIN=False
AUTH_LDAP_FIRSTNAME_FIELD="givenName"
AUTH_LDAP_LASTNAME_FIELD="sn"
AUTH_LDAP_USE_TLS=False
AUTH_USER_REGISTRATION=True

CUSTOM_SECURITY_MANAGER = CustomSecurityManager

1
投票

要同时使用 LDAP 和数据库用户 - 您应该实现自定义 Superset 安全管理器,这将解决问题。

首先,您应该创建新文件,例如

my_security_manager.py
。将这些行放入其中:

from superset.security import SupersetSecurityManager


class MySecurityManager(SupersetSecurityManager):
    
    def __init__(self, appbuilder):
        super(MySecurityManager, self).__init__(appbuilder)

其次,您应该让 Superset 知道您想要使用全新的安全管理器。为此,请将这些行添加到您的 Superset 配置文件中 (

superset_config.py
):

from my_security_manager import MySecurityManager
CUSTOM_SECURITY_MANAGER = MySecurityManager

然后您可以使用自定义身份验证逻辑覆盖类的 auth_user_db(用户名, 密码) 方法。

© www.soinside.com 2019 - 2024. All rights reserved.