-
Notifications
You must be signed in to change notification settings - Fork 25.9k
Tighten API key behaviour with DLS and incompatible license #78378
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
Merged
ywangd
merged 13 commits into
elastic:master
from
ywangd:error-on-dls-and-incompatible-license
Oct 12, 2021
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
72d0c54
Tighten API key behaviour with DLS and incompatible license
ywangd b731df0
Return error in more places where DLS/FLS is checked.
ywangd 72742cb
Merge remote-tracking branch 'origin/master' into error-on-dls-and-in…
ywangd d846876
checkstyle
ywangd c4d741c
Revert "checkstyle"
ywangd 9c0a69d
Revert "Return error in more places where DLS/FLS is checked."
ywangd b36fdfe
Add new intercetpor instead of relying on the existing one.
ywangd 36259f8
add test for get blockage
ywangd d21655a
Merge branch 'master' into error-on-dls-and-incompatible-license
elasticmachine f81fbf7
Merge remote-tracking branch 'origin/master' into error-on-dls-and-in…
ywangd 2943786
make sure interceptor only runs if dls/fls is enabled
ywangd 3482dbc
Merge remote-tracking branch 'origin/master' into error-on-dls-and-in…
ywangd 19c1a95
address feedback
ywangd 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
66 changes: 66 additions & 0 deletions
66
...ticsearch/xpack/security/authz/interceptor/DlsFlsLicenseComplianceRequestInterceptor.java
This file contains hidden or 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,66 @@ | ||
| /* | ||
| * 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.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import org.elasticsearch.ElasticsearchSecurityException; | ||
| import org.elasticsearch.action.ActionListener; | ||
| import org.elasticsearch.action.IndicesRequest; | ||
| import org.elasticsearch.common.util.concurrent.ThreadContext; | ||
| import org.elasticsearch.license.LicenseUtils; | ||
| import org.elasticsearch.license.XPackLicenseState; | ||
| import org.elasticsearch.transport.TransportActionProxy; | ||
| import org.elasticsearch.xpack.core.security.authz.AuthorizationEngine; | ||
| import org.elasticsearch.xpack.core.security.authz.AuthorizationEngine.AuthorizationInfo; | ||
| import org.elasticsearch.xpack.core.security.authz.accesscontrol.IndicesAccessControl; | ||
| import org.elasticsearch.xpack.core.security.authz.permission.Role; | ||
| import org.elasticsearch.xpack.security.authz.RBACEngine; | ||
|
|
||
| import static org.elasticsearch.xpack.core.security.authz.AuthorizationServiceField.AUTHORIZATION_INFO_KEY; | ||
| import static org.elasticsearch.xpack.core.security.authz.AuthorizationServiceField.INDICES_PERMISSIONS_KEY; | ||
|
|
||
| public class DlsFlsLicenseComplianceRequestInterceptor implements RequestInterceptor { | ||
| private static final Logger logger = LogManager.getLogger(DlsFlsLicenseComplianceRequestInterceptor.class); | ||
|
|
||
| private final ThreadContext threadContext; | ||
| private final XPackLicenseState licenseState; | ||
|
|
||
| public DlsFlsLicenseComplianceRequestInterceptor(ThreadContext threadContext, XPackLicenseState licenseState) { | ||
| this.threadContext = threadContext; | ||
| this.licenseState = licenseState; | ||
| } | ||
|
|
||
| @Override | ||
| public void intercept( | ||
| AuthorizationEngine.RequestInfo requestInfo, | ||
| AuthorizationEngine authorizationEngine, | ||
| AuthorizationInfo authorizationInfo, | ||
| ActionListener<Void> listener) { | ||
|
|
||
| if (requestInfo.getRequest() instanceof IndicesRequest && false == TransportActionProxy.isProxyAction(requestInfo.getAction())) { | ||
| if (false == licenseState.isAllowed(XPackLicenseState.Feature.SECURITY_DLS_FLS)) { | ||
| final Role role = RBACEngine.maybeGetRBACEngineRole(threadContext.getTransient(AUTHORIZATION_INFO_KEY)); | ||
| if (role == null || role.hasFieldOrDocumentLevelSecurity()) { | ||
| logger.trace("Role has DLS or FLS and license is incompatible. " + | ||
| "Checking for whether the request touches any indices that have DLS or FLS configured"); | ||
| final IndicesAccessControl indicesAccessControl = threadContext.getTransient(INDICES_PERMISSIONS_KEY); | ||
| if (indicesAccessControl != null && indicesAccessControl.hasFieldOrDocumentLevelSecurity()) { | ||
| final ElasticsearchSecurityException licenseException = | ||
| LicenseUtils.newComplianceException("field and document level security"); | ||
| licenseException.addMetadata( | ||
| "es.indices_with_dls_or_fls", indicesAccessControl.getIndicesWithFieldOrDocumentLevelSecurity()); | ||
| listener.onFailure(licenseException); | ||
| return; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| listener.onResponse(null); | ||
| } | ||
| } |
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.
If the PR gets merged, this new method here can be used in
IndicesPermission#authorizeto avoid the loop for computing DLS and FLS controls when the Roles does not have it.