# Creation of one role, how to set pattern-based anonymization to all fields in one rule?

**URL:** <https://forum.opensearch.org/t/creation-of-one-role-how-to-set-pattern-based-anonymization-to-all-fields-in-one-rule/16936>\
**Category:** Security\
**Created:** [December 4, 2023, 1:42pm UTC](https://forum.opensearch.org/t/creation-of-one-role-how-to-set-pattern-based-anonymization-to-all-fields-in-one-rule/16936 "2023-12-04T13:42:46Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![ing\_coy](https://avatars.discourse-cdn.com/v4/letter/i/b487fb/32.png) [@ing\_coy](https://forum.opensearch.org/u/ing_coy)\
**Post date:** [December 4, 2023, 1:42pm UTC](https://forum.opensearch.org/t/creation-of-one-role-how-to-set-pattern-based-anonymization-to-all-fields-in-one-rule/16936/1 "2023-12-04T13:42:47Z")

</div>

**Versions** (relevant - OpenSearch/Dashboard/Server OS/Browser):  
OpenSearch 2.11.0 - Dashboard 2.11.0 - Windows64 - Mozilla/Chrome

**Describe the issue** :  
When you create one role you can define an anonymization rule. Documentation says you can use one or more regular expressions and replacement strings to mask a field. The syntax is `<field>::/<regular-expression>/::<replacement-string>`.

The `<field>` part can contain wildcard \*, but if it is one wildcard only it does not work.

For example: `*e*:/<regular-expression>/::*`  
this works as expected, GET request obtains all the hits, string replacement is correctly applied in all the fields that contains an “e” in the fieldname

if I try to extend the rule to all fields, I assume I must use this: `*::/<regular-expression>/::*`  
this rule is accepted when the role is created but it does not work, **GET request obtains 0 hits**

**Configuration** :

**Relevant Logs or Screenshots** :

---

<div class="post-metadata">

**Author:** ![Eugene7](https://avatars.discourse-cdn.com/v4/letter/e/bbce88/32.png) [@Eugene7](https://forum.opensearch.org/u/Eugene7)\
**Post date:** [December 5, 2023, 6:57pm UTC](https://forum.opensearch.org/t/creation-of-one-role-how-to-set-pattern-based-anonymization-to-all-fields-in-one-rule/16936/3 "2023-12-05T18:57:40Z")

</div>

Hi @ing_coy

I have just tried the following anonymization rule, It works in my lab.  
`*::/.*/::*`

Could you share your `roles.yml` file ?

---

<div class="post-metadata">

**Author:** ![ing\_coy](https://avatars.discourse-cdn.com/v4/letter/i/b487fb/32.png) [@ing\_coy](https://forum.opensearch.org/u/ing_coy)\
**Post date:** [December 6, 2023, 10:01am UTC](https://forum.opensearch.org/t/creation-of-one-role-how-to-set-pattern-based-anonymization-to-all-fields-in-one-rule/16936/4 "2023-12-06T10:01:27Z")

</div>

Thank you for the answer.  
I did not change the roles.yml file.  
I have created the role using the Dashboard.  
I tried your anonymization rule  
`*::/.*/::*`

and I obtain 0 hits

 ![image](https://us1.discourse-cdn.com/flex019/uploads/mauve_hedgehog/original/2X/b/be5a21300233f0ce43b4282d173470800f42732e.png)

---

<div class="post-metadata">

**Author:** ![ing\_coy](https://avatars.discourse-cdn.com/v4/letter/i/b487fb/32.png) [@ing\_coy](https://forum.opensearch.org/u/ing_coy)\
**Post date:** [December 6, 2023, 10:06am UTC](https://forum.opensearch.org/t/creation-of-one-role-how-to-set-pattern-based-anonymization-to-all-fields-in-one-rule/16936/5 "2023-12-06T10:06:02Z")

</div>

If I change the anonymization rule, and I specify the field name  
I obtain multiple hits and the field is correctly anonymized

 ![image](https://us1.discourse-cdn.com/flex019/uploads/mauve_hedgehog/original/2X/7/702be33c84ec8e4f34563fe91c14a08e3691806d.png)

---

<div class="post-metadata">

**Author:** ![Eugene7](https://avatars.discourse-cdn.com/v4/letter/e/bbce88/32.png) [@Eugene7](https://forum.opensearch.org/u/Eugene7)\
**Post date:** [December 6, 2023, 11:33am UTC](https://forum.opensearch.org/t/creation-of-one-role-how-to-set-pattern-based-anonymization-to-all-fields-in-one-rule/16936/6 "2023-12-06T11:33:41Z")

</div>

Could you share your Document level security expression? What version of operating system do you use?

---

<div class="post-metadata">

**Author:** ![ing\_coy](https://avatars.discourse-cdn.com/v4/letter/i/b487fb/32.png) [@ing\_coy](https://forum.opensearch.org/u/ing_coy)\
**Post date:** [December 6, 2023, 1:05pm UTC](https://forum.opensearch.org/t/creation-of-one-role-how-to-set-pattern-based-anonymization-to-all-fields-in-one-rule/16936/7 "2023-12-06T13:05:17Z")

</div>

I think you have centered the point, the issue seems to occur only when you configure both masked\_fields and DLS expressions at the same time.  
I have removed the DLS expression and now the anonymization works perfectly. Is it a limitation?

My DLS expression is  
 ![image](https://us1.discourse-cdn.com/flex019/uploads/mauve_hedgehog/original/2X/6/60a773c67925931cb12cc49fb276c3626c6b2b0e.png)

Windows 10 Enterprise  
Version 22H2

---

<div class="post-metadata">

**Author:** ![Eugene7](https://avatars.discourse-cdn.com/v4/letter/e/bbce88/32.png) [@Eugene7](https://forum.opensearch.org/u/Eugene7)\
**Post date:** [December 7, 2023, 4:11pm UTC](https://forum.opensearch.org/t/creation-of-one-role-how-to-set-pattern-based-anonymization-to-all-fields-in-one-rule/16936/8 "2023-12-07T16:11:23Z")

</div>

Hi @ing_coy

According to tests in my lab, DLS query can’t read a value that was anonymized. In the order execution, field anonymization runs first, DLS query runs after field anonymization.

---

<div class="post-metadata">

**Author:** ![ing\_coy](https://avatars.discourse-cdn.com/v4/letter/i/b487fb/32.png) [@ing\_coy](https://forum.opensearch.org/u/ing_coy)\
**Post date:** [December 11, 2023, 2:18pm UTC](https://forum.opensearch.org/t/creation-of-one-role-how-to-set-pattern-based-anonymization-to-all-fields-in-one-rule/16936/9 "2023-12-11T14:18:10Z")

</div>

Hi @Eugene7,  
what you write is correct, I would add that even when the value is left unchanged by the anonymization, DLS can’t read it and the response gives 0 hits.

In your opinion, would it make sense to ask for a fix?

Regards,  
Max
