暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

MySQL使用多因素身份认证

多因素身份验证(MFA)是指用户在身份验证过程中使用多个身份验证值(或“因素”)。MFA比单因素/单因素身份验证(1FA/SFA)提供了更高的安全性,后者只使用一种身份验证方法(如密码)。MFA支持其他身份验证方法,例如使用多个密码进行身份验证,或者使用智能卡、安全密钥和生物识别阅读器等设备进行身份验证。
MySQL从8.0.27开始支持使用多因素身份认证,支持用户使用单因素,2因素及3因素认证。使用多因素身份认证时,需要对系统变量“authentication_policy”进行设置,并使用创建用户语句或更改用户语句指定认证方法,登陆MySQL时,指定—password1,—password2和—password3选项。此外,企业版的服务器端还支持使用“authentication_fido”插件、通过外部设备进行验证。
使用多因素身份认证时,首先需要配置认证策略,为系统变量“authentication_policy”赋值。变量值是用逗号分割的列表,列表中最多包含三个值,值可以使用“*”、认证插件的名称或为空值。例如,authentication_policy = '*,authentication_fido,’,默认值为’*,,’表示使用单因素认证,并且支持使用2因素及3因素认证。该变量可以写入配置文件中,也可以通过SET GLOBAL语句指定。通过列表中3个值不同的排列组合,可以为认证方法配置不同的策略,例如,

策略

'*'

仅允许使用单因素认证

'*,*'

仅允许使用2因素认证

'*,*,*'

仅允许使用3因素认证

'*,'

允许使用单因素或2因素认证

'*,,'

允许使用单因素、2因素或3因素认证

'*,*,'

允许使用2因素或3因素认证

'*,auth_plugin'

允许使用2因素认证,第一个因素可以使用任意方法,第二因素必须使用指定的认证插件

'auth_plugin,*,'

允许使用2因素或3因素认证,第一个因素必须使用指定的认证插件

'auth_plugin,'

允许使用单因素或2因素认证,第一个因素必须使用指定的认证插件

'auth_plugin,auth_plugin,auth_plugin'

允许使用3因素认证,并且必须使用指定的认证的插件

注意:使用内部存储的认证插件必须作为第一个因素,并且不能重复出现,如下情况会出现错误:

    authenication_policy = 'caching_sha2_password, sha256_password'
    authentication_policy = 'caching_sha2_password, authetication_fido, sha256_password'


    MySQL localhost:3350 ssl SQL > CREATE USER 'powerdba'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Welcome01' and IDENTIFIED WITH caching_sha2_password BY 'Welcome02';
    ERROR: 4052 (HY000): Invalid plugin "caching_sha2_password" specified as 2 factor during "CREATE USER".

    正确的使用方法如下,本例第一个因素使用caching_sha2_password,第二个因素使用authentication_windows。

      SQL > CREATE USER powerdba IDENTIFIED WITH caching_sha2_password BY 'Welcome01' AND IDENTIFIED WITH authentication_windows AS '"YITAO.XU"';

      登录MySQL时,指定—password1,—password2

        D:\mysql-commercial-8.0.31-winx64\mysql-commercial-8.0.31-winx64\bin>mysql --port=3310 --user=powerdba --password1 --password2
        Enter password: *********
        Enter password:
        Welcome to the MySQL monitor. Commands end with ; or \g.
        Your MySQL connection id is 18
        Server version: 8.0.31-commercial MySQL Enterprise Server - Commercial


        Copyright (c) 2000, 2022, Oracle and/or its affiliates.


        Oracle is a registered trademark of Oracle Corporation and/or its
        affiliates. Other names may be trademarks of their respective
        owners.


        Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


        mysql>

        以上内容是关于MySQL多因素身份认证的一个简介,感兴趣的读者可以体验试用。

        感谢关注“MySQL解决方案工程师”

        我的新书《MySQL高可用解决方案——从主从复制到InnoDB Cluster》已经上市,感兴趣的朋友可以通过下面的链接购买。

        文章转载自MySQL解决方案工程师,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

        评论