日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

Oracle學(xué)習(xí)筆記(14)權(quán)限管理(

 憂郁_小剛 2011-05-20

權(quán)限管理

 

1、Oracle兩類型的用戶權(quán)限:
System 使用戶在數(shù)據(jù)庫(kù)中完成部分行為
Object 使用戶接觸和操作一個(gè)特定的數(shù)據(jù)對(duì)象。只有owner(Object Schema才能授權(quán))

 

2、系統(tǒng)權(quán)限(100多種)
其中,create table和create any table 的區(qū)別
any關(guān)鍵字指示用戶在權(quán)限中可以操作任何schema. grant授權(quán),revoke 取消權(quán)限
窗口1:
sql>create user testuser1
    identified by kxf_001 default tablespace users
    quota 10m on users;

sql>grant create table to testuser1;  //此權(quán)限只能給到自己創(chuàng)建一個(gè)表,而不能操作多張表

窗口2:
sql>conn testuser1/kxf_001;  //無(wú)法連接到Oracle
窗口1:
sql>grant create session to testuser1; //授權(quán)create session
窗口2:
sql>conn testuser1/kxf_001
sql>create table test1(id int) tablespace users; //創(chuàng)建表

sql>create table kong.tt1(id int) tablespace users; //權(quán)限不足
窗口1:
sql>grant create any table to testuser1;  //將“可以創(chuàng)建任何表”的權(quán)限給testuser1
窗口2:
sql>create table kong.tt1(id int) tablespace users;  //創(chuàng)建成功
窗口1:
sql>revoke create any table from testuser1;   //撤銷(xiāo)testuser1的權(quán)限create any table

INDEX:CREATE ANY INDEX \ ALTER ANY INDEX \ DROP ANY INDEX
TABLE:CREATE TABLE \ CREATE ANY TABLE\ALTER ANY TABLE\DROP ANY TABLE\ SELECT ANY TABLE\ UPDATE ANY TABLE \ DELETE ANY TABLE
SESSION:CREATE SESSION\ ALTER SESSION\ RESTRICTED SESSION
TABLESPACE:CREATE TABLESPACE\ ALTER TABLESPACE\ DROP TABLESPACE \ UNLIMITED TABLESPACE(無(wú)限空間資源的使用)
【注意】沒(méi)有create index權(quán)限。如:

grant system_privs,[....] to [user/role/public],[....] with admin option
其中,with admin option 可以把權(quán)限授予第三個(gè)人


sql>grant create index to testuser1;  //缺少或無(wú)效權(quán)限

sql>truncate table kong.sales; 
sql>grant truncate table to testuser1; //授予testuser1truncate table權(quán)限。
sql>grant truncate any table to testuser1;

sql>grant drop any table to testuser1;
sql>grant create table,create session,create view to kong,testuser1; //授予多個(gè)用戶多個(gè)權(quán)限。

sql>grant create table to public;  //授權(quán)create table給系統(tǒng)中所有用戶

sql>create role testrole1   //創(chuàng)建角色1
sql>create role testrole2;   //創(chuàng)建角色2
sql>grant create table to testrole2; //為角色2添加create table權(quán)限。

sql>create user testuser2 identified by kxf_001;
sql>conn testuser1/xkf_001;
sql>grant create table to testuser2; //權(quán)限不足,只允許testuser2創(chuàng)建表
窗口2:
sql>conn sys/admin1 as sysdba
sql>grant create table to testuser1 with admin option; //授權(quán)create table給testuser1帶上管理權(quán)限。
窗口1:
sql>grant create table to testuser2; //授權(quán)成功

 

3、系統(tǒng)權(quán)限(System Privileges)
SYSDBA\SYSOPER 權(quán)限集合(特殊):實(shí)現(xiàn)database的管理和操作
SYSOPER:startup、shutdown、alter database open|mount、alter database backup controlfile to(數(shù)據(jù)庫(kù)完整修復(fù)) 、recover database、alter database archivelog

SYSDBA:sysoper privileges with admin option、create database、alter database begin/end backup、restricted session、recover database until

注意:sysoper不能建立數(shù)據(jù)庫(kù),不能完成數(shù)據(jù)庫(kù)的部分修復(fù),沒(méi)有受限(restricted)模式的權(quán)限,不具有備份權(quán)限。而sysdba具有sysoper所有的權(quán)限,同時(shí)帶上了admin選項(xiàng)。

sql>grant sysdba to kong;  //為kong用戶授予管理員sysdba的權(quán)限
sql>select * from v$pwfile_users;  //sysdba有權(quán)利查數(shù)據(jù)字典
sql>grant sysoper to kong with admin option //為kong授予sysoper權(quán)限并帶上admin選項(xiàng),其實(shí)kong已經(jīng)是sysdba,而sysdba具有sysoper的所有權(quán)限帶上了admin選項(xiàng)。

O7_DICTIONARY_ACCESSIBILITY 參數(shù):數(shù)據(jù)字典表能不能存儲(chǔ)或被改變。
sql>grant select any table to testuser1;
sql>select * from sys.aud$;  //查詢系統(tǒng)審計(jì)表

sql>show parameter O7  //O7_DICTIONARY_ACCESSIBILITY value=false
sql>show user   //testuser1
sql>select * from sys.aud$;  //審計(jì)記錄表(不能)

sql>alter system set o7_dictionary_accessibility=true ;//設(shè)計(jì)對(duì)任意表操作的用戶能不能訪問(wèn)到系統(tǒng)表的資料,一般來(lái)說(shuō)系統(tǒng)默認(rèn)將這個(gè)參數(shù)值設(shè)置為false,即系統(tǒng)審計(jì)記錄表不對(duì)普通用戶開(kāi)放。
sql>startup force  //強(qiáng)制重啟,讓數(shù)據(jù)庫(kù)打開(kāi)
窗口2:
sql>conn testuser1/kxf_001; //已經(jīng)連接
sql>select * from sys.aud$;  //審計(jì)記錄表(可以訪問(wèn))

窗口1:
sql>revoke create table,create any table from testuser1;//系統(tǒng)權(quán)限未授予testuser1

sql>show user  //"sys"
sql>revoke create table from testuser1;  //撤銷(xiāo)create table權(quán)限成功
sql>revoke create any table from testuser1; //系統(tǒng)權(quán)限create any table未授予testuser1;

sql>grant create session to testuser2;  //授予會(huì)話權(quán)限給testuser2
sql>alter user testuser2 quota 10m on users; //在表空間users上給testuser2分配10m限額資源。

sql>conn testuser2/kxf_001
sql>create table tt1(id int) tablespace users;  //此時(shí),testuser2仍然還有創(chuàng)建表的權(quán)限,在撤銷(xiāo)基于admin傳遞出的權(quán)限時(shí),它是不會(huì)級(jí)聯(lián)的。

注意:對(duì)象權(quán)限帶上admin option選項(xiàng)授予出去時(shí)是會(huì)級(jí)聯(lián)的。

 

4、對(duì)象權(quán)限(Object Privileges)
ALTER(Table\Sequence\Procedure)、DELETE(Table\View)、EXECUTE(Procedure)、INDEX(Table\View)、INSERT(Table\View)、PEFERENCES(Table)、SELECT(Table\View\Sequence)、UPDATE(Table\View)
grant [object_privs(column,...)],[....]on object_name to user/role/public,....with grant option
其中with grant option可以將權(quán)限授予第三個(gè)人。默認(rèn)owner可以授權(quán)第三個(gè)人。

GRANT EXECUTE ON dbms_output TO jeff;  //授予執(zhí)行某個(gè)存儲(chǔ)過(guò)程的權(quán)限
GRANT UPDATE ON emi.customers TO jeff WITH GRANT OPTION;

窗口1:
sql>show user //"SYS"
sql>select * from kong.authors;

窗口2:
sql>conn sys/admin1 as sysdba
sql>set wrap off
sql>set linesize 800
sql>select * from kong.authors;
sql>grant  select,update on kong.authors to testuser1; //默認(rèn)不可以將權(quán)限授予第三個(gè)人

sql>conn kong/kxf_001
sql>grant select,update on kong.authors to testuser1;  //授權(quán)成功

sql>grant select,update on kong.authors to sys with grant option; //sys也可以享有g(shù)rant授予權(quán)限。

sql>conn sys/admin1 as sysdba
sql>grant select,update on kong.authors to testuser1; //授權(quán)成功

sql>conn kong/kxf_001
sql>grant select on authors(au_id,au_lname) to testuser1; //授予testuser1查詢authors,缺少無(wú)效權(quán)限

取消權(quán)限:
REVOKE SELECT on emi.orders FROM jeff;
sql>revoke select on authors from testuser1;

注意:with grant option 取消權(quán)限應(yīng)該是級(jí)聯(lián)的。

sql>grant select on authors to testuser1 with grant option

sql>conn testuser1/kxf_001
sql>select * from kong.authors;
sql>grant select on kong.authors to testuser2;  //testuser1也可以將這個(gè)權(quán)限授出給testuser2

sql>conn testuser2/kxf_001
sql>select * from kong.authors; //testuser2也可以使用這個(gè)權(quán)限

sql>conn kong/kxf_001
sql>revoke select on authors from testuser1;  //取消testuser1的select權(quán)限。

sql>conn kong/kxf_001
sql>revoke select on authors from sys;// 取消sys的select 權(quán)限

sql>conn testuser2/kxf_001
sql>select * from kong.authors;  //此時(shí),無(wú)法訪問(wèn)testuser2的select 權(quán)限。

 

5、獲取權(quán)限信息:
DBA_SYS_PRIVS dba系統(tǒng)權(quán)限
SESSION_PRIVS 會(huì)話權(quán)限
DBA_TAB_PRIVS
DBA_COL_PRIVS

sql>conn sys/admin1 as sysdba
sql>select * from dba_sys_privs ;//dba授了哪些權(quán)限給哪些人

sql>conn testuser2/kxf_001
sql>select * from session_privs; //當(dāng)前開(kāi)的session里用戶擁有什么權(quán)限

sql>conn kong/kxf_001
sql>select * from user_tab_privs; //授予了哪些對(duì)象權(quán)限給哪些用戶

sql>conn sys/admin1 as sysdba
sql>select * from dba_col_privs;  // 授予了哪些欄位權(quán)限給哪些用戶

 

6、審計(jì)Auditing
審計(jì)規(guī)則:審計(jì)用戶、語(yǔ)句或?qū)ο螅徽Z(yǔ)句執(zhí)行是否成功;
審計(jì)策略:默認(rèn)審計(jì)(實(shí)例啟動(dòng)或關(guān)閉、Administrator權(quán)限)、Database審計(jì)(由DBA進(jìn)行enable<初始關(guān)閉>,不可以基于column值的記錄)、Value-based基于值或應(yīng)用程序?qū)徲?jì):使用觸發(fā)器。

