TDE (Transparent Data Encryption) Tablespace Live Conversion in Oracle 12cR2

One of the new exciting new security features in Oracle 12cR2 (12.2.0.1) , is the ability to encrypt your tablespaces “online“. In the past Implementing TDE required creating a new encrypted tablespace and then moving the data from the original tablespace to the encrypted tablespace (export/import data pump operations), which means a down time of your systems unless you use active data guard which minimizes TDE conversion implementation.

Let us now explore and simulate:

Current environment is: Oracle 12cR2 (Container Database Architecture) in Windows OS

Current ORACLE_HOME=C:\app\emodb\product\12.2.0\dbhome_2

Create a directory for the key store:

C:\app\emodb\product\12.2.0\dbhome_2\key_store

Go to sqlnet.ora file and add the below lines:

ENCRYPTION_WALLET_LOCATION=

(SOURCE=

(METHOD=file)

(METHOD_DATA=

(DIRECTORY=C:\app\emodb\product\12.2.0\dbhome_2\key_store)))

Set your COMPATIBLE Initialization parameter file to 12.2.0.0 :

SQL> ALTER SYSTEM SET COMPATIBLE = ‘12.2.0.0’ SCOPE = SPFILE;

Then execute:

SQL> ADMINISTER KEY MANAGEMENT CREATE KEYSTORE ‘C:\app\emodb\product\12.2.0\dbhome_2\key_store’ IDENTIFIED BY super_mario$88;

 

create keystore

ewallet will be created:

 

eWallet

Open the key store by executing:

SQL> ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY super_mario$88;

 

adminster key management

 

Now I will create the Master Key:

SQL> ADMINISTER KEY MANAGEMENT SET ENCRYPTION KEY IDENTIFIED BY super_mario$88 WITH BACKUP USING ‘mario_bck7’;

 

encryption key pass

Backup of key store generated (it’s better to place it in a different directory)

ewallet_backup

I have already created and activated a master key in the root container and, one in each of the pluggable databases. Now I will create local master key for pluggable database

 

SQL>alter session set container=PDBORCL;

 

SQL>ADMINISTER KEY MANAGEMENT SET KEYSTORE OPEN IDENTIFIED BY super_mario$88;

SQL>ADMINISTER KEY MANAGEMENT SET KEY IDENTIFIED BY super_mario$88 WITH BACKUP;

Now the interesting part…..the online tablespace conversion:

I will run the alter tablespace command to encrypt an existing tablespace named “COMPANY_INFO_TS”:

 

SQL>ALTER TABLESPACE COMPANY_INFO_TS  ENCRYPTION ONLINE USING ‘AES256’ ENCRYPT FILE_NAME_CONVERT = (‘COMPANY_INFO.DBF’, ‘COMPANY_INFO_ENC.DBF’);

tablespace conversion command

If you don’t specify the encryption algorithm, the default encryption will be AES128

Encrypted new data file is generated:

encrypted dbf file

 

of course you need to increase the tablespace size before your start the conversion, as the conversion process will require more space allocation.

You can use DataWalker for Oracle to test viewing the data file blocks that is not encrypted, and encrypted one:

http://www.toolswatch.org/2014/03/new-tool-datawalker-for-oracle-v1-0-in-the-wild/

 

Useful queries:

** to check wallet status

SELECT * FROM v$encryption_wallet;

** to check encryption keys created 1 in CDB and the other in PDB database:

SELECT con_id, key_id FROM v$encryption_keys;

 

ORA-30373: Object Data Types Are Not Supported In This Context , when creating Materialized View

If you face this error while creating materialized view:

 

ORA-30373: Object Data Types Are Not Supported In This Context

This means you are trying to create a Materialized View that references columns data types such as XMLTYPE or SDO_GEOMETRY or ESRI ST_GEOMETRY. This is a 12c limitation.

On the other hand, if you try to crate a materialized view with ST_GEOMETRY column this won’t be allowed.The workaround is not including the ST_GEOMETRY attribute in the materialized view.

 

Oracle Spatial Error ORA-29532: Java call terminated by uncaught Java exception ORA-06512: at “MDSYS.SDO_UTIL”, line 196

This error is received in 11g release, but fixed in 12c release :

 

ORA-29532: Java call terminated by uncaught Java exception: java.lang.RuntimeException
ORA-06512: at “MDSYS.SDO_UTIL”, line 196

is there any workaround for this problem in 11g …. YES:

1. Drop the spatial index on the geometry table
2. Run the update
3. Rebuild the spatial index

 

sqlplus error ORA-12560

This could be known and primitive to many people, however i am putting it to help the community in general from different technical-levels.

when you initiate sqlplus and trying to connect to your database instance you face the following error:

ORA-12560: TNS:protocol adapter error

 

if you are using windows OS, you need to check the following:

  1. check that the database services is up and running, go to the search icon and search for “services” and ensure all Oracle services are up and running.
  2.   if Oracle database is up and running fine, then check your environment variables in  CMD, you need to set the following:

 

set ORACLE_HOME=D:\app\db33\product\12.1.0\dbhome_33

set ORACLE_SID= ORACLE33

