-
Notifications
You must be signed in to change notification settings - Fork 25.1k
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
Prevent access for users with DLS/FLS to the failure store #124634
Open
slobodanadamovic
wants to merge
12
commits into
elastic:main
Choose a base branch
from
slobodanadamovic:sa-failure-store-dls-fls-interceptor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+191
−16
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ba0d56f
Prevent access for users with DLS/FLS to the failure store
slobodanadamovic dbe80a0
remove debug logs
slobodanadamovic 4d8ea21
refactor away from using streams
slobodanadamovic 8843679
remove todo
slobodanadamovic 8e20b39
Merge branch 'main' of github.com:elastic/elasticsearch into sa-failu…
slobodanadamovic a2e1b9e
Merge branch 'main' into sa-failure-store-dls-fls-interceptor
slobodanadamovic 80e904a
adjust IT tests
slobodanadamovic 58110d4
also prevent direct access to backing failure indices with FLS/DLS
slobodanadamovic 50c937b
Merge branch 'main' of github.com:elastic/elasticsearch into sa-failu…
slobodanadamovic a9efba4
direct access to backing data indices should work with FLS
slobodanadamovic f0eb840
use getIndicesLookup instead of index metadata
slobodanadamovic feee7da
Merge branch 'main' into sa-failure-store-dls-fls-interceptor
slobodanadamovic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
...va/org/elasticsearch/xpack/security/authz/interceptor/FailureStoreRequestInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* 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.IndexAbstraction; | ||
import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; | ||
import org.elasticsearch.cluster.project.ProjectResolver; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
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 { | ||
|
||
private final ClusterService clusterService; | ||
private final ProjectResolver projectResolver; | ||
|
||
public FailureStoreRequestInterceptor( | ||
ClusterService clusterService, | ||
ProjectResolver projectResolver, | ||
ThreadPool threadPool, | ||
XPackLicenseState licenseState | ||
) { | ||
super(threadPool.getThreadContext(), licenseState); | ||
this.clusterService = clusterService; | ||
this.projectResolver = projectResolver; | ||
} | ||
|
||
@Override | ||
void disableFeatures( | ||
IndicesRequest indicesRequest, | ||
Map<String, IndicesAccessControl.IndexAccessControl> indicesAccessControlByIndex, | ||
ActionListener<Void> listener | ||
) { | ||
for (var indexAccessControl : indicesAccessControlByIndex.entrySet()) { | ||
if ((hasFailuresSelectorSuffix(indexAccessControl.getKey()) || isBackingFailureStoreIndex(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()) { | ||
for (String index : request.indices()) { | ||
if (hasFailuresSelectorSuffix(index) || isBackingFailureStoreIndex(index)) { | ||
return true; | ||
} | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private boolean hasFailuresSelectorSuffix(String name) { | ||
return IndexNameExpressionResolver.hasSelectorSuffix(name) | ||
&& IndexComponentSelector.getByKey( | ||
IndexNameExpressionResolver.splitSelectorExpression(name).v2() | ||
) == IndexComponentSelector.FAILURES; | ||
} | ||
|
||
private boolean hasDlsFlsPermissions(IndicesAccessControl.IndexAccessControl indexAccessControl) { | ||
return indexAccessControl.getDocumentPermissions().hasDocumentLevelPermissions() | ||
|| indexAccessControl.getFieldPermissions().hasFieldLevelSecurity(); | ||
} | ||
|
||
private boolean isBackingFailureStoreIndex(String index) { | ||
final IndexAbstraction indexAbstraction = clusterService.state() | ||
.metadata() | ||
.getProject(projectResolver.getProjectId()) | ||
.getIndicesLookup() | ||
.get(index); | ||
if (indexAbstraction == null) { | ||
return false; | ||
} | ||
return indexAbstraction.isFailureIndexOfDataStream(); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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::failures
selector.