# PKI pull full dn not just cn

**URL:** <https://discuss.elastic.co/t/pki-pull-full-dn-not-just-cn/282508>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-security\
**Created:** [August 25, 2021, 5:34pm UTC](https://discuss.elastic.co/t/pki-pull-full-dn-not-just-cn/282508 "2021-08-25T17:34:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sam3546](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sam3546/32/79281_2.png) [@sam3546](https://discuss.elastic.co/u/sam3546)\
**Post date:** [August 25, 2021, 5:34pm UTC](https://discuss.elastic.co/t/pki-pull-full-dn-not-just-cn/282508/1 "2021-08-25T17:34:19Z")

</div>

So i have a pki realm that passes auth to an ldap realm but the pki realm uses a usernam\_pattern attribute to pull the cn from the pki but i want the whole dn returning and passing to the ldap realm.

e.g  
PKI;

```auto
CN=VVVVVVVV,OU=WWWWWWWW,O=XXXXXXXX,L=YYYYYYYY,C=ZZZZZZZZ

```

LDAP user full DN;

```auto
CN=VVVVVVVV,OU=WWWWWWWW,O=XXXXXXXX,L=YYYYYYYY,C=ZZZZZZZZ

```

The pki realm uses a username\_pattern that supposedly defaults to `CN=(.*?)(?:,\|$)` and so just grabs the cn `VVVVVVVV` and passes it to ldap, which fails as its looking for the whole DN. I dont want to just search on the CN as there's a chance multiple users have the same CN but different O or OU.

Any help would be great.

---

<div class="post-metadata">

**Author:** ![Yang\_Wang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yang_wang/32/48857_2.png) [@Yang\_Wang](https://discuss.elastic.co/u/Yang_Wang)\
**Post date:** [August 26, 2021, 4:37am UTC](https://discuss.elastic.co/t/pki-pull-full-dn-not-just-cn/282508/2 "2021-08-26T04:37:55Z")

</div>

Did you try configure your own `username_pattern` setting? [Security settings in Elasticsearch | Elasticsearch Guide [7.14] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.14/security-settings.html#ref-pki-settings)

---

<div class="post-metadata">

**Author:** ![sam3546](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sam3546/32/79281_2.png) [@sam3546](https://discuss.elastic.co/u/sam3546)\
**Post date:** [August 26, 2021, 1:10pm UTC](https://discuss.elastic.co/t/pki-pull-full-dn-not-just-cn/282508/3 "2021-08-26T13:10:28Z")

</div>

Thanks @Yang_Wang, I wondered if there was a way to not use that setting but seems there is no alternative. For anyone wanting to achieve the same the below code works perfectly fine.

```auto
pki1.username_pattern: "(.*)"

```

Cheers

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 23, 2021, 1:11pm UTC](https://discuss.elastic.co/t/pki-pull-full-dn-not-just-cn/282508/4 "2021-09-23T13:11:25Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