Database審計(jì)(默認(rèn)關(guān)閉):
啟動(dòng)database審計(jì) >設(shè)定Audit option選項(xiàng)(表 AUDIT TABLE\觸發(fā)器 AUDIT create any trigger\select選項(xiàng) AUDIT SELECT ON emi.orders\進(jìn)一步審計(jì)給予欄位的值則使用DBMS_FGA package) >一旦用戶發(fā)出相應(yīng)的command就會(huì)生成相關(guān)的審計(jì)記錄,該審計(jì)記錄可以記錄在OS中也可以記錄在Database中或默認(rèn)(audit_trail=none)
audit create table
      select/update/insert[on object]
 by session/by access
whenever successful/not successful //可選,只記錄成功或失敗的,若不指定,則全部記錄

其中:by session 發(fā)出相同command,只記錄一次
      by access  每發(fā)出一次command,記錄一次


sql>show parameter audit_trail 跟蹤記錄 // value=db/os/none
sql>audit select on kong.authors by session; //啟動(dòng)kong.authors表的審計(jì),只審計(jì)select動(dòng)作。
sql>audit create table; //審計(jì)create table動(dòng)作

sql>audit update on kong.authors whenever not successful; //只記錄不成功的update審計(jì)

sql>desc dbms_fga;

 

a.取消審計(jì):noaudit
sql>noaudit select on kong.authors;

 

b.查看審計(jì)選項(xiàng):
ALL_DEF_AUDIT_OPTS  所有缺省的審計(jì)選項(xiàng)
DBA_STMT_AUDIT_OPTS 所有語(yǔ)句的審計(jì)選項(xiàng)
DBA_PRIV_AUDIT_OPTS 所有權(quán)限的審計(jì)選項(xiàng)
DBA_OBJ_AUDIT_OPTS  所有數(shù)據(jù)對(duì)象的審計(jì)選項(xiàng)
 
sql>select * from all_def_audit_opts;
sql>select * from dba_stmt_audit_opts;
sql>select * from dba_obj_audit_opts;

 

c.如何獲取審計(jì)記錄:
DBA_AUDIT_TRAIL、DBA_AUDIT_EXISTS、DBA_AUDIT_OBJECT、DBA_AUDIT_SESSION、DBA_AUDIT_STATEMENT

sql>audit select on kong.authors /; 
sql>conn kong/kxf_001
sql>select * from authors;

sql>conn sys/admin1 as sysdba
sql>select * from dba_audit_trail; //對(duì)authors的審計(jì)操作都記錄在該dba_audit_trail中。

sql>select * from dba_audit_object;
sql>select * from dba_audit_session;

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多