{"id":404,"date":"2020-11-05T19:29:12","date_gmt":"2020-11-05T18:29:12","guid":{"rendered":"https:\/\/anjo.pt\/keyword-oracle\/?p=404"},"modified":"2021-01-30T14:10:49","modified_gmt":"2021-01-30T13:10:49","slug":"get-unlock-from-pdb-lockdown-profiles","status":"publish","type":"post","link":"https:\/\/anjo.pt\/keyword-oracle\/2020\/11\/05\/get-unlock-from-pdb-lockdown-profiles\/","title":{"rendered":"Get unlock from PDB Lockdown profiles"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">PDB Lockdown profiles allow, on a multitenant database, to limit what a user can do inside a PDB.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">One use case is when we want to avoid high privileged users (like Application DBAs) to perform ALTER SYSTEM or ALTER SESSION commands.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Quickly we would think we can do a PDB Lockdown profile like:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; create lockdown profile lock_test;\nSQL&gt; alter lockdown profile lock_test disable statement=(&#039;ALTER SESSION&#039;);\nSQL&gt; alter lockdown profile lock_test disable statement=(&#039;ALTER SYSTEM&#039;);\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">The problem of this simple profile is that we can lock ourselves, also as common user, inside the lock profile. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Image that you want to enable this profile on several PDBs:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; alter session set container=pdb01;\nSession altered.\n\nSQL&gt; alter system set pdb_lockdown=lock_test;\nSystem altered.\n\nSQL&gt; alter session set container=samplepdb;\nERROR:\nORA-01031: insufficient privileges\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Oups, you cannot anymore change the active container!<\/p>\n\n\n\n<!--more-->\n\n\n\n<p class=\"wp-block-paragraph\">One has to reconnect to the CDB and then can go to the second PDB and apply the lockdown profile:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; connect \/ as sysdba\nConnected.\n\nSQL&gt; alter session set container=samplepdb;\nSession altered.\n\nSQL&gt; alter system set pdb_lockdown=lock_test;\nSystem altered.\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">What if now I (I&#8217;m the CDB DBA and have SYSDBA rights) want to change a parameter on one of the PDBs? <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It is not possible to disable the pdb_lockdown profile:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; connect \/ as sysdba\nConnected.\n\nSQL&gt; alter session set container=samplepdb;\nSession altered.\n\nSQL&gt; alter session set pdb_lockdown=&#039;&#039;;\nERROR:\nORA-01031: insufficient privileges\n\nSQL&gt; alter system set pdb_lockdown=&#039;&#039;;\nalter system set pdb_lockdown=&#039;&#039;\n*\nERROR at line 1:\nORA-01031: insufficient privileges\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Two possible options are:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>drop the PDB Lockdown on Root container<\/li><\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; connect \/ as sysdba\nConnected.\n\nSQL&gt; drop lockdown profile lock_test ;\nLockdown Profile dropped.\n\nSQL&gt; alter session set container=samplepdb;\nSession altered.\n\nSQL&gt; alter system set pdb_lockdown=&#039;&#039;;\nSystem altered.\n<\/pre><\/div>\n\n\n<ul class=\"wp-block-list\"><li>change the existing lockdown profile temporarily to allow operations<\/li><\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; connect \/ as sysdba\nConnected.\n\nSQL&gt; alter lockdown profile lock_test enable statement=(&#039;ALTER SYSTEM&#039;) users=common;\nLockdown Profile altered.\n\nSQL&gt; alter session set container=samplepdb;\nSession altered.\n\nSQL&gt; alter system set pdb_lockdown=&#039;&#039;;\nSystem altered.\n\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">The problem of this two solutions is that the relax of the lockdown profile will apply to all the PDBs where it is enabled. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If we want just temporarily be super users and skip the lockdown profile, the solution is to disable on the session on the cdb$root and then change to another container. During our session we will not have any lockdown profile enabled.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSQL&gt; -- Connected to CDB$ROOT\nSQL&gt; show con_name\nCON_NAME\n------------------------------\nCDB$ROOT\n\nSQL&gt; -- Lockdown profiles enabled on PDBs\nSQL&gt; select b.name PDB,a.name, value$ from pdb_spfile$ a join v$pdbs b on b.con_uid=a.pdb_uid where a.name=&#039;pdb_lockdown&#039;;\nPDB        NAME                 VALUE$\n---------- -------------------- ---------------\nSAMPLEPDB  pdb_lockdown         &#039;LOCK_TEST&#039;\nPDB01      pdb_lockdown         &#039;LOCK_TEST&#039;\n\nSQL&gt; -- Lockdown profile disables alter system and alter session\nSQL&gt; select con_id,profile_name,rule,clause,status,users,except_users from cdb_lockdown_profiles;\n    CON_ID PROFILE_NA RULE                      CLAUS STATUS  USERS  EXCEPT_USE\n---------- ---------- ------------------------- ----- ------- ------ ----------\n         1 LOCK_TEST  ALTER SESSION                   DISABLE ALL\n         1 LOCK_TEST  ALTER SYSTEM                    DISABLE ALL\n\nSQL&gt; -- As common user on cdb$root we can change the session pdb_lockdown profile\nSQL&gt; alter session set pdb_lockdown=&#039;&#039;;\nSession altered.\n\nSQL&gt; -- And this will go with us to the next container\nSQL&gt; alter session set container=PDB01;\nSession altered.\n\nSQL&gt; show parameter pdb_lockdown\nNAME                                 TYPE        VALUE\n------------------------------------ ----------- ------------------------------\npdb_lockdown                         string\n\nSQL&gt; alter system set open_cursors=300;\nSystem altered.\n\nSQL&gt; -- If we reconnect, the lockdown profile is still there\nSQL&gt; connect \/ as sysdba\nConnected.\nSQL&gt; alter session set container=PDB01;\nSession altered.\n\nSQL&gt; show parameter pdb_lockdown\nNAME                                 TYPE        VALUE\n------------------------------------ ----------- ------------------------------\npdb_lockdown                         string      LOCK_TEST\n\nSQL&gt; alter system set open_cursors=300;\nalter system set open_cursors=300\n*\nERROR at line 1:\nORA-01031: insufficient privileges\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"> What is interesting to notice from this behaviour is:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>when changing a session parameter on cdb$root, this parameter will remain active also when going to another containers within the same session.<\/p><\/blockquote>\n\n\n\n<p class=\"wp-block-paragraph\">The parameters that were not changed on session level, will get adapted when changing to another container, with the values set specifically for that container.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PDB Lockdown profiles allow, on a multitenant database, to limit what a user can do inside a PDB. One use case is when we want to avoid high privileged users (like Application DBAs) to perform ALTER SYSTEM or ALTER SESSION commands. Quickly we would think we can do a PDB Lockdown profile like: The problem [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,39,9],"tags":[],"class_list":["post-404","post","type-post","status-publish","format-standard","category-oracle","category-oracle-19c","category-security","czr-hentry"],"_links":{"self":[{"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/posts\/404","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/comments?post=404"}],"version-history":[{"count":2,"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/posts\/404\/revisions"}],"predecessor-version":[{"id":453,"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/posts\/404\/revisions\/453"}],"wp:attachment":[{"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/media?parent=404"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/categories?post=404"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/anjo.pt\/keyword-oracle\/wp-json\/wp\/v2\/tags?post=404"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}