oracle18c新特性-使用者NO AUTHENTICATION認證方式和Proxy user連線
版權宣告:本文為Buddy Yuan原創文章,未經允許不得轉載。原文地址:ofollow,noindex" target="_blank">oracle18c新特性-使用者NO AUTHENTICATION認證方式和Proxy user連線
使用Oracle18.3,我們可以在沒有密碼的情況下建立使用者。實際上出於安全原因,沒有人可以直接連線到應用程式的架構是一個非常好的功能。一個很好方法是使用代理連線,實際上連線為t1使用者但使用t2使用者的密碼,。下面我們就來研究測試一下。
建立T1使用者,賦予create session,resource許可權;
create user t1 identified by t1; grant create session,resource to t1;
建立T2使用者,只賦予create session許可權;
create user t2 identified by t2; grant create session to t2;
賦予允許proxy連線的許可權.
alter user t1 grant connect through t2;
使用代理連線的方式如下,這樣就不用輸入t1使用者的密碼,就連上了t1使用者
Usage: <proxy> ::= <proxyuser> [ <username> ][/ <password> ][@ <connect_identifier> ] SQL> connect t2[t1]/t2@ORCLPDB1 Connected. SQL> select sys_context('USERENV','SESSION_USER') as session_user,sys_context('USERENV','SESSION_SCHEMA') as session_schema,sys_context('USERENV','PROXY_USER') as proxy from dual; SESSION_USERSESSION_SCHEMAPROXY ----------------- ------------------- ------------ T1T1T2 </connect_identifier> </password> </username> </proxyuser> </proxy>
當我們把T1賬號鎖定一下,會發現使用代理的連線會被鎖定。
SQL> alter user t1 account lock; User altered. SQL> connect t2[t1]/t2@ORCLPDB1 ERROR: ORA-28000: The account is locked.
搞明白代理使用者的連線方式,接下來我們來研究NO AUTHENTICATION認證。這裡先把t1和t2使用者刪除。
以下是18c的新特性。使用NO AUTHENTICATION,可以建立一個沒有密碼的使用者。也沒有辦法登陸這個使用者。
NO AUTHENTICATION Clause Use the NO AUTHENTICATION clause to create a schema that does not have a password and cannot be logged into. This is intended for schema only accounts and reduces maintenance by removing default passwords and any requirement to rotate the password. SQL> create user t1 no authentication; User created. SQL> grant create session to t1; Grant succeeded SQL> connect t1@ORCLPDB1 Enter password: ERROR: ORA-01017: invalid username/password; logon denied
可以看到這裡是沒辦法按登入的。需要輸入密碼。我們可以使用proxy連線試試看能不能登陸。
SQL> create user t2 identified by t2; User created. SQL> alter user t1 grant connect through t2; User altered. SQL> connect t2[t1]/t2@ORCLPDB1 Connected.
可以看到這裡可以通過proxy使用者進行連線了。即使t1使用者沒有密碼也可以連線。當然這裡有個問題,就是這麼做有什麼作用?我們的一個想法是,讓t1使用者裡面有資料,然後t1使用者是沒有密碼且不能登入的。然後我們通過代理t2使用者對t1使用者下的資料進行查詢和其他操作。這樣我們就影藏了資料庫的使用者。全程通過代理使用者做所有的操作。我們來測試一下。
1.先刪除t1和t2使用者
drop user t1 cascade; drop user t2 cascade;
2.建立t1,t2使用者,t1使用no authentication認證方式。,同時賦權讓t2成為proxy使用者。
SQL> create user t1 no authentication; User created. SQL> grant create session , create table to t1; Grant succeeded. SQL> create user t2 identified by t2; User created. SQL> alter user t1 grant connect through t2; User altered.
3.測試使用proxy方式連線。
SQL> connect t2[t1]/t2@ORCLPDB1 Connected.
4.直接登陸,需要輸入密碼,此時無法登陸
SQL> connect t1/t1@ORCLPDB1 ERROR: ORA-01017: invalid username/password; logon denied
5.授權sysdba給使用者t1,發現管理許可權不能被授權給該使用者,因為該使用者使用的是no authentication認證方式。
SQL> connect sys/oracle@ORCLPDB1 as sysdba; Connected. SQL> grant sysdba to t1; grant sysdba to t1 * ERROR at line 1: ORA-40366: Administrative privilege cannot be granted to this user.
6.把no authentication認證方式修改成密碼認證。此時就可以授予sysdba許可權了
SQL> alter user t1 identified by t1; User altered. SQL> grant sysdba to t1; Grant succeeded.
7.再次修改成no authentication認證方式,此時是不行的,不能把sysdba許可權使用者設定成no authentication認證方式,收回sysdba許可權,就又能成功了。
SQL> alter user t1 no authentication; alter user t1 no authentication * ERROR at line 1: ORA-40367: An Administrative user cannot be altered to have no authentication type. SQL> revoke sysdba from t1; Revoke succeeded. SQL> alter user t1 no authentication; User altered.
8.再次取消no authentication認證方式,在t1使用者下建立表和插入資料.
SQL> connect sys/oracle@ORCLPDB1 as sysdba; Connected. SQL> alter user t1 identified by t1; SQL> connect t1/t1@ORCLPDB1 Connected. SQL> create table t1 (name varchar2(32)); Table created. SQL> insert into t1 values('buddy'); 1 row created. SQL> commit; Commit complete.
9.再次重新設定no authentication認證方式,通過proxy方式進行連線,可以查看錶的資料和插入資料。此時雖然表屬於t1使用者,但是t1使用者是沒有密碼和不能登入的,只能通過t2使用者使用proxy連線方式登入操作。
SQL> connect sys/oracle@ORCLPDB1 as sysdba; Connected. SQL> alter user t1 no authentication; User altered. SQL> connect t2[t1]/t2@ORCLPDB1 Connected. SQL> select * from t1; NAME -------------------------------- buddy SQL> insert into t1 values('buddy99'); 1 row created. SQL> commit; Commit complete. SQL> select object_name, object_type, owner from all_objects where object_name ='T1'; OBJECT_NAMEOBJECT_TYPEOWNER -------------------- ----------------------- ------------------------------ T1TABLET1
那麼我們能不能使用審計來審計是什麼使用者乾的呢,能不能看到代理使用者乾的?
SQL> connect sys/oracle@ORCLPDB1 as sysdba; Connected. SQL> create audit policy t1_user_audit_policy privileges create table when 'SYS_CONTEXT(''USERENV'',''SESSION_USER'') = ''T1''' evaluate per session container=current; Audit policy created SQL> audit policy t1_user_audit_policy whenever successful; Audit succeeded. SQL> connect t2[t1]/t2@ORCLPDB1 Connected. SQL> create table a1 (name varchar2(30)); Table created.
檢視審計unified_audit_trail表,可以看到DBPROXY_USERNAME欄位不為空就是代理使用者T2建立的。
SQL> connect sys/oracle@ORCLPDB1 as sysdba; Connected. SQL> select object_name,event_timestamp, dbusername, dbproxy_username from unified_audit_trail where action_name = 'CREATE TABLE'; OBJECT_NAMEEVENT_TIMESTAMPDBUSERNAMEDBPROXY_USERNAME ------------------------------ ------------------------------ ------------------------------ ------------------------------ A123-OCT-18 10.21.33.073649 PMT1T2