# Problem with document level security

**URL:** https://discuss.elastic.co/t/problem-with-document-level-security/41944
**Category:** Elasticsearch
**Tags:** elastic-stack-security
**Created:** [February 16, 2016, 9:47pm UTC](https://discuss.elastic.co/t/problem-with-document-level-security/41944 "2016-02-16T21:47:35Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![AndreyL](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andreyl/32/19365_2.png) [@AndreyL](https://discuss.elastic.co/u/AndreyL)
#### Post date: [February 16, 2016, 9:47pm UTC](https://discuss.elastic.co/t/problem-with-document-level-security/41944/1 "2016-02-16T21:47:35Z")

</div>

I have the following two documents in Elastic:

```
 [ {
      "_index" : "hr",
      "_type" : "blog",
      "_id" : "123",
      "_score" : 1.0,
      "_source" : {
        "title" : "blah blah Doe"
      }
    }, {
      "_index" : "hr",
      "_type" : "person",
      "_id" : "1",
      "_score" : 1.0,
      "_source" : {
        "name" : "Jane Doe",
        "title" : "Software Engineer"
      }
    } ]

```

==========================================  
I have two roles: `hr_user` and `hr_blog_reader`, and two users mapped to them. Role `hr_user` should have full access to hr index; `hr_blog_reader` should only have access to documents with `_type=blog`:

```
hr_blog_reader:
  indices:
    'hr':
      privileges: read
      query: '{"match":{"_type":"blog"}}'

hr_user:
  indices:
    'hr':
      privileges: all

```

When I run a query as `hr_user`, I get both documents back, as expected. When I run a query as `hr_blog_reader`, I get the following error:

```
{
  "error" : {
    "root_cause" : [ {
      "type" : "security_exception",
      "reason" : "action [indices:data/read/search] is unauthorized for user [hr_blog_reader]"
    } ],
    "type" : "security_exception",
    "reason" : "action [indices:data/read/search] is unauthorized for user [hr_blog_reader]"
  },
  "status" : 403
}

```

I'm running the queries using curl:

```
curl http://localhost:9200/_search?pretty -u hr_blog_reader

```

Any ideas what I'm doing wrong?

---

<div class="post-metadata">

### Author: ![jaymode](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jaymode/32/50103_2.png) [@jaymode](https://discuss.elastic.co/u/jaymode)
#### Post date: [February 16, 2016, 11:11pm UTC](https://discuss.elastic.co/t/problem-with-document-level-security/41944/2 "2016-02-16T23:11:27Z")

</div>

What version of Shield are you using? You may need to set `shield.dls_fls.enabled: true` in your elasticsearch.yml file. This was supposed to be enabled by default in 2.2, but there was a bug and it was not; we'll fix it in the next bug release version.

Also, in your logs you might have a message saying that role isn't valid and why.

---

<div class="post-metadata">

### Author: ![AndreyL](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andreyl/32/19365_2.png) [@AndreyL](https://discuss.elastic.co/u/AndreyL)
#### Post date: [February 17, 2016, 5:40pm UTC](https://discuss.elastic.co/t/problem-with-document-level-security/41944/4 "2016-02-17T17:40:46Z")

</div>

That worked, thank you!

---

<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: [July 6, 2017, 1:46pm UTC](https://discuss.elastic.co/t/problem-with-document-level-security/41944/5 "2017-07-06T13:46:45Z")

</div>


