forked from docs/doc-exports
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com> Co-authored-by: Lu, Huayi <luhuayi@huawei.com> Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
70 lines
17 KiB
HTML
70 lines
17 KiB
HTML
<a name="EN-US_TOPIC_0000001098830728"></a><a name="EN-US_TOPIC_0000001098830728"></a>
|
|
|
|
<h1 class="topictitle1">CREATE REDACTION POLICY</h1>
|
|
<div id="body0000001125005011"><div class="section" id="EN-US_TOPIC_0000001098830728__section64541617155413"><h4 class="sectiontitle">Function</h4><p id="EN-US_TOPIC_0000001098830728__p48721529133312"><strong id="EN-US_TOPIC_0000001098830728__b15755191483412">CREATE REDACTION POLICY</strong> creates a data redaction policy for a table.</p>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001098830728__section530426175413"><h4 class="sectiontitle">Precautions</h4><ul id="EN-US_TOPIC_0000001098830728__ul2301626185417"><li id="EN-US_TOPIC_0000001098830728__li6508144710461">Only the table owner has the permission to create a data redaction policy.</li><li id="EN-US_TOPIC_0000001098830728__li5717812205115">You can create data redaction policies only for ordinary tables. Redaction policies are unavailable to system catalogs, HDFS tables, foreign tables, temporary tables, UNLOGGED tables, views, and functions.</li><li id="EN-US_TOPIC_0000001098830728__li10543192315366">Synonyms cannot be used to create redaction policies for ordinary table objects.</li><li id="EN-US_TOPIC_0000001098830728__li62391740173610">Table objects and redaction policies have a one-to-one mapping relationship. A redaction policy is a collection of data redaction functions that can be applied to multiple columns in a table. You can set different redaction functions for different columns.</li><li id="EN-US_TOPIC_0000001098830728__li1620843714471">A redaction policy is enabled by default upon its creation, that is, the <strong id="EN-US_TOPIC_0000001098830728__b85391223193420">enable</strong> parameter of the policy is <strong id="EN-US_TOPIC_0000001098830728__b7917183614349">true</strong> by default.</li><li id="EN-US_TOPIC_0000001098830728__li19350134104912">Redaction policies do not take effect on users with the <strong id="EN-US_TOPIC_0000001098830728__b82320466342">sysadmin</strong> permission. Data in the redacted columns is always visible to such users.</li></ul>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001098830728__s76b82d2844864556836665e71507845d"><h4 class="sectiontitle">Syntax</h4><div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001098830728__screen173304864816"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
|
|
<span class="normal">2</span>
|
|
<span class="normal">3</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">CREATE</span><span class="w"> </span><span class="n">REDACTION</span><span class="w"> </span><span class="n">POLICY</span><span class="w"> </span><span class="n">policy_name</span><span class="w"> </span><span class="k">ON</span><span class="w"> </span><span class="k">table_name</span><span class="w"></span>
|
|
<span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">WHEN</span><span class="w"> </span><span class="p">(</span><span class="n">when_expression</span><span class="p">)</span><span class="w"> </span><span class="p">]</span><span class="w"></span>
|
|
<span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">ADD</span><span class="w"> </span><span class="k">COLUMN</span><span class="w"> </span><span class="k">column_name</span><span class="w"> </span><span class="k">WITH</span><span class="w"> </span><span class="n">redaction_function_name</span><span class="w"> </span><span class="p">(</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="n">argument</span><span class="w"> </span><span class="p">[,</span><span class="w"> </span><span class="p">...]</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="p">)]</span><span class="w"> </span><span class="p">[,</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="p">];</span><span class="w"></span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001098830728__section329711615553"><h4 class="sectiontitle">Parameter Description</h4><ul id="EN-US_TOPIC_0000001098830728__ul13297216165518"><li id="EN-US_TOPIC_0000001098830728__le0d876a4740142cba6070d2bfa9fe052"><strong id="EN-US_TOPIC_0000001098830728__a9135027b510a46a6a4c96ad94015b654">policy_name</strong><p id="EN-US_TOPIC_0000001098830728__p47444371904">Specifies the name of a redaction policy.</p>
|
|
</li><li id="EN-US_TOPIC_0000001098830728__l59953a97ae544273852d23e58811e857"><strong id="EN-US_TOPIC_0000001098830728__aafb71be4f77c42b09bc43534c8375b37">table_name</strong><p id="EN-US_TOPIC_0000001098830728__p129154115187">Specifies the name of the table to which the redaction policy is applied.</p>
|
|
</li><li id="EN-US_TOPIC_0000001098830728__li549719951616"><strong id="EN-US_TOPIC_0000001098830728__b141373218180">WHEN ( when_expression )</strong><p id="EN-US_TOPIC_0000001098830728__p11491174112011">Specifies the expression used for the redaction policy to take effect. The redaction policy takes effect only when this expression is true.</p>
|
|
<div class="note" id="EN-US_TOPIC_0000001098830728__note152055145311"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001098830728__p14609172911014">When a query statement is querying a table where a redaction policy is enabled, the redacted data is invisible in the query only if the WHEN expression for the redaction policy is true. Generally, the WHEN clause is used to specify the users for which the redaction policy takes effect.</p>
|
|
<p id="EN-US_TOPIC_0000001098830728__p52886545456">The WHEN clause must comply with the following rules:</p>
|
|
<ol id="EN-US_TOPIC_0000001098830728__ol1681469167"><li id="EN-US_TOPIC_0000001098830728__li15681465161">The expression can be a combination of multiple subexpressions connected by AND and/or OR.</li><li id="EN-US_TOPIC_0000001098830728__li156916619161">Each subexpression supports only the =, <>, !=, >=, >, <=, and < operators. The left and right operand values can only be constant values or one of the following system constant values: <strong id="EN-US_TOPIC_0000001098830728__b229819253556">SESSION_USER</strong>, <strong id="EN-US_TOPIC_0000001098830728__b3296278559">CURRENT_USER</strong>, <strong id="EN-US_TOPIC_0000001098830728__b6314133045513">USER</strong>, <strong id="EN-US_TOPIC_0000001098830728__b1348413815517">CURRENT_ROLE</strong>, and <strong id="EN-US_TOPIC_0000001098830728__b16260541185513">CURRENT_SCHEMA</strong> system constants or the <strong id="EN-US_TOPIC_0000001098830728__b2012704485514">SYS_CONTEXT</strong> system function.</li><li id="EN-US_TOPIC_0000001098830728__li46917631620">Each subexpression can be an IN or NOT IN expression. The value for the left operand can be any of the system constant values listed in rule 2, and each element in the array of the right operand must be a constant value.</li><li id="EN-US_TOPIC_0000001098830728__li26912631618">If you want a redaction policy to be valid in all conditions, that is, you want it to take effect on all users (including the table owner), you are advised to use the (1=1) expression to create this policy.</li><li id="EN-US_TOPIC_0000001098830728__li176915611167">If the WHEN clause is not specified, the redaction policy is disabled by default. You need to manually specify a WHEN expression for the policy to take effect.</li></ol>
|
|
</div></div>
|
|
</li><li id="EN-US_TOPIC_0000001098830728__li109730225161"><strong id="EN-US_TOPIC_0000001098830728__b52262235588">column_name</strong><p id="EN-US_TOPIC_0000001098830728__p518122711582">Specifies the name of the table column to which the redaction policy is applied.</p>
|
|
</li><li id="EN-US_TOPIC_0000001098830728__li234522701614"><strong id="EN-US_TOPIC_0000001098830728__b20556191241">function_name</strong><p id="EN-US_TOPIC_0000001098830728__p212414138413">Specifies the redaction function applied to the specified table column.</p>
|
|
</li><li id="EN-US_TOPIC_0000001098830728__li20539133401616"><strong id="EN-US_TOPIC_0000001098830728__b8860175647">arguments</strong><p id="EN-US_TOPIC_0000001098830728__p54735341082">Specifies the list of arguments of the redaction function.</p>
|
|
<div class="note" id="EN-US_TOPIC_0000001098830728__note1511614581467"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001098830728__p1885550123017">The system provides three built-in redaction functions: <strong id="EN-US_TOPIC_0000001098830728__b179844131914">MASK_NONE</strong>, <strong id="EN-US_TOPIC_0000001098830728__b1654551518910">MASK_FULL</strong>, and <strong id="EN-US_TOPIC_0000001098830728__b15309171710912">MASK_PARTIAL</strong>. For details about the function specifications, see <a href="dws_06_0064.html">Data Redaction Functions</a>. You can also define your own redaction functions, which must comply with the following rules:</p>
|
|
<ol id="EN-US_TOPIC_0000001098830728__ol19615123919161"><li id="EN-US_TOPIC_0000001098830728__li146151239131618">In addition to the redaction format, only one column can be specified in the argument list for data redaction.</li><li id="EN-US_TOPIC_0000001098830728__li136161239181613">The return type must be the same as the data type of the redacted column.</li><li id="EN-US_TOPIC_0000001098830728__li1961643931615">The functions can be pushed down.</li><li id="EN-US_TOPIC_0000001098830728__li261618399165">The functions only implement the formatting for specific data types and do not involve complex association operations with other table objects.</li></ol>
|
|
<p id="EN-US_TOPIC_0000001098830728__p18116195816611">Built-in redaction functions can cover common redaction scenarios of sensitive information. Therefore, you are advised to use built-in redaction functions to create redaction policies.</p>
|
|
</div></div>
|
|
</li></ul>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001098830728__section1879372020138"><h4 class="sectiontitle">Examples</h4><p id="EN-US_TOPIC_0000001098830728__p2951115933013">Create a table object <strong id="EN-US_TOPIC_0000001098830728__b8888915105414">emp</strong> as user <strong id="EN-US_TOPIC_0000001098830728__b48931015195413">alice</strong>, and insert data into the table.</p>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001098830728__screen1974112714348"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
|
|
<span class="normal">2</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">CREATE</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="n">emp</span><span class="p">(</span><span class="n">id</span><span class="w"> </span><span class="nb">int</span><span class="p">,</span><span class="w"> </span><span class="n">name</span><span class="w"> </span><span class="nb">varchar</span><span class="p">(</span><span class="mi">20</span><span class="p">),</span><span class="w"> </span><span class="n">salary</span><span class="w"> </span><span class="nb">NUMERIC</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span><span class="mi">2</span><span class="p">));</span><span class="w"></span>
|
|
<span class="k">INSERT</span><span class="w"> </span><span class="k">INTO</span><span class="w"> </span><span class="n">emp</span><span class="w"> </span><span class="k">VALUES</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s1">'July'</span><span class="p">,</span><span class="w"> </span><span class="mi">1230</span><span class="p">.</span><span class="mi">10</span><span class="p">),</span><span class="w"> </span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="s1">'David'</span><span class="p">,</span><span class="w"> </span><span class="mi">999</span><span class="p">.</span><span class="mi">99</span><span class="p">);</span><span class="w"></span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
<p id="EN-US_TOPIC_0000001098830728__p59506593305">Create a redaction policy <strong id="EN-US_TOPIC_0000001098830728__b1931762005415">mask_emp</strong> for the <strong id="EN-US_TOPIC_0000001098830728__b1231832095414">emp</strong> table as user <strong id="EN-US_TOPIC_0000001098830728__b1231812203548">alice</strong> to make the <strong id="EN-US_TOPIC_0000001098830728__b33180208545">salary</strong> column invisible to user <strong id="EN-US_TOPIC_0000001098830728__b1431819202545">matu</strong>.</p>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001098830728__screen133645594346"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">CREATE</span><span class="w"> </span><span class="n">REDACTION</span><span class="w"> </span><span class="n">POLICY</span><span class="w"> </span><span class="n">mask_emp</span><span class="w"> </span><span class="k">ON</span><span class="w"> </span><span class="n">emp</span><span class="w"> </span><span class="k">WHEN</span><span class="p">(</span><span class="k">current_user</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s1">'matu'</span><span class="p">)</span><span class="w"> </span><span class="k">ADD</span><span class="w"> </span><span class="k">COLUMN</span><span class="w"> </span><span class="n">salary</span><span class="w"> </span><span class="k">WITH</span><span class="w"> </span><span class="n">mask_full</span><span class="p">(</span><span class="n">salary</span><span class="p">);</span><span class="w"></span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
<p id="EN-US_TOPIC_0000001098830728__p7950759133014">Grant the <strong id="EN-US_TOPIC_0000001098830728__b87791123175410">SELECT</strong> permission on the <strong id="EN-US_TOPIC_0000001098830728__b107791923135416">emp</strong> table to user <strong id="EN-US_TOPIC_0000001098830728__b1177992318547">matu</strong> as user <strong id="EN-US_TOPIC_0000001098830728__b878002385415">alice</strong>.</p>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001098830728__screen693627143520"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">GRANT</span><span class="w"> </span><span class="k">SELECT</span><span class="w"> </span><span class="k">ON</span><span class="w"> </span><span class="n">emp</span><span class="w"> </span><span class="k">TO</span><span class="w"> </span><span class="n">matu</span><span class="p">;</span><span class="w"></span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
<p id="EN-US_TOPIC_0000001098830728__p179501259103016">Switch to user <strong id="EN-US_TOPIC_0000001098830728__b16882172645416">matu</strong>.</p>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001098830728__screen616983817357"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">SET</span><span class="w"> </span><span class="k">ROLE</span><span class="w"> </span><span class="n">matu</span><span class="w"> </span><span class="n">PASSWORD</span><span class="w"> </span><span class="s1">'{password}'</span><span class="p">;</span><span class="w"></span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
<p id="EN-US_TOPIC_0000001098830728__p99506599304">Query the <strong id="EN-US_TOPIC_0000001098830728__b1282622913542">emp</strong> table. Data in the <strong id="EN-US_TOPIC_0000001098830728__b882611299547">salary</strong> column has been redacted.</p>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001098830728__screen5137846163518"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">emp</span><span class="p">;</span><span class="w"></span>
|
|
</pre></div></td></tr></table></div>
|
|
|
|
</div>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001098830728__section1426016489355"><h4 class="sectiontitle">Helpful Links</h4><p id="EN-US_TOPIC_0000001098830728__p9325125517354"><a href="dws_06_0132.html">ALTER REDACTION POLICY</a>, <a href="dws_06_0199.html">DROP REDACTION POLICY</a></p>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_06_0118.html">DDL Syntax</a></div>
|
|
</div>
|
|
</div>
|
|
|