forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tighten API key behaviour with DLS and incompatible license (elastic#…
…78378) (elastic#79021) * Tighten API key behaviour with DLS and incompatible license (elastic#78378) When the cluster license is incompatible with DLS and FLS, instead of failing open, API keys now fail closed by throwing an error if any of the target indices has DLS/FLS protection. * Fix for 7.x quirks * more quirks
- Loading branch information
Showing
8 changed files
with
201 additions
and
6 deletions.
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
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
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
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
66 changes: 66 additions & 0 deletions
66
...ticsearch/xpack/security/authz/interceptor/DlsFlsLicenseComplianceRequestInterceptor.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,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); | ||
} | ||
} |