{"id":55,"date":"2014-10-21T11:34:51","date_gmt":"2014-10-21T11:34:51","guid":{"rendered":"https:\/\/www.spotonoracle.com\/?p=55"},"modified":"2016-05-10T16:30:41","modified_gmt":"2016-05-10T16:30:41","slug":"dont-ditch-audit_trail-prematurely","status":"publish","type":"post","link":"https:\/\/www.spotonoracle.com\/?p=55","title":{"rendered":"Don&#8217;t ditch AUDIT_TRAIL prematurely"},"content":{"rendered":"<p>When migrating to unified auditing in Oracle 12c I faced a strange behaviour in the recording of LOGON \/ LOGOFF actions.<\/p>\n<p>As the <a href=\"http:\/\/docs.oracle.com\/database\/121\/REFRN\/refrn10006.htm#REFRN10006\" target=\"_blank\">Oracle 12c documentation<\/a> points out, the AUDIT_* parameters have no effect once you enable unified auditing. Guess what I did in the good spirit of cleaning up obsolete settings:<br \/>\nI reset those parameters in the spfile after enabling unified auditing.<\/p>\n<p>Enable unified auditing by relinking the oracle binary.<\/p>\n<pre class=\"brush: sql; collapse: false; title: ; wrap-lines: false; notranslate\" title=\"\">\r\n$ cd ${ORACLE_HOME}\/rdbms\/lib\r\n$ make -f ins_rdbms.mk uniaud_on ioracle ORACLE_HOME=${ORACLE_HOME}\r\n\r\nSQL&gt; show parameter audit_trail\r\nNAME          TYPE        VALUE\r\n------------- ----------- ----------\r\naudit_trail   string      NONE\r\n<\/pre>\n<p>I disabled all the Oracle built-in audit policies and created my own to record LOGON \/ LOGOFF actions.<\/p>\n<pre class=\"brush: sql; collapse: false; title: ; wrap-lines: false; notranslate\" title=\"\">\r\nSQL&gt; create audit policy audpol_connection\r\n     actions logon, logoff;\r\n\r\nAudit policy created.\r\n\r\nSQL&gt; audit policy audpol_connection;\r\n\r\nAudit succeeded.\r\n\r\nSQL&gt; select * from audit_unified_enabled_policies;\r\n\r\nUSER_NAME       POLICY_NAME          ENABL SUC FAI\r\n--------------- -------------------- ----- --- ---\r\nALL USERS       AUDPOL_CONNECTION    BY    YES YES\r\n\r\nSQL&gt; select * from audit_unified_policies\r\n     where policy_name = 'AUDPOL_CONNECTION'\r\n     and audit_option like '%LOGO%';\r\n\r\nPOLICY_NAME          AUDIT CONDI AUDIT_OPTION    AUDIT_OPTION_TY OBJEC OBJEC OBJEC COMMO\r\n-------------------- ----- ----- --------------- --------------- ----- ----- ----- -----\r\nAUDPOL_CONNECTION    NONE  NONE  LOGOFF          STANDARD ACTION NONE  NONE  NONE\r\nAUDPOL_CONNECTION    NONE  NONE  LOGON           STANDARD ACTION NONE  NONE  NONE\r\n<\/pre>\n<p>This shows, that my audit policy is enabled and should record LOGON and LOGOFF actions.<\/p>\n<p>I also want the audit trail to be written immediately so it becomes visible in UNIFIED_AUDIT_TRAIL view without waiting for the flush to happen (or explicitly flushing it every time).<\/p>\n<pre class=\"brush: sql; collapse: false; title: ; wrap-lines: false; notranslate\" title=\"\">\r\nSQL&gt; exec dbms_audit_mgmt.set_audit_trail_property(\r\n         dbms_audit_mgmt.audit_trail_unified\r\n       , dbms_audit_mgmt.audit_trail_write_mode\r\n       , dbms_audit_mgmt.audit_trail_immediate_write\r\n     )\r\n\r\nPL\/SQL procedure successfully completed.\r\n<\/pre>\n<p>For the sake of clean output let&#8217;s purge the existing audit trail.<\/p>\n<pre class=\"brush: sql; collapse: false; title: ; wrap-lines: false; notranslate\" title=\"\">\r\nSQL&gt; exec dbms_audit_mgmt.clean_audit_trail(\r\n         dbms_audit_mgmt.audit_trail_unified\r\n       , false\r\n     )\r\n\r\nPL\/SQL procedure successfully completed.\r\n<\/pre>\n<p>So far so good. Now begins the actual test case by connecting to the database from a different terminal.<\/p>\n<pre class=\"brush: sql; collapse: false; title: ; wrap-lines: false; notranslate\" title=\"\">\r\n$ sqlplus system\/manager@dev1\r\n\r\nSQL*Plus: Release 12.1.0.2.0 Production on Tue Oct 21 17:39:02 2014\r\nCopyright (c) 1982, 2014, Oracle.  All rights reserved.\r\nLast Successful login time: Tue Oct 21 2014 17:38:49 +02:00\r\nConnected to:\r\nOracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production\r\nWith the Partitioning, OLAP, Advanced Analytics, Real Application Testing and Unified Auditing options\r\n<\/pre>\n<p>Note that I have not logged out yet&#8230;<\/p>\n<p>Checking in my original session we cannot find any LOGON event recorded. I most definitively expected to see a LOGON event.<\/p>\n<pre class=\"brush: sql; collapse: false; title: ; wrap-lines: false; notranslate\" title=\"\">\r\nSQL&gt; select audit_type, sessionid, dbusername, event_timestamp, action_name, return_code\r\n     from unified_audit_trail\r\n     where action_name like '%LOG%'\r\n     order by event_timestamp;\r\n\r\nno rows selected\r\n\r\n<\/pre>\n<p>After disconnecting from the other session the LOGOFF event becomes visible.<\/p>\n<pre class=\"brush: sql; collapse: false; title: ; wrap-lines: false; notranslate\" title=\"\">\r\nSQL&gt; select audit_type, sessionid, dbusername, event_timestamp, action_name, return_code\r\n     from unified_audit_trail\r\n     where action_name like '%LOG%'\r\n     order by event_timestamp;\r\n\r\nAUDIT_TYPE SESSIONID    DBUSERNAME    EVENT_TIMESTAMP                 ACTION_NAME     RETURN_CODE\r\n---------- ------------ ------------- ------------------------------- --------------- -----------\r\nStandard   2253237941   SYSTEM        21-OCT-14 05.13.38.712564 PM    LOGOFF          0\r\n\r\n<\/pre>\n<p>I have run multiple different test with different clients, connection methods, etc. all ending with the same result: Oracle just wont record LOGON actions! We only get to see the LOGOFF event.<\/p>\n<p>Against all odds and feeling a little desperate I eventually decided to set &#8220;AUDIT_TRAIL = DB&#8221; and give it a go.<\/p>\n<pre class=\"brush: sql; collapse: false; title: ; wrap-lines: false; notranslate\" title=\"\">\r\nSQL&gt; show parameter audit_trail\r\n\r\nNAME          TYPE        VALUE\r\n------------- ----------- ----------\r\naudit_trail   string      DB\r\n<\/pre>\n<p>I purged the audit trail and ran the same test as before again.<\/p>\n<p>Connect from a differen terminal to the database.<\/p>\n<pre class=\"brush: sql; collapse: false; title: ; wrap-lines: false; notranslate\" title=\"\">\r\n$ sqlplus system\/manager@dev1\r\n\r\nSQL*Plus: Release 12.1.0.2.0 Production on Tue Oct 21 17:39:02 2014\r\nCopyright (c) 1982, 2014, Oracle.  All rights reserved.\r\nLast Successful login time: Tue Oct 21 2014 17:38:49 +02:00\r\nConnected to:\r\nOracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production\r\nWith the Partitioning, OLAP, Advanced Analytics, Real Application Testing and Unified Auditing options\r\n<\/pre>\n<p>Check the unified audit trail &#8211; and there it is.<\/p>\n<pre class=\"brush: sql; collapse: false; title: ; wrap-lines: false; notranslate\" title=\"\">\r\nSQL&gt; select audit_type, sessionid, dbusername, event_timestamp, action_name, return_code\r\n     from unified_audit_trail\r\n     where action_name like '%LOG%'\r\n     order by event_timestamp;\r\n\r\nAUDIT_TYPE SESSIONID    DBUSERNAME    EVENT_TIMESTAMP                 ACTION_NAME     RETURN_CODE\r\n---------- ------------ ------------- ------------------------------- --------------- -----------\r\nStandard   1706589952   SYSTEM        21-OCT-14 07.17.46.063184 PM    LOGON           0\r\n\r\n<\/pre>\n<p>After disconnecting from the other session I can again see the LOGOFF action.<\/p>\n<pre class=\"brush: sql; collapse: false; title: ; wrap-lines: false; notranslate\" title=\"\">\r\nSQL&gt; select audit_type, sessionid, dbusername, event_timestamp, action_name, return_code\r\n     from unified_audit_trail\r\n     where action_name like '%LOG%'\r\n     order by event_timestamp;\r\n\r\nAUDIT_TYPE SESSIONID    DBUSERNAME    EVENT_TIMESTAMP                 ACTION_NAME     RETURN_CODE\r\n---------- ------------ ------------- ------------------------------- --------------- -----------\r\nStandard   1706589952   SYSTEM        21-OCT-14 07.17.46.063184 PM    LOGON           0\r\nStandard   1706589952   SYSTEM        21-OCT-14 07.18.02.661384 PM    LOGOFF          0\r\n\r\n<\/pre>\n<p>In my opinion this does not work as designed as I believe Oracle actually wanted the AUDIT_* parameters to have no effect on unified auditing. I haven&#8217;t tested exhaustively but I imagine there might be other problems with unified auditing when AUDIT_TRAIL is set to NONE. So, test carefully whether all your auditing is working as expected.<\/p>\n<p>Foot note: All test have been run on Oracle 12.1.0.2<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When migrating to unified auditing in Oracle 12c I faced a strange behaviour in the recording of LOGON \/ LOGOFF actions. As the Oracle 12c documentation points out, the AUDIT_* parameters have no effect once you enable unified auditing. Guess what I did in the good spirit of cleaning up obsolete settings: I reset those [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,3],"tags":[],"class_list":["post-55","post","type-post","status-publish","format-standard","hentry","category-auditing","category-internals"],"_links":{"self":[{"href":"https:\/\/www.spotonoracle.com\/index.php?rest_route=\/wp\/v2\/posts\/55","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.spotonoracle.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.spotonoracle.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.spotonoracle.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.spotonoracle.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=55"}],"version-history":[{"count":2,"href":"https:\/\/www.spotonoracle.com\/index.php?rest_route=\/wp\/v2\/posts\/55\/revisions"}],"predecessor-version":[{"id":57,"href":"https:\/\/www.spotonoracle.com\/index.php?rest_route=\/wp\/v2\/posts\/55\/revisions\/57"}],"wp:attachment":[{"href":"https:\/\/www.spotonoracle.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=55"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.spotonoracle.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=55"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.spotonoracle.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=55"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}