- 
                Notifications
    You must be signed in to change notification settings 
- Fork 25.6k
Prevent access for users with DLS/FLS to the failure store #124634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
ba0d56f
              dbe80a0
              4d8ea21
              8843679
              8e20b39
              a2e1b9e
              80e904a
              58110d4
              50c937b
              a9efba4
              f0eb840
              feee7da
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|  | ||
| package org.elasticsearch.xpack.security.authz.interceptor; | ||
|  | ||
| import org.elasticsearch.ElasticsearchSecurityException; | ||
| import org.elasticsearch.action.ActionListener; | ||
| import org.elasticsearch.action.IndicesRequest; | ||
| import org.elasticsearch.action.support.IndexComponentSelector; | ||
| import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; | ||
| import org.elasticsearch.license.XPackLicenseState; | ||
| import org.elasticsearch.rest.RestStatus; | ||
| import org.elasticsearch.threadpool.ThreadPool; | ||
| import org.elasticsearch.xpack.core.security.authz.accesscontrol.IndicesAccessControl; | ||
|  | ||
| import java.util.Map; | ||
|  | ||
| public class FailureStoreRequestInterceptor extends FieldAndDocumentLevelSecurityRequestInterceptor { | ||
|  | ||
| public FailureStoreRequestInterceptor(ThreadPool threadPool, XPackLicenseState licenseState) { | ||
| super(threadPool.getThreadContext(), licenseState); | ||
| } | ||
|  | ||
| @Override | ||
| void disableFeatures( | ||
| IndicesRequest indicesRequest, | ||
| Map<String, IndicesAccessControl.IndexAccessControl> indicesAccessControlByIndex, | ||
| ActionListener<Void> listener | ||
| ) { | ||
| for (var indexAccessControl : indicesAccessControlByIndex.entrySet()) { | ||
| if (hasFailuresSelectorSuffix(indexAccessControl.getKey()) && hasDlsFlsPermissions(indexAccessControl.getValue())) { | ||
| listener.onFailure( | ||
| new ElasticsearchSecurityException( | ||
| "Failure store access is not allowed for users who have " | ||
| + "field or document level security enabled on one of the indices", | ||
| RestStatus.BAD_REQUEST | ||
| ) | ||
| ); | ||
| return; | ||
| } | ||
| } | ||
| listener.onResponse(null); | ||
| } | ||
|  | ||
| @Override | ||
| boolean supports(IndicesRequest request) { | ||
| if (request.indicesOptions().allowSelectors()) { | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure we want  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! This started with intention to prevent access with  | ||
| for (String index : request.indices()) { | ||
| if (hasFailuresSelectorSuffix(index)) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|  | ||
| private boolean hasFailuresSelectorSuffix(String name) { | ||
| return IndexNameExpressionResolver.hasSelectorSuffix(name) | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can use  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Fine to include the bigger check with splitting as an assertion since it does additional validation, but  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. Will make the change. | ||
| && IndexComponentSelector.getByKey( | ||
| IndexNameExpressionResolver.splitSelectorExpression(name).v2() | ||
| ) == IndexComponentSelector.FAILURES; | ||
| } | ||
|  | ||
| private boolean hasDlsFlsPermissions(IndicesAccessControl.IndexAccessControl indexAccessControl) { | ||
| return indexAccessControl.getDocumentPermissions().hasDocumentLevelPermissions() | ||
| || indexAccessControl.getFieldPermissions().hasFieldLevelSecurity(); | ||
| } | ||
|  | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've hit the ready button too soon. I still want to test cover the case when users have direct access to
.fs-*indices and accessing without::failuresselector.