天天看点

Vertica中用户登录认证

本文翻译整理自:Authentication Methods for dbadmin

在vertica中,当你新建一个数据库后,默认是没有设置认证配置的。在这种情况下,Vertica假定所有用户(包括dbadmin)都具有隐式密码身份验证。用户可以使用此身份验证方法通过网络接口和本地域套接字进行身份验证。

示例:默认认证登录方式

首先,我们创建一个名为auth_test的新数据库:

admintools -t create_db -d auth_test -s 10.0.0.10 -p letmein 
           

然后,我们创建一个名为test的用户:

在新创建的数据库上,登录身份验证在网络上以及本地套接字类似于以下内容,其中默认身份验证方法为

default:password

网络连接:

$ vsql -X -U dbadmin -w letmein -h 10.0.0.10 -c "select client_authentication_name,client_authentication from sessions where session_id = current_session();"
client_authentication_name | client_authentication
----------------------------+-----------------------
default: Password 		 | 0
(1 row)

$ vsql -X -U test -w lettestin -h 10.0.0.10 -c "select client_authentication_name,client_authentication from sessions where session_id = current_session();"
client_authentication_name | client_authentication
----------------------------+-----------------------
default: Password | 0
(1 row)
           

本地连接:

$ vsql -X -U dbadmin -w letmein -c "select client_authentication_name,client_authentication from sessions where session_id = current_session();"
client_authentication_name | client_authentication
----------------------------+-----------------------
default: Password		 | 0
(1 row)

$ vsql -X -U test -w lettestin -c "select client_authentication_name,client_authentication from sessions where session_id = current_session();"
client_authentication_name | client_authentication
----------------------------+-----------------------
default: Password | 0
(1 row)
           
示例:新建认证

当您创建单一身份验证方法时,vertica假定用户不再是新手用户,其目的是锁定某些登录。现在,vertica的策略改为仅允许具有明确授权分配的用户访问。除了通过本地域套接字进行的dbadmin密码身份验证之外,我们不再假定

default:password

为了测试这一点,让我们创建一个新的身份验证方法:

dbadmin=> create authentication network_passwd method 'hash' host '0.0.0.0/0' ;
CREATE AUTHENTICATION 
           

现在,用户测试无法使用default:password方法登录。这将适用于任何非dbadmin用户。

$ vsql -X -U test -w lettestin -h 10.0.0.10 -c "select client_authentication_name,client_authentication from sessions where session_id = current_session();"
vsql: FATAL 2248: Authentication failed for username "test"
$ vsql -X -U test -w lettestin -c "select client_authentication_name,client_authentication from sessions where session_id = current_session();"
vsql: FATAL 2248: Authentication failed for username "test" 
           

dbadmin仅允许通过本地域套接字使用密码身份验证方法,以防止dbadmin被锁定:

$ vsql -X -U dbadmin -w letmein -c "select client_authentication_name,client_authentication from sessions where session_id = current_session();"
client_authentication_name | client_authentication
----------------------------+-----------------------
default: Password		 | 0
$ vsql -X -U dbadmin -w letmein -h 10.0.0.10 -c "select client_authentication_name,client_authentication from sessions where session_id = current_session();"
vsql: FATAL 2248: Authentication failed for username "dbadmin"
           
示例:创建并对用户授权认证

因此,要使任何非dbadmin用户登录,需要进行明确的身份验证方法分配,如以下步骤所示:

dbadmin=> CREATE AUTHENTICATION local_passwd method 'hash' local;
CREATE AUTHENTICATION

dbadmin=> GRANT AUTHENTICATION network_passwd to test;
GRANT AUTHENTICATION

dbadmin=> GRANT AUTHENTICATION local_passwd to test;
GRANT AUTHENTICATION 
           

现在,我们看到用户测试可以访问网络和本地密码身份验证方法:

$ vsql -X -U test -w lettestin -h 10.0.0.10 -c "select client_authentication_name,client_authentication from sessions where session_id = current_session();"
client_authentication_name | client_authentication
----------------------------+-----------------------
network_passwd			 | 45035996273708038
(1 row)
$ vsql -X -U test -w lettestin -c "select client_authentication_name,client_authentication from sessions where session_id = current_session();"
client_authentication_name | client_authentication
----------------------------+-----------------------
local_passwd			 | 45035996273708098
(1 row) 
           

同样,可以通过将网络的密码认证授予dbadmin,来使得dbadmin用户可以网络登录。

$ vsql -X -U dbadmin -w letmein -c "grant authentication network_passwd to dbadmin;"
GRANT AUTHENTICATION
$ vsql -X -U dbadmin -w letmein -h 10.0.0.10 -c "select client_authentication_name,client_authentication from sessions where session_id = current_session();"
client_authentication_name | client_authentication
----------------------------+-----------------------
network_passwd			 | 45035996273708038
           

不建议对dbadmin用户授予本地认证,因为不正确的配置可能会导致dbadmin被锁定。