What happens when using Online Tablespace Encryption

Categories: Oracle Database · Security · Online Tablespace Encryption

What’s up guys? Here just a quick overview of what happens when you use the new feature Online Tablespace Encryption of Oracle Database 12cR2 Oracle Database 12c Release 2.

I just want to show what Oracle does when encrypting an existing tablespace online. So let us see the example.

Connect to the database:

[oracle@oracle-srv ~]$ sqlplus / as sysdba

SQL*Plus: Release 12.2.0.1.0 Production on Sun Nov 26 20:51:21 2017

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

As we are dealing with TDE we have to check the wallet status:

SQL> SET LIN 1000
SQL> COL WRL_PARAMETER FORM A60
SQL> COL STATUS FORM A20
SQL> SELECT WRL_PARAMETER,STATUS,WALLET_TYPE FROM V$ENCRYPTION_WALLET;

WRL_PARAMETER						     					 STATUS		  		  WALLET_TYPE
------------------------------------------------------------ -------------------- --------------------
/u01/app/oracle/product/12.2.0.1/			     			 OPEN		  		  PASSWORD

Encryption

It is open at the CDB level, but the tablespace I want to change is on a PDB, so I will alternate my session to SOEPDB:

SQL> alter session set container=soepdb;

Session altered.

Let us try to encrypt the tablespace:

SQL> ALTER TABLESPACE tsdsoe ENCRYPTION ONLINE USING 'AES192' ENCRYPT;
ALTER TABLESPACE tsdsoe ENCRYPTION ONLINE USING 'AES192' ENCRYPT
*
ERROR at line 1:
ORA-28374: typed master key not found in wallet

It did not work, since I did not have a keystore for this PDB yet.

So let’s create the keystore:

SQL> ADMINISTER KEY MANAGEMENT SET KEY IDENTIFIED BY "oracle" WITH BACKUP USING 'mkey_bkp' ;

keystore altered.

Now we try to encrypt again:

SQL> ALTER TABLESPACE tsdsoe ENCRYPTION ONLINE USING 'AES192' ENCRYPT;

Tablespace altered.

Fine, it worked. Let’s query dba_tablespaces to check:

SQL> select TABLESPACE_NAME, STATUS, CONTENTS, ENCRYPTED from dba_tablespaces;

TABLESPACE_NAME 	       	   STATUS	 CONTENTS	       	   ENC
------------------------------ --------- --------------------- ---
SYSTEM			       		   ONLINE	 PERMANENT	           NO
SYSAUX			       		   ONLINE	 PERMANENT	           NO
UNDOTBS1		       		   ONLINE	 UNDO		           NO
TEMP			       		   ONLINE	 TEMPORARY	           NO
TSDSOE			       		   ONLINE	 PERMANENT	           YES

5 rows selected.

Here comes the interesting part… If we check the alert.log we will see what just happened. I will split it to explain better.

Here the error due to the missing keystore:

2017-11-26T20:51:42.178245+01:00
SOEPDB(3):ALTER TABLESPACE tsdsoe ENCRYPTION ONLINE USING 'AES192' ENCRYPT
SOEPDB(3):ORA-28374 signalled during: ALTER TABLESPACE tsdsoe ENCRYPTION ONLINE USING 'AES192' ENCRYPT...

Here we have the keystore that was just created:

2017-11-26T20:52:10.014414+01:00
SOEPDB(3):Creating new database key for new master key and wallet
SOEPDB(3):Creating new database key with the new master key
SOEPDB(3):Retiring: ena 2 flag 6 mkloc 0
SOEPDB(3):   encrypted key 2b1a5e2f3558f388cbfb462baade6d4d00000000000000000000000000000000
SOEPDB(3):   mkid a143b7686a934fedbfdcf2064294430e
SOEPDB(3):Creating: ena 2 flag e mkloc 1
SOEPDB(3):   encrypted key e219426db356adfcaf17b19e958ea28300000000000000000000000000000000
SOEPDB(3):   mkid 88b8e3272f964f41bf3dacd75e230de2
SOEPDB(3):New database key and new master key created successfully

And here is the encryption procedure itself. Observe that Oracle copied data from an existing datafile to a new one:

2017-11-26T20:52:21.577789+01:00
SOEPDB(3):ALTER TABLESPACE tsdsoe ENCRYPTION ONLINE USING 'AES192' ENCRYPT
2017-11-26T20:52:21.584722+01:00
SOEPDB(3):About to encrypt tablespace TSDSOE (tsn 3/4)
SOEPDB(3):Rekeying datafile /u02/oradata/CDB2/58542FF64D541288E0530F0FA8C0C065/datafile/o1_mf_tsdsoe_dtsdhmr8_.dbf (12) to /u02/oradata/CDB2/58542FF64D541288E0530F0FA8C0C065/datafile/o1_mf_tsdsoe_%u_.dbf
2017-11-26T20:52:26.449204+01:00
SOEPDB(3):Rekey operation committed for file /u02/oradata/CDB2/58542FF64D541288E0530F0FA8C0C065/datafile/o1_mf_tsdsoe_f1p6vonj_.dbf

And then deleted the non encrypted datafile:

2017-11-26T20:52:28.462284+01:00
SOEPDB(3):About to zero out original file "/u02/oradata/CDB2/58542FF64D541288E0530F0FA8C0C065/datafile/o1_mf_tsdsoe_dtsdhmr8_.dbf"
2017-11-26T20:52:30.658380+01:00
SOEPDB(3):Successfully zero'ed out original file "/u02/oradata/CDB2/58542FF64D541288E0530F0FA8C0C065/datafile/o1_mf_tsdsoe_dtsdhmr8_.dbf"
SOEPDB(3):Successfully deleted original file "/u02/oradata/CDB2/58542FF64D541288E0530F0FA8C0C065/datafile/o1_mf_tsdsoe_dtsdhmr8_.dbf"
SOEPDB(3):Completed rekey for tablespace TSDSOE (tsn 3/4) from key version 0 to 1.
SOEPDB(3):Completed: ALTER TABLESPACE tsdsoe ENCRYPTION ONLINE USING 'AES192' ENCRYPT
2017-11-26T20:53:41.656374+01:00

So when you want to online encrypt a tablespace make sure you have enough room to double the size of this tablespace for this operation to be successfully concluded.

Hope you enjoyed it!

Best regards,

Franky

Earlier comments

  1. Olexandr Siroklyn

    Hello Franky,

    Thanks for a good article. If suddenly you’re interested to have information about a way to have inexpensive row level data encryption for Oracle database standard or enterprise edition 11g and 12c versions,

    may I propose you to look at FCBCrypto software product page http://www.oracleongpu.com/fcbcrypto/

    ?

    Thank you.

    With best wishes,

    Olexandr

Comments