1. 程式人生 > >【跟我學oracle18c】第十七天:Multitenant Architecture多租戶框架:2.2 Overview of Commonality in the CDB(藍色感悟)

【跟我學oracle18c】第十七天:Multitenant Architecture多租戶框架:2.2 Overview of Commonality in the CDB(藍色感悟)

在CDB中,每個使用者、角色或物件都是通用的或本地的。類似地,通常或區域性授予特權.

This section contains the following topics:

Parent topic: Overview of the Multitenant Architecture

2.2.1 About Commonality in a CDB

在根中定義的一個常見現象在插入到這個根的所有容器中都是一樣的.

本節包含以下主題:

  • 共性的原則
    在CDB中,在系統容器(CDB本身)或特定應用程式容器中都可能出現這種現象.
  • CDB中的名稱空間
    在CDB中,每個物件的名稱空間都限定在其容器的作用域內.

Parent topic: Overview of Commonality in the CDB

2.2.1.1 共性的原則

在CDB中,在系統容器(CDB本身)或特定應用程式容器中都可能出現這種現象。

例如,如果您在連線到CDB$ROOT時建立一個公共使用者帳戶,那麼這個使用者帳戶對於CDB中的所有PDBs和應用程式根都是通用的。但是,如果您在連線到應用程式根目錄時建立了一個應用程式通用使用者帳戶,那麼這個使用者帳戶只對這個應用程式容器中的PDBs通用.

在CDB$ROOT或應用程式根的上下文中,公共原則如下:

  • 在每個現有容器和未來容器中都存在相同的常見現象.

    因此,CDB根中定義的公共使用者在插入到CDB根的每個PDB中具有相同的標識;在應用程式根中定義的公共使用者在插入到該應用程式根的每個應用程式PDB中具有相同的標識。相比之下,一個本地現象的作用域僅侷限於一個現有容器.(一句話非強調兩次,看著都費勁,不就是CDB根與application root一致)

  • 只有普通使用者才能改變常見現象的存在.

    更準確地說,只有登入到CDB根或應用程式根的公共使用者才能建立、銷燬或修改當前容器中通用的使用者、角色或物件的屬性.

Parent topic: About Commonality in a CDB

2.2.1.2 CDB中的名稱空間

在CDB中,每個物件的名稱空間都限定在其容器的作用域內。

以下原則總結了界定範圍的規則

  • 從應用程式的角度來看,PDB與非cdb沒有區別.

  • 區域性現象是在一個容器內產生並限制在一個容器內.

    Note:

    In this topic, the word “ 現象” means “使用者帳戶、角色或資料庫物件.”

  • 常見現象定義在一個CDB根或應用程式根中,並且存在於所有已經或將要插入到這個根中的PDBs中。

這個說法比較有意思,我進行了一次在cdb和pdb內的cdb下建立的c##test使用者的存在性檢驗,發現都可以看到,但是使用者本身具有的許可權是私有的,必須單獨給予

例子:在cdb的sys使用者下create user C##test identified by test;但是未給任何許可權,pdb的sys使用者下grant dba to c##test;然後參見下圖可以理解上面存在於三個字

下圖是cdb內的c##test使用者許可權截圖

下圖是pdb內的

測試使用者的可連線行為

SQL> conn c##test/[email protected]

提示
 

SQL> conn c##test/[email protected]
Connected to Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 
Connected as c##[email protected]

以上原則對區域性現象和常見現象具有啟示意義.

  • 區域性現象

本地現象必須在容器中唯一命名,但不能跨CDB中的所有容器。在不同容器中同名的區域性現象是不同的。例如,本地使用者sh一個PDB不會與另一個PDB中的本地使用者sh發生衝突。(pdb使用者的私有性).

 

CDB$ROOT常見現象

在CDB$ROOT中定義的常見現象存在於多個容器中,並且在每個名稱空間中必須是唯一的。例如,CDB根包含預定義的通用使用者,如SYSTEM和SYS。為了確保名稱空間分離,Oracle資料庫防止在另一個容器中建立SYSTEMuser。(

我試著在pdb內建立cdb$root中存在的c##test使用者是不允許的

SQL> create user C##test identified by test;
create user C##test identified by test
ORA-65094: 本地使用者名稱或角色名無效,由於cdb內不允許使用者建立非c##開頭的使用者,就不存在其他嘗試了

為了確保名稱空間分離,在CDB根中使用者建立的公共現象的名稱必須以COMMON_USER_PREFIX初始化引數指定的值開始。預設的字首是c##或c##。所有其他使用者建立的現象的名稱不能以c#或c#開頭。例如,您不能在hrpdb中建立名為c##hr的本地使用者,也不能在名為hr的CDB根中建立公共使用者.

SQL> show parameter COMMON_USER_PREFIX
NAME                                 TYPE        VALUE
------------------------------------ ----------- ------------------------------
common_user_prefix                   string
 

應用程式常見的現象

在應用程式容器中,本地和應用程式常見現象的名稱不能衝突.

  • 應用程式通用使用者和角色

    應用程式通用使用者和CDB通用使用者的原理是一樣的。不同之處在於,對於CDB公共使用者,公共使用者字首的預設值是c##或c##,而在應用程式根中,公共使用者字首的預設值是空字串.

    多租戶體系結構假設您從應用程式根建立應用程式PDBs,或者將單租戶應用程式轉換為多租戶應用程式.

  • 應用程式常見的物件

    多租戶體系結構假設您在應用程式根中建立應用程式公共物件。稍後,您將在應用程式PDBs中本地新增資料。但是,Oracle資料庫支援在應用程式PDB中建立本地表。在本例中,本地表與應用程式PDB中的應用程式公共物件駐留在同一個名稱空間中。

See Also:

Oracle Database Security Guide to learn more about common users and roles

Parent topic: About Commonality in a CDB

2.2.2 Overview of CDB中的普通使用者和本地使用者

如果使用者帳戶擁有定義資料庫的物件,則此使用者帳戶是常見的。非oracle提供的使用者帳戶要麼是本地帳戶,要麼是通用帳戶

CDB公共使用者是在CDB根中建立的公共使用者。應用程式公共使用者是在應用程式根目錄中建立的使用者,並且僅在此應用程式容器中通用

下圖顯示了CDB中可能的使用者帳戶型別

Figure 2-6 User Accounts in a CDB

Description of Figure 2-6 follows
Description of "Figure 2-6 User Accounts in a CDB"

CDB公共使用者可以連線到CDB中具有足夠許可權的任何容器。相反,應用程式普通使用者只能連線到建立它的應用程式根,或者連線到這個應用程式根的PDB,這取決於它的許可權.

This section contains the following topics:

  • Common Users in a CDB
    Within the context of either the system container (CDB) or an application container, a common user is a database user that has the same identity in the root and in every existing and future PDB within this container.
  • Local Users in a CDB
    local user is a database user that is not common and can operate only within a single PDB.

See Also:

Oracle Database Security Guide for an overview of common and local users

Parent topic: Overview of Commonality in the CDB

2.2.2.1 Common Users in a CDB

在系統容器(CDB)或應用程式容器的上下文中,公共使用者是在根目錄中以及在此容器中的每個現有和將來的PDB中具有相同標識的資料庫使用者.

每個普通使用者都可以連線到其容器的根,並在其具有足夠許可權的任何PDB中執行操作。一些管理任務必須由普通使用者執行。示例包括建立PDB和斷開PDB的連線.

例如,系統是具有DBA許可權的CDB公共使用者。因此,系統可以連線到CDB根和資料庫中的任何PDB。您可以在saas_sales應用程式容器中建立一個公共使用者saas_sales_admin。在這種情況下,saas_sales_admin使用者只能連線到saas_sales應用程式根或saas_salesapplication容器中的應用程式PDB。

每個普通使用者要麼是oracle提供的,要麼是使用者建立的。oracle提供的普通使用者的例子有SYS和SYSTEM。每個使用者建立的公共使用者要麼是CDB公共使用者,要麼是應用程式公共使用者.

Figure 2-7 在兩個PDBs中顯示示例使用者和模式:hrpdb和salespdb。在CDB$ROOT、hrpdb和salespdb中具有模式的SYS和c## #dbaare CDB通用使用者。hrpdb中存在本地使用者hr和 rep。salespdb中也有本地使用者hr和rep.

Figure 2-7 Users and Schemas in a CDB

Description of Figure 2-7 follows
Description of "Figure 2-7 Users and Schemas in a CDB"

普通使用者具有以下特徵:

  • 普通使用者可以登入任何具有CREATE會話特權的容器(包括CDB$ROOT).

    普通使用者不需要在每個容器中擁有相同的特權。例如,c##dbauser可以在hrpdb和根目錄中建立會話,但不能在salespdb中建立會話。因為具有適當許可權的普通使用者可以在容器之間切換,所以根使用者可以管理PDBs.

  • 應用程式公共使用者在其自己的應用程式容器之外的任何容器中沒有建立會話特權.

    因此,應用程式公共使用者被限制在其自己的應用程式容器中。例如,在saas_sales應用程式中建立的應用程式公共使用者只能連線到saas_sales應用程式容器中的應用程式根和PDBs。

  • 使用者建立的CDB公共使用者的名稱必須遵循其他資料庫使用者的命名規則。此外,名稱必須以COMMON_USER_PREFIX初始化引數指定的字元開頭,預設為c##或c##。oracle提供的通用使用者名稱和使用者建立的應用程式通用使用者名稱沒有這個限制。

    本地使用者名稱不能以字元c##或c##開頭.

  • 在建立它的容器(系統容器或特定應用程式容器)中的所有PDBs中,每個公共使用者都被惟一地命名。

    CDB公共使用者是在CDB根中定義的,但是必須能夠以相同的身份連線到每個PDB。應用程式公共使用者駐留在應用程式根中,可以以相同的身份連線到其容器中的每個應用程式PDB。

See Also:

Parent topic: Overview of Common and Local Users in a CDB

2.2.2.2 Local Users in a CDB

本地使用者是不常見的資料庫使用者,只能在單個PDB中操作。

本地使用者具有以下特徵:

  • 本地使用者是特定於PDB的,可能在此PDB中擁有一個模式.

    在圖2-7中,hrpdb上的本地使用者hr擁有hr模式。在salespdb上,本地使用者重新分配rep模式,本地使用者hr擁有hr模式.

  • 本地使用者可以管理PDB,包括開啟和關閉它。

    具有SYSDBA特權的普通使用者可以向本地使用者授予SYSDBA特權。在本例中,特權使用者仍然是本地使用者。

  • 一個PDB中的本地使用者無法登入到另一個PDB或CDB根。

    例如,當本地使用者hr連線到hrpdb時,hr不使用資料庫連結就不能訪問駐留在salespdb資料庫中的shschema中的物件。同樣,當本地使用者sh連線到salespdb PDB時,sh不使用資料庫連結就無法訪問駐留在hrpdb中的hrschema中的物件。

  • 本地使用者的名稱不能以字元c##或c##開頭。

  • 本地使用者的名稱必須在其PDB中是唯一的。

    包含該使用者模式的使用者名稱和PDB確定一個惟一的本地使用者。圖2-7顯示了hrpdb上存在一個名為rep的本地使用者和模式。salespdb PDB上存在一個完全獨立的名為rep的本地使用者和模式。

下表描述了圖2-7中涉及CDB的場景。每行描述在前一行的操作之後發生的操作。公共使用者系統在兩個PDBs中建立本地使用者.

Table 2-3 Local Users in a CDB

Operation Description
SQL> CONNECT [email protected]
Enter password: ********
Connected.

SYSTEM connects to the hrpdb container using the service name hrpdb.

SQL> CREATE USER rep IDENTIFIED BY password; 

User created.

SQL> GRANT CREATE SESSION TO rep;

Grant succeeded.

SYSTEM now creates a local user rep and grants the CREATE SESSION privilege in this PDB to this user. The user is local because common users can only be created by a common user connected to the root.

SQL> CONNECT [email protected]
Enter password: *******
ERROR:
ORA-01017: invalid username/password; logon denied

The rep user, which is local to hrpdb, attempts to connect to salespdb. The attempt fails because rep does not exist in PDB salespdb. This behavior mimics the behavior of non-CDBs. A user account on one non-CDB is independent of user accounts on a different non-CDB.

SQL> CONNECT [email protected]
Enter password: ********
Connected.

SYSTEM connects to the salespdb container using the service name salespdb.

SQL> CREATE USER rep IDENTIFIED BY password; 

User created.

SQL> GRANT CREATE SESSION TO rep;

Grant succeeded.

SYSTEM creates a local user rep in salespdband grants the CREATE SESSION privilege in this PDB to this user. Because the name of a local user must only be unique within its PDB, a user named rep can exist in both salespdband hrpdb.

SQL> CONNECT [email protected]
Enter password: *******
Connected.

The rep user successfully logs in to salespdb.

See Also:

Oracle Database Security Guide to learn about local user accounts

Parent topic: Overview of Common and Local Users in a CDB

2.2.3 Overview of CDB中的公共和本地角色

使用者建立的角色要麼是本地的,要麼是通用的。公共角色對於CDB本身或特定的應用程式容器都是通用的。

每個oracle提供的角色都是常見的,例如預定義的DBA角色。在oracle提供的指令碼中,向oracle提供的使用者和角色授予的所有特權或角色通常都被授予,只有一個例外:系統特權在本地授予公共角色。

This section contains the following topics:

  • Common Roles in a CDB
    A common role exists either in the CDB root or an application root, and applies to every PDB within the root container (either the CDB or the application container).
  • Local Roles in a CDB
    A local role exists only in a single PDB, just as a role in a non-CDB exists only in the non-CDB.

See Also:

"Grants to PUBLIC in a CDB"

Parent topic: Overview of Commonality in the CDB

2.2.3.1 Common Roles in a CDB

一個通用角色存在於CDB根或應用程式根中,並應用於根容器(無論是CDB還是應用程式容器)中的每個PDB。
公共角色對於跨容器操作非常有用,可以確保每個PDB中都有一個公共使用者。每個常見角色都是以下型別之一:

  • Oracle-supplied

    All Oracle-supplied roles, such as DBA and PUBLIC, are common to the CDB.

  • User-created

    通過執行Create role…CONTAINER=ALL在CDB根或應用程式根中,它們決定了角色通用的容器。使用標準命名約定。此外,CDB公共角色的名稱必須以COMMON_USER_PREFIX初始化引數指定的字元開頭,預設為c##或c##。

角色的作用域是定義它的根的作用域。如果您在CDB$ROOT中定義角色,那麼它的作用域就是整個CDB。如果您在應用程式根目錄中定義角色,那麼它的作用域就是應用程式容器。

See Also:

Parent topic: Overview of Common and Local Roles in a CDB

2.2.3.2 Local Roles in a CDB

本地角色只存在於單個PDB中,就像非cdb中的角色只存在於非cdb中一樣。
本地角色只能包含應用於角色所在容器中的角色和特權。例如,如果您在hrpdb中建立了本地角色pdbadmin,那麼這個角色的作用域僅限於這個PDB。
相同CDB或相同應用程式容器中的PDBs可能包含同名的本地角色。例如,使用者建立的角色pdbadmin可能存在於hrpdb和salespdb中。然而,這些角色是完全獨立的

See Also:

Oracle Database Security Guide to learn how to manage local roles

Parent topic: Overview of Common and Local Roles in a CDB

2.2.4 Overview of Privilege and Role Grants in a CDB

就像在非CDB中一樣,CDB中的使用者可以授予並被授予角色和特權。然而,CDB中的角色和特權要麼在本地授予,要麼通常授予。
本地授予的特權或角色僅在授予它的PDB中可執行。被授予的特權或角色通常在容器中的每個現有和將來的PDB(無論是CDB還是應用程式容器)中都可以執行。
使用者和角色可以是通用的,也可以是本地的。然而,特權本身既不是普通的,也不是本地的。如果使用者使用CONTAINER=CURRENT子句在本地授予特權

This section contains the following topics:

See Also:

Oracle Database Security Guide to learn how to manage common privileges

Parent topic: Overview of Commonality in the CDB

2.2.4.1 Principles of Privilege and Role Grants in a CDB

在CDB中,所有的授權行為,無論是本地的還是普通的,都發生在一個容器中。容器可以是CDB根、應用程式根或PDB。
如果當前的容器是CDB根,那麼授予通常意味著授予CDB中的所有容器。但是,如果當前容器是應用程式根,那麼授予通常意味著授予當前應用程式容器中的所有PDBs。

授予的基本原則如下:

  • 普通現象和區域性現象都可以在區域性授予和被授予。
  • 只有常見的現象才可能被普遍授予或被授予

本地使用者、角色和特權被限制到特定的PDB。因此,本地使用者可能不會通常授予角色和特權,而本地角色和特權可能不會通常授予

The following sections describe the implications of the preceding principles.

Parent topic: Overview of Privilege and Role Grants in a CDB

2.2.4.2 Privileges and Roles Granted Locally in a CDB

角色和特權可以在本地授予使用者和角色,而不管被授予的角色是本地的還是通用的。

The following table explains the valid possibilities for locally granted roles and privileges.

Table 2-4 Local Grants

Phenomenon May Grant Locally May Be Granted Locally May Receive a Role or Privilege Granted Locally

Common User

Yes

N/A

Yes

Local User

Yes

N/A

Yes

Common Role

N/A

YesFoot 1

Yes

Local Role

N/A

YesFoot 2

Yes

Privilege

N/A

Yes

N/A

Footnote 1

此角色中的特權僅在授予角色的容器中可用,而不管特權是本地授予的還是普通授予的。

 

Footnote 2

此角色中的特權僅在授予和建立該角色的容器中可用。

 

This section contains the following topics:

Parent topic: Overview of Privilege and Role Grants in a CDB

2.2.4.2.1 What Makes a Privilege or Role Grant Local

要在本地授予角色或特權,請使用grant語句和CONTAINER=CURRENT子句(預設為CONTAINER=CURRENT子句)。

具體來說,只有在滿足以下條件時,才能在本地授予角色或特權:

  • 授予人具有授予指定角色或特權所需的特權。
    對於系統角色和特權,授予方必須擁有授予的角色或特權的管理選項。對於物件特權,授予方必須具有授予特權的選項。

  • The grant applies to only one container.

    預設情況下,GRANT語句包含CONTAINER=CURRENT子句,該子句表示在本地授予特權或角色

Example 2-4 Granting a Privilege Locally

在本例中,sys和c##hr_admin都是普通使用者。該示例連線到hrpdb作為系統(具有管理員許可權),然後在本地將employees表上的讀許可權授予c##hr_admin。此授權僅適用於hrpdb內的c##hr_admin,不適用於任何其他PDBs.

CONNECT [email protected]
Enter password: password
Connected.

GRANT READ ON employees TO c##hr_admin CONTAINER=CURRENT;

See Also:

Oracle Database Security Guide to learn more about granting local roles and privileges

Parent topic: Privileges and Roles Granted Locally in a CDB

2.2.4.2.2 Roles and Privileges Granted Locally

使用者或角色可能被本地授予特權(容器=當前)。

For example, a READ ANY TABLE privilege granted locally to a local or common user in hrpdbapplies only to this user in this PDB. Analogously, the READ ANY TABLE privilege granted to user hr in a non-CDB has no bearing on the privileges of an hr user that exists in a separate non-CDB.

使用者或角色可能被本地授予角色(容器=當前)。如表2-4所示,公共角色可能會獲得本地授予的特權。例如,在hrpdb中,公共角色c##dba可以在本地被授予讀取任何表特權。如果c##cdb公共角色是本地授予的,那麼角色中的特權只應用於授予角色的容器中。在本例中,具有c##cdba角色的普通使用者沒有權利在hrpdb之外的任何PDB中行使此特權,因為hrpdb中的這個角色在本地被授予了特權。

See Also:

Oracle Database Security Guide to learn how to grant roles and privileges in a CDB

Parent topic: Privileges and Roles Granted Locally in a CDB

2.2.4.3 Roles and Privileges Granted Commonly in a CDB

通常可以授予特權和公共角色。
只有在受資助者和受資助者都是通用的情況下,使用者帳戶或角色才能被授予角色和特權。如果角色是通用的,那麼角色本身必須是通用的。下表解釋了普通贈款的可能性。

Table 2-5 Common Grants

Phenomenon May Grant Commonly May Be Granted Commonly May Receive Roles and Privileges Granted Commonly

Common User Account

Yes

N/A

Yes

Local User Account

No

N/A

No

Common Role

N/A

YesFoot 3

Yes

Local Role

N/A

No

No

Privilege

N/A

Yes

N/A

Footnote 3

被授予公共角色的特權在所有容器中都可用。此外,在本地授予公共角色的任何特權僅在將該特權授予公共角色的容器中可用。

 

This section contains the following topics:

See Also:

Oracle Database Security Guide to learn more about common grants

Parent topic: Overview of Privilege and Role Grants in a CDB

2.2.4.3.1 What Makes a Grant Common

CONTAINER=ALL子句指定通常授予特權或角色.

當符合以下條件時,通常會授予角色或特權:

  • 授予人是普通使用者。
    執行授權的使用者要麼是CDB本身的通用使用者,要麼是特定應用程式容器的通用使用者。


  • 被授予者是一個普通使用者或普通角色。
    贈款的接收者對cdb本身來說是通用的,對特定的應用程式容器也是通用的。

  • 授予人具有授予指定角色或特權所需的特權。
    對於系統角色和特權,授予方必須擁有授予的角色或特權的管理選項。對於物件特權,授予方必須具有授予特權的選項。


  • 贈款適用於發生贈款的容器(無論是cdb還是應用程式容器)中的所有PDBs。
    GRANT語句包含一個CONTAINER=ALL子句,指定通常授予特權或角色。

  • 如果角色被授予,那麼它必須是通用的,如果物件特權被授予,那麼授予特權的物件必須是通用的。

Example 2-5 Granting a Privilege Commonly

在本例中,系統和c##hr_admin都是普通使用者。系統連線到CDB根,然後將CREATE任何表特權授予c##hr_admin。在這種情況下,c##hr_admin現在可以在CDB中的任何PDB中建立一個表.

CONNECT [email protected] 
Enter password: password
Connected.

GRANT CREATE ANY TABLE TO c##hr_admin CONTAINER=ALL;

小試一下

SQL> grant dba to c##test container=all;
Grant succeeded

SQL> conn c##test/[email protected]
Connected to Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 
Connected as c##[email protected]

 

 

See Also:

Oracle Database Security Guide to learn how to grant common privileges privileges

Parent topic: Roles and Privileges Granted Commonly in a CDB

2.2.4.3.2 Roles and Privileges Granted Commonly

公共使用者帳戶或角色可能會被授予通常的特權(CONTAINER=ALL).

在CDB根或應用程式根的上下文中,特權被授予當前容器中所有現有和將來的PDBs中的這個公共使用者帳戶或角色。例如,如果系統連線到CDB根,並向CDB公共使用者帳戶c##dba授予SELECT任何表特權,那麼c##dba使用者在CDB中的所有PDBs中都具有此特權。通常授予的角色或特權不能在本地撤消。

使用者或角色可能會獲得通常授予的公共角色。如表2-5的腳註所述,公共角色可以在本地獲得特權。因此,一個普通使用者可以被授予一個普通角色,這個角色可能包含本地授予的特權

例如,公共角色c##admin可以被授予對hrpdb來說是本地的SELECT任何表特權。在公共角色中本地授予的特權僅適用於授予特權的容器。因此,具有c##admin角色的普通使用者無權在salespdb或hrpdb之外的任何PDB中行使hrpdb包含的特權。

 

See Also:

Oracle Database Security Guide to learn how to grant roles and privileges in a CDB

Parent topic: Roles and Privileges Granted Commonly in a CDB

2.2.4.4 Grants to PUBLIC in a CDB

在cdb,公眾是一個常見角色。在PDB中,在本地授予PUBLIC的特權使所有本地和公共使用者帳戶僅在此PDB中行使這些特權。

授予oracle提供的使用者和角色的所有特權和角色通常都被授予,但授予PUBLIC的系統特權除外,PUBLIC是在本地授予的。這個異常之所以存在,是因為您可能希望撤銷Oracle資料庫中預設包含的某些授予,比如在SYS上執行。實現的方案.

假設hrpdb中存在本地使用者帳戶hr。此使用者在本地授予hr上的SELECT特權。員工公開。hrpdb中的普通使用者和本地使用者可以行使授予給PUBLIC的特權。salespdb或任何其他PDB中的使用者帳戶沒有查詢hr的特權。員工在hrpdb。

通常授予PUBLIC的特權使所有本地使用者能夠在各自的PDBs中行使被授予的特權,並使所有普通使用者能夠在有權訪問的PDBs中行使此特權。Oracle建議使用者通常不向公眾授予特權和角色。

See Also:

Oracle Database Security Guide to learn how the PUBLIC role works in a multitenant environment

Parent topic: Overview of Privilege and Role Grants in a CDB

2.2.4.5 Grants of Privileges and Roles: Scenario

在這個場景中,系統建立普通使用者c##dba,並嘗試給這個使用者特權來查詢hrpdb中hr模式中的表。
該場景展示了CONTAINER子句如何影響角色和特權的授予。第一列顯示了CDB$ROOT中的操作。第二列顯示hrpdb中的操作。

Table 2-6 Granting Roles and Privileges in a CDB

t Operations in CDB$ROOT Operations in hrpdb Explanation

t1

SQL> CONNECT [email protected]
Enter password: *******
Connected.

n/a

Common user SYSTEM connects to the root container.

t2

SQL> CREATE USER c##dba 
IDENTIFIED BY password 
CONTAINER=ALL;

n/a

SYSTEM creates common user c##dba. The clause CONTAINER=ALLmakes the user a common user.

t3

SQL> GRANT CREATE SESSION 
  TO c##dba;

n/a

SYSTEM grants the CREATE SESSIONsystem privilege to c##dba. Because the clause CONTAINER=ALL is absent, this privilege is granted locally and thus applies only to the root, which is the current container.

t4

SQL> CREATE ROLE c##admin 
  CONTAINER=ALL;

n/a

SYSTEM creates a common role named c##admin. The clause CONTAINER=ALLmakes the role a common role.

t5

SQL> GRANT SELECT ANY TABLE 
  TO c##admin;
Grant succeeded.

n/a

SYSTEM grants the SELECT ANY TABLE privilege to the c##admin role. The absence of the CONTAINER=ALLclause makes the privilege local to the root. Thus, this common role contains a privilege that is exercisable only in the root.

t6

SQL> GRANT c##admin TO c##dba;
SQL> EXIT;

n/a

SYSTEM grants the c##admin role to c##dba. Because the CONTAINER=ALLclause is absent, the role applies only to the current container, even though it is a common role. If c##dbaconnects to a PDB, then c##dba does not have this role.

t7

n/a

SQL> CONNECT c##[email protected]
Enter password: *******
ERROR: ORA-01045: user c##dba
lacks CREATE SESSION privilege;
logon denied

c##dba fails to connect to hrpdbbecause the grant at t3 was local to the root.

t8

n/a

SQL> CONNECT [email protected]
Enter password: *******
Connected.

SYSTEM connects to hrpdb.

t9

n/a

SQL> GRANT CONNECT, RESOURCE TO c##dba;
Grant succeeded.
SQL> EXIT

SYSTEM grants the CONNECT and RESOURCE roles to common user c##dba. Because the clause CONTAINER=ALL is absent, the grant is local to hrpdb.

t10

n/a

SQL> CONNECT c##[email protected]
Enter password: *******
Connected.

Common user c##dba connects to hrpdb.

t11

n/a

SQL> SELECT COUNT(*)
FROM hr.employees;
select * from hr.employees
                 *
ERROR at line 1:
ORA-00942: table or view does
not exist

The query of hr.employees still returns an error because c##dbadoes not have select privileges on tables in hrpdb. The SELECT ANY TABLE privilege granted locally at t5 is restricted to the root and thus does not apply to hrpdb.

t12

SQL> CONNECT [email protected]
Enter password: *******
Connected.

n/a

Common user SYSTEM connects to the root container.

t13

SQL> GRANT SELECT ANY TABLE
 TO c##admin CONTAINER=ALL;
Grant succeeded.

n/a

SYSTEM grants the SELECT ANY TABLE privilege to the c##admin role. The presence of CONTAINER=ALLmeans the privilege is being granted commonly.

t14

n/a

SQL> SELECT COUNT(*) FROM 
  hr.employees;
select * from hr.employees
                 *
ERROR at line 1:
ORA-00942: table or view does
not exist

A query of hr.employees still returns an error. The reason is that at t6 the c##admin common role was granted to c##dba in the root only.

t15

SQL> GRANT c##admin TO c##dba
  CONTAINER=ALL;
Grant succeeded.

n/a

SYSTEM grants the common role named c##admin to c##dba, specifying CONTAINER=ALL. Now user c##dba has the role in allcontainers, not just the root.

t17

n/a

SQL> SELECT COUNT(*)
  FROM hr.employees;

  COUNT(*)
----------
       107

The query succeeds.

See Also:

Oracle Database Security Guide to learn how to manage common and local roles

Parent topic: Overview of Privilege and Role Grants in a CDB

2.2.5 Overview of Common and Local Objects in a CDB

公共物件在CDB根或應用程式根中定義,可以使用元資料鏈接或物件連結引用。區域性物件是指不是普通物件的所有物件。
資料庫提供的公共物件在CDB$ROOT中定義,不能更改。Oracle資料庫不支援在CDB$ROOT中建立公共物件。

您可以將大多數模式物件(如表、檢視、PL/SQL和Java程式單元、序列等)作為應用程式根中的公共物件建立。如果物件存在於應用程式根中,則稱其為應用程式公共物件。
本地使用者可以擁有一個公共物件。此外,一個普通使用者可以擁有一個本地物件,但只有當物件不是資料鏈接或元資料鏈接,也不是元資料鏈接或資料鏈接時才可以。

See Also: