Hi @stramzik
Short Answer: No Not Easy, if users are directly accessing Elasticsearch with Users and Role (perhaps if via Service / API gateway you could use a templated query or something but would need to think about that)
Take a look at this which is pretty much what you are trying to do 1 role gives all documents with 2 of 3 fields ... the Other Role limits the fields to the 3rd fields but limits documents ... but they get OR'd so all documents all fields (BTW I tested that)
I think you are going to need to divide your index by countries or something as suggested...
PUT discuss-test-fls/
{
"mappings": {
"properties": {
"Country": {
"type": "keyword"
},
"Data": {
"type": "keyword"
},
"sample": {
"type": "long"
}
}
}
}
GET discuss-test-fls/_search
POST discuss-test-fls/_doc
{"Country": "India", "sample":1 , "Data":"hi" }
POST discuss-test-fls/_doc
{"Country": "India", "sample": 2, "Data":"hello" }
POST discuss-test-fls/_doc
{"Country": "India", "sample": 3, "Data":"how" }
POST discuss-test-fls/_doc
{"Country": "Buthan", "sample": 4, "Data":"are" }
POST discuss-test-fls/_doc
{"Country": "Buthan", "sample": 5, "Data":"you" }
POST discuss-test-fls/_doc
{"Country": "Buthan", "sample": 6, "Data":"Kibana?" }
# Create Roles
PUT _security/role/discuss-base-fields
{
"indices": [
{
"names": [
"discuss-test-fls"
],
"privileges": [
"read"
],
"field_security": {
"grant": [
"Country",
"sample"
]
}
}
]
}
PUT _security/role/discuss-show-india
{
"indices": [
{
"names": [
"discuss-test-fls"
],
"privileges": [
"read"
],
"field_security": {
"grant": [
"Data"
]
},
"query" : {
"template" : {
"source" : {
"term" : { "Country" : "India" }
}
}
}
}
]
}
# Create User and assign Roles
PUT _security/user/testing
{
"password": "123456",
"roles": [
"discuss-show-india",
"discuss-base-fields"
],
"full_name": "",
"email": "",
"metadata": {},
"enabled": true
}
Then curl
you get both as explained in the docs... try with either role you get each part.... try it.
curl -u discuss-test-fls:123456 https://localhost:9200/discuss-test-fls/_search?pretty
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 6,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "discuss-test-fls",
"_id" : "ksj6aIcBaxQDBNhISPo3",
"_score" : 1.0,
"_source" : {
"Country" : "India",
"Data" : "hi",
"sample" : 1
}
},
{
"_index" : "discuss-test-fls",
"_id" : "k8j6aIcBaxQDBNhISPqT",
"_score" : 1.0,
"_source" : {
"Country" : "India",
"Data" : "hello",
"sample" : 2
}
},
{
"_index" : "discuss-test-fls",
"_id" : "lMj6aIcBaxQDBNhISPrp",
"_score" : 1.0,
"_source" : {
"Country" : "India",
"Data" : "how",
"sample" : 3
}
},
{
"_index" : "discuss-test-fls",
"_id" : "3Cf6aIcBohX2d_7rScBH",
"_score" : 1.0,
"_source" : {
"Country" : "Buthan",
"Data" : "are",
"sample" : 4
}
},
{
"_index" : "discuss-test-fls",
"_id" : "lcj6aIcBaxQDBNhISfqp",
"_score" : 1.0,
"_source" : {
"Country" : "Buthan",
"Data" : "you",
"sample" : 5
}
},
{
"_index" : "discuss-test-fls",
"_id" : "G776aIcBE-JHYtAUSqsF",
"_score" : 1.0,
"_source" : {
"Country" : "Buthan",
"Data" : "Kibana?",
"sample" : 6
}
}
]
}
}