I have a following structure in the elasticsearch index "answers"
{"can_view": ["F1", "F2", "F3"],"firstname": "John","lastname": "Black"}
{"can_view": ["F1", "F2"],"firstname": "Jack","lastname": "Grey"}
{"can_view": ["F2", "F3"],"firstname": "Adam","lastname": "Brown"}
I have setup XPack Security for elasticsearch. I have three users in the system: F1
, F2
, F3
.
I've added a role for securing documents with this request.
POST /_xpack/security/role/alias_read
{
"indices" : [
{
"names": [ "answers" ],
"privileges": [ "read" ],
"query": {
"template": {
"source": {
"match": {
"can_view": "{{_user.username}}"
}
}
}
}
}
]
}
I've assigned this role alias_read
to F1, F2 and F3 users.
Now if I'm logged in as F1
user, I am able to see only those documents.
{"can_view": ["F1", "F2", "F3"],"firstname": "John","lastname": "Black"}
{"can_view": ["F1", "F2"],"firstname": "Jack","lastname": "Grey"}
If I'm logged in as F2 user, I am able to see only those documents
{"can_view": ["F1", "F2"],"firstname": "Jack","lastname": "Grey"}
{"can_view": ["F2", "F3"],"name": "Adam","value": "Brown"}
That works just perfect and correct.
Now the question is if there is a way to do the similar protection but for concrete field values (not for entire documents and not for entire fields).
For example.
I have a following structure in the elasticsearch index "answers"
{"firstname": {"can_view": ["F1", "F2", "F3"], "value": "John"} ,"lastname": {"can_view": ["F1"], "value":"Black"} }
{"firstname": {"can_view": ["F3"], "value": "Jack"} ,"lastname": {"can_view": ["F2"], "value":"Grey"} }
{"firstname": {"can_view": ["F3", "F1"], "value": "Adam"} ,"lastname": {"can_view": ["F2", "F3"], "value":"Brown"} }
What I'm trying to get is, if I'm logged in as a user F1
, I should be able to see only those results:
{"firstname": {"can_view": ["F1", "F2", "F3"], "value": "John"} ,"lastname": {"can_view": ["F1"], "value":"Black"} }
{"firstname": {"can_view": ["F3", "F1"], "value": "Adam"}}
If I'm logged in as a user F2
, I should be able to see only those results:
{"firstname": {"can_view": ["F1", "F2", "F3"], "value": "John"}}
{"lastname": {"can_view": ["F2"], "value":"Grey"} }
{"lastname": {"can_view": ["F2", "F3"], "value":"Brown"} }
So I would like to restrict concrete values for concrete users. Is there a way to do it in elasticsearch using xpack or maybe some other security package? Using roles or whatever?
Versions that I use are:
elasticsearch 6.5.1
kibana 6.5.1
X-Pack