Logo
登录认证

登录认证 #

密码认证 #

DBPlusEngine-Proxy 默认使用密码认证方式,配置格式如下:

authority:
  users:
    - user: root@root
      password: root
    - user: sharding
      password: sharding

该配置中为 DBPlusEngine 指定了两个用户:

  • root: @% 表示该用户可以通过任意 host 访问 DBPlusEngine,password 指定了密码为 root。
  • sharding: 该用户没有指定 host 配置,默认值同样为 @%password 指定了密码为 sharding

当管理员需要限制特定用户的登录主机时,可以通过 username@host 这样的方式来指定,如:

- user: user1@192.168.1.111
  password: user1_password

表示 user1 用户只能通过 192.168.1.111 这个地址访问 DBPlusEngine,认证密码是 user1_password

LDAP 认证 #

说明:

  • 在启用 LDAP 认证之前,用户应先行部署 LDAP 服务器,如 OpenLDAP
  • 当使用 MySQL 客户端时,需显示开启 cleartext-plugin,如: mysql -h 127.0.0.1 -P 3307 -u root -p –enable-cleartext-plugin

在 DBPlusEngine 中配置 LDAP 的方式如下:

示例 1 #

每个用户都需要经过 LDAP 认证,且使用相同的 DN 模板。

authority:
  users:
    - user: root@%
    - user: sharding
  authenticators:
    auth_ldap:
      type: LDAP
      props:
        ldap_server_url: ldap://localhost:389
        ldap_dn_template: cn={0},ou=users,dc=example,dc=org
  defaultAuthenticator: auth_ldap

该配置指定了一个身份认证器 auth_ldap,它的类型为 LDAPprops 中给出了必要的配置:

  • ldap_server_url: LDAP 服务器的访问地址
  • ldap_dn_template:用户 DN 模板

在使用以上配置时,用户 rootsharding 对应的用户 DN 分别是:

  • root:cn=root,ou=users,dc=example,dc=org
  • sharding:cn=sharding,ou=users,dc=example,dc=org

示例2 #

每个用户都需要经过 LDAP 认证,但使用不同的 DN 模板。

authority:
  users:
    - user: root@%
      props:
        ldap_dn: cn=root,ou=admin,dc=example,dc=org
    - user: sharding
  authenticators:
    auth_ldap:
      type: LDAP
      props:
        ldap_server_url: ldap://localhost:389
        ldap_dn_template: cn={0},ou=users,dc=example,dc=org
  defaultAuthenticator: auth_ldap

示例1 的区别是: 用户 root 与其他用户不在同一个 ou 中,因此为 root 单独指定了明确的用户 DN。 在使用以上配置时,用户 rootsharding 对应的用户 DN 分别是:

  • root:cn=root,ou=admin,dc=example,dc=org
  • sharding:cn=sharding,ou=users,dc=example,dc=org

混合认证 #

混合认证意味着部分用户使用密码认证方式,另一部分用户使用 LDAP 认证方式,这是一种非常灵活的搭配,可满足特定安全场景的需要。

混合认证配置格式如下:

authority:
  users:
    - user: root@%
      auth: auth_ldap
    - user: sharding
      password: sharding
    - user: user1
      password: password_user1
  authenticators:
    auth_ldap:
      type: LDAP
      props:
        ldap_server_url: ldap://localhost:389
        ldap_dn_template: cn={0},ou=users,dc=example,dc=org

在以上配置中,没有指定 defaultAuthenticator,默认为使用密码认证方式。与此同时,通过显示配置 auth: auth_ldap,为用户 root 指定了身份认证器,要求该用户通过 LDAP 认证进行登录。 在使用以上配置时,用户 rootshardinguser1 对应的认证方式分别是:

  • root:LDAP
  • sharding:密码
  • user1:密码

说明:在混合认证场景中,管理员也可以通过默认启用 LDAP 认证,并使用 auth: password 将少部分用户设置为密码认证。