When using the new FLX implementation for DLS/FLS security the multi-tenancy feature in Kibana seems to be broken.
After setting use_impl: flx in sg_authz_dlsfls.yml a logged in user in Kibana gets a HTTP 500 Internal Server Error when trying to access Kibana after login.
Here are the (anonymized) Elasticsearch log messages:
[2022-11-04T09:28:08,390][WARN ][r.suppressed ] [es-node1] path: /.kibana, params: {index=.kibana}
org.elasticsearch.transport.RemoteTransportException: [es-node2][1.2.3.4:9300][indices:admin/get]
Caused by: java.lang.IllegalStateException: Index [.kibana_109026154_USER] is not registered in com.floragunn.searchguard.enterprise.dlsfls.RoleBasedDocumentAuthorization$StatefulIndexQueries@2419ca2b
at com.floragunn.searchguard.enterprise.dlsfls.RoleBasedDocumentAuthorization.hasDlsRestrictions(RoleBasedDocumentAuthorization.java:84) ~[?:?]
at com.floragunn.searchguard.enterprise.dlsfls.DlsFlsValve.apply(DlsFlsValve.java:127) ~[?:?]
...
[2022-11-04T09:28:08,435][WARN ][r.suppressed ] [es-node1] path: /.kibana_7.17.7_001, params: {index=.kibana_7.17.7_001}
org.elasticsearch.transport.RemoteTransportException: [es-node2][1.2.3.4:9300][indices:admin/create]
Caused by: java.lang.IllegalStateException: Index [.kibana_109026154_USER_7.17.7_001] is not registered in com.floragunn.searchguard.enterprise.dlsfls.RoleBasedDocumentAuthorization$StatefulIndexQueries@2419ca2b
at com.floragunn.searchguard.enterprise.dlsfls.RoleBasedDocumentAuthorization.hasDlsRestrictions(RoleBasedDocumentAuthorization.java:84) ~[?:?]
at com.floragunn.searchguard.enterprise.dlsfls.DlsFlsValve.apply(DlsFlsValve.java:127) ~[?:?]
..
[2022-11-04T09:28:08,470][ERROR][c.f.s.e.d.DlsFlsValve ] [es-node1] Error while evaluating DLS/FLS privileges
java.lang.IllegalStateException: Index [.kibana_109026154_USER_7.17.7] is not registered in com.floragunn.searchguard.enterprise.dlsfls.RoleBasedDocumentAuthorization$StatefulIndexQueries@7b209981
at com.floragunn.searchguard.enterprise.dlsfls.RoleBasedDocumentAuthorization.hasDlsRestrictions(RoleBasedDocumentAuthorization.java:84) ~[dlic-search-guard-flx-dlsfls-1.0.0-es-7.17.7.jar:1.0.0-es-7.17.7]
..
[2022-11-04T09:28:08,489][ERROR][c.f.s.f.SearchGuardFilter] [es-node1] Exception while handling indices:data/write/bulk; org.elasticsearch.action.bulk.BulkRequest/unset
java.lang.IllegalStateException: Index [.kibana_109026154_USER_7.17.7] is not registered in com.floragunn.searchguard.enterprise.dlsfls.RoleBasedDocumentAuthorization$StatefulIndexQueries@7b209981
at com.floragunn.searchguard.enterprise.dlsfls.RoleBasedDocumentAuthorization.hasDlsRestrictions(RoleBasedDocumentAuthorization.java:84) ~[dlic-search-guard-flx-dlsfls-1.0.0-es-7.17.7.jar:1.0.0-es-7.17.7]
at com.floragunn.searchguard.enterprise.dlsfls.DlsFlsValve.apply(DlsFlsValve.java:127) ~[dlic-search-guard-flx-dlsfls-1.0.0-es-7.17.7.jar:1.0.0-es-7.17.7]
..
[2022-11-04T09:28:08,508][WARN ][r.suppressed ] [es-node1] path: /.kibana_7.17.7/_create/config%3A7.17.7, params: {require_alias=true, refresh=wait_for, index=.kibana_7.17.7, id=config:7.17.7, op_type=create}
java.lang.IllegalStateException: Index [.kibana_109026154_USER_7.17.7] is not registered in com.floragunn.searchguard.enterprise.dlsfls.RoleBasedDocumentAuthorization$StatefulIndexQueries@7b209981
at com.floragunn.searchguard.enterprise.dlsfls.RoleBasedDocumentAuthorization.hasDlsRestrictions(RoleBasedDocumentAuthorization.java:84) ~[dlic-search-guard-flx-dlsfls-1.0.0-es-7.17.7.jar:1.0.0-es-7.17.7]
at com.floragunn.searchguard.enterprise.dlsfls.DlsFlsValve.apply(DlsFlsValve.java:127) ~[dlic-search-guard-flx-dlsfls-1.0.0-es-7.17.7.jar:1.0.0-es-7.17.7]
...
If desired, I can provide the full Java stack trace.
To my understand it seems that Kibana is unable to create the hidden Kibana system indices.
It seems to do not matter if the assigned role for the user has a DLS or FLS restriction configured or not.
When reverting sg_authz_dlsfls.yml back to use_impl: legacy the user is able to access Kibana.
We excessively used DLS before upgrading to FLX without any problems.
This roles should restrict access to events containing agent.name: test.example.com but the user can access all events of this index, for example events containing agent.name: test2.example.com
@trauta Did you migrate your environment to FLX recently or this is a new deployment?
If migrated, is the migration of all nodes in the cluster completed?
The multitenancy feature is only broken if the logged in user is assigned to the SGS_KIBANA_USER_NO_DEFAULT_TENANT role or when the 'Globalā tenant is disabled via the searchguard.multitenancy.tenants.enable_global setting in the kibana.yml.
When leaving the āGlobalā tenant is active, a user can select the other tenants without problems.
BUT: Even then, the new FLX DLS implementation is somehow broken, the user can still see events that he is not supposed to access.
The following config still allows access to all events of the filebeat index.
I have one request: Would it be possible that you run the command ./sgctl.sh component-state and provide us the resulting output. You can also send me the output by private message.
Please keep in mind that the output of the command might be very long.
@trauta We have an experimental fix for this. Would you mind to try it whether it fixes the issues?
You can find it at https://maven.search-guard.com:443/search-guard-flx-snapshot/com/floragunn/search-guard-flx-elasticsearch-plugin/b-flx-dls-no-index-handling-SNAPSHOT/search-guard-flx-elasticsearch-plugin-b-flx-dls-no-index-handling-20221118.154911-2.zip
When the user logs in, there is no more āInternal server errorā message and no error messages in the ES logs.
However, after logging in, the menu for changing tenants is no longer displayed in Kibana.
When entering the āDiscoverā menu there is an error message saying āError loading Discover - Forbiddenā.
There are no error messages in the ES logs, but in the Kibana logs there is the following message:
{"type":"log","@timestamp":"2022-11-23T15:54:05+01:00","tags":["error","plugins","searchguard"],"pid":144903,"message":"Fail to create the index \".kibana_7.17. 7_001\" for tenant \"\", {\"error\":{\"root_cause\":[{\"type\":\"security_exception\",\"reason\":\"Insufficient permissions\"}],\"type\":\"security_exception\",\"reason\":\"Insufficient permissions\"},\"status\":403}"}
If you add sgtenant=TEST to the Kibana URL, Kibana switches to the TEST tenant and the tenant menu is also visible again.
It seems that there are problems with the default private tenant.
Could you also share your kibana.yml configuration? Especially, it would be interesting for us what tenant is displayed by default? Is it the private tenant?
Could you check whether now the DLS rules are effective?
adding searchguard.multitenancy.tenants.preferred: ["Private"] to the kibana.yml fixes the problem with the disappearing tenant menu.
Iām not quite sure if this is really required, I thought the Private tenant is the always default tenant.
Or was this behavior maybe changed with FLX?
This does not fix the non-working DLS filter, unfortunately
I have just noticed that you are using a match query for the DLS query. This will not search for exact strings, but tokenize the search string and perform a fuzzy full text search. In this case, you might want to use a term query to get exact matching.