set PATH=D:\app\db33\product\12.1.0\dbhome_33\bin

to check that its reflected, execute the following to verify the value of ORACLE_HOME:

echo %ORACLE_HOME%

windows cmd oracle environment variables

now try initiating sqlplus and it will be working 🙂

 

 

INHERIT PRIVILEGES in Oracle 12c

Before Oracle 12c release, an Invoker Rights  unit always ran with the privileges of its invoker. If its invoker had higher privileges than its owner (for example, SYS, SYSTEM, or account with DBA role) then the IR unit might perform operations unintended by, or not authorized by the owner.

To explore first the behavior of invoker rights in 11g release, I have performed the following simulation test:

Oracle Database Release: 11.2.0.4.161018

Created a new user called “developer” with limited privileges:

CREATE USER developer

IDENTIFIED BY dodo_983

DEFAULT TABLESPACE TS_USER_DATA_01

TEMPORARY TABLESPACE TS_TEMP_DATA_01

PROFILE DEFAULT

ACCOUNT UNLOCK;

grant create session to developer ;

grant create procedure to developer ;

then the account will create a procedure:

CREATE OR REPLACE PROCEDURE priv_up  AUTHID CURRENT_USER AS

PRAGMA AUTONOMOUS_TRANSACTION;

BEGIN

EXECUTE IMMEDIATE ‘GRANT DBA TO developer’;

EXCEPTION

WHEN OTHERS THEN

NULL;

END;

/

Now the developer asks the DBA to execute multiple procedures under the schema (to trick him):

As SYS account you execute the SQL statement:

SQL> execute developer.priv_up();

 

11g-sys

 

And developer account now has DBA role !!!

Now this is a big security problem and its called “Privilege Escalation” …if your are a DBA and dealt with many third party applications, many of them provide *.sql scripts (tens of them sometimes) and you don’t have the time to inspect all sql code, this very difficult and hectic job.

 

In 12c This has been changed Invoker Rights unit can run with the privileges of its invoker only if its owner has either the INHERIT PRIVILEGES privilege on the invoker or the INHERIT ANY PRIVILEGES privilege.

A new account “developer” with the following definition:

CREATE USER developer

IDENTIFIED BY dodo_983

DEFAULT TABLESPACE TS_USER_DATA_01

TEMPORARY TABLESPACE TS_TEMP_DATA_01

PROFILE DEFAULT

ACCOUNT UNLOCK;

 

grant create session to developer ;

grant create procedure to developer ;

 

Now the developer creates a new function and a procedure (that has embedded SQL statement for granting):

 

CREATE OR REPLACE PROCEDURE priv_up  AUTHID CURRENT_USER AS

PRAGMA AUTONOMOUS_TRANSACTION;

BEGIN

EXECUTE IMMEDIATE ‘GRANT DBA TO developer’;

EXCEPTION

WHEN OTHERS THEN

NULL;

END;

/

A new account “super_user” with the following definition:

 

CREATE USER super_user

IDENTIFIED BY roro_983

DEFAULT TABLESPACE TS_USER_DATA_01

TEMPORARY TABLESPACE TS_TEMP_DATA_01

PROFILE DEFAULT

ACCOUNT UNLOCK;

 

grant create session to super_user ;

 

grant dba to super_user ;

 

SELECT grantee FROM   dba_role_privs WHERE  granted_role = ‘DBA’ ORDER BY grantee ;

 

users-with-dba

 

Connecting now as “superuser” account:

 

The powerful account “super_user” was tricked to execute the procedure:

SQL> execute developer.priv_up();

Now “developer” account has the “DBA” role!!!!

 

developer-dba-role

 

To remediate this:

 

SQL> REVOKE INHERIT PRIVILEGES ON USER super_user FROM PUBLIC;

 

revoke-inherit-privileges-from-public

 

Now if the super user tries to execute the procedure he will receive the below error:

 

ora06598

 

So, the procedure called by super_user wants to exercise one of super_user account privileges that the creator of the procedure (developer user) lacks.

Important Remark: executing the same procedure using “SYS” or “SYSTEM” accounts will by default lead to the same error ORA-06598 which is great since it will protect the SYS account from executing undesired (untrusted) SQL code.

its worth mentioning also, that if you try perform export data pump backup for schema  using SYS user after revoking INHERIT PRIVILEGE from all accounts from public, you will receive in the export log the below error:

ORA-06598: insufficient INHERIT PRIVILEGES privilege

To fix this export error:

SQL> GRANT INHERIT PRIVILEGES ON USER  SYS TO schema_Account;

 

This is a very nice security enhancement in 12c …..Thank You Oracle 🙂

Oracle Enterprise Manager 13c Error ORA-06512: at “SYSMAN.EM_TARGET”, line 9634

while installing Oracle Enterprise Manager 13c Cloud Control  i have faced the below errors:

ORA-01722: invalid number

ORA-06512: at “SYSMAN.EM_TARGET”, line 9634

ORA-06512: at “SYSMAN.EM_TARGET”, line 10403

ORA-06512: at “SYSMAN.EM_SYSTEM”, line 324

ORA-06512: at “SYSMAN.EM_SYSTEM”, line 242

ORA-06512: at “SYSMAN.MGMT_SYSTEM”, line 32

ORA-06512: at “SYSMAN.CFW_LIFECYCLE”, line 90

ORA-06512: at “SYSMAN.CFW_SERVICE_FAMILY”, line 58

ORA-06512: at line 15

 

To resolve this:

Set the following parameter:

 

SQL> alter system set optimizer_mode=all_rows scope=both;

 

Cheers ! 🙂

 

Oracle 12c Database Data Redaction – DBMS_REDACT

With Oracle Database 12c, Oracle has introduced a new PL/SQL package called DBMS_REDACT to support data masking or data redaction. This new feature is also back ported to Oracle version 11.2.0.4.

DBMS_REDACT Package has the following procedures that perform different actions:

dbms_redact-proc

I will now explore it with an example:

Querying the original table:

SQL> select * from HR.JOBS_TEMP ;

jobs_temp-table-data

Execute the following as SYS:

begin
       dbms_redact.add_policy(
       object_schema => ‘HR’,
       object_name   => ‘JOBS_TEMP’,
       column_name   => ‘MIN_SALARY’,
       policy_name   => ‘redect_jobs_min_salary’,
       function_type => DBMS_REDACT.FULL,
       expression    => ‘1=1’);
  end;

Re-executing the query  with an account that has “SELECT” permission on the table will illustrate “FULL REDACTION” of the column values:

jobs_temp-table-redact

To disable a policy:

BEGIN

  DBMS_REDACT.DISABLE_POLICY (

    object_schema  => ‘HR’,

    object_name    => ‘JOBS_TEMP’,

    policy_name    => ‘redect_jobs_min_salary’);

END;

/

The following query will list the current configured redaction policy:

SQL> select * from REDACTION_POLICIES;

query-to-list-redact-policies

The following query will list currently redacted columns:

SQL> select * from REDACTION_COLUMNS;

query-to-list-redact-columns

The following policy will mask the data for un-authorized users, so non-HR users won’t be able to see the maximum salary using expression statement:

BEGIN

 DBMS_REDACT.ADD_POLICY(

   object_schema   => ‘HR’,

   object_name     => ‘JOBS_TEMP’,

   column_name     => ‘MAX_SALARY’,

   policy_name     => ‘JOBS_TEMP_MAX_SAL’,

   function_type   => DBMS_REDACT.FULL,

   expression      => ‘SYS_CONTEXT(”USERENV”, ”SESSION_USER”)!= ”HR”’);

END;

/

Important remark: only 1 policy can be applied on a table or a view. Trying to create another policy on the same table will result with the following errors:

ORA-28069: A data redaction policy already exists on this object.

ORA-06512: at “SYS.DBMS_REDACT_INT”, line 3

ORA-06512: at “SYS.DBMS_REDACT”, line 42

ORA-06512: at line 2

To add other columns to the current policy, use DBMS_REDACT.ALTER_POLICY and add DBMS_REDACT.ADD_COLUMN.

of course redacting data in a column won’t provide protection against “SYS” account , or user granted “DBA” role from viewing the real data.

physical standby errors ORA-00600 ORA-10567 ORA-10564 ORA-01110 ORA-10561

The following errors were thrown while trying to sync physical standby database with the primary database:

ORA-00600: internal error code, arguments: [3020], [239], [13749],
[1002452405], [], [], [], [], [], [], [], []
ORA-10567: Redo is inconsistent with data block (file# 239, block# 13749, file
offset is 112631808 bytes)
ORA-10564: tablespace SYSAUX
ORA-01110: data file 211: ‘/database/orcl07/SYSAUX01.ORA’
ORA-10561: block type ‘TRANSACTION MANAGED INDEX BLOCK’, data object# 2877779

To resolve this you have 2 approaches …..choose one:

******************** First Approach *********************************

1. on the primary database

RMAN> rman target /

run
{
ALLOCATE CHANNEL ch1 DEVICE TYPE DISK format ‘/database/orcl07/backup/inc_SYSYAUX_%U’;
backup datafile 211;
release channel ch1;
}

—-  after executing the above rman command a backup of set for the data file will be generated and will require copying to the physical standby database server

scp inc_SYSYAUX_m7robspv_1_1 standby_server:/database/orcl07/backup/

2. on the standby database:

RMAN> catalog start with ‘/oradbp21/export/bkp/’;
RMAN> shutdown immediate;
RMAN> startup mount;
RMAN> restore datafile 239;
RMAN> exit;

SQL> RECOVER AUTOMATIC STANDBY DATABASE;

******************** Second Approach *********************************

1. on the standby database:

SQL> shutdown immediate;

2. on the primary database:

SQL> ALTER tablespace SYSAUX begin backup;

scp /database/orcl07/SYSAUX01.ORA standby_server:/database/orcl07/SYSAUX01.ORA

SQL> ALTER tablespace SDE end backup ;

3. on the standby database:
SQL> STARTUP NOMOUNT
SQL> ALTER DATABASE MOUNT STANDBY DATABASE;
SQL> RECOVER AUTOMATIC STANDBY DATABASE;