Remove combo security and license helper from license state (#55366) (#55417)

Security features in the license state currently do a dynamic check on
whether security is enabled. This is because the license level can
change the default security enabled state. This commit splits out the
check on security being enabled, so that the combo method of security
enabled plus license allowed is no longer necessary.
This commit is contained in:
Ryan Ernst 2020-04-17 13:07:02 -07:00 committed by GitHub
parent 49e30b15a2
commit 66071b2f6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 61 additions and 58 deletions

View File

@ -402,11 +402,11 @@ public class XPackLicenseState {
} }
public boolean isIpFilteringAllowed() { public boolean isIpFilteringAllowed() {
return isAllowedBySecurityAndLicense(OperationMode.GOLD, false); return isAllowedByLicense(OperationMode.GOLD, false);
} }
public boolean isAuditingAllowed() { public boolean isAuditingAllowed() {
return isAllowedBySecurityAndLicense(OperationMode.GOLD, false); return isAllowedByLicense(OperationMode.GOLD, false);
} }
public boolean isStatsAndHealthAllowed() { public boolean isStatsAndHealthAllowed() {
@ -427,33 +427,33 @@ public class XPackLicenseState {
* @return {@code true} to enable DLS and FLS. Otherwise {@code false}. * @return {@code true} to enable DLS and FLS. Otherwise {@code false}.
*/ */
public boolean isDocumentAndFieldLevelSecurityAllowed() { public boolean isDocumentAndFieldLevelSecurityAllowed() {
return isAllowedBySecurityAndLicense(OperationMode.PLATINUM, false); return isAllowedByLicense(OperationMode.PLATINUM, false);
} }
public boolean areAllRealmsAllowed() { public boolean areAllRealmsAllowed() {
return isAllowedBySecurityAndLicense(OperationMode.PLATINUM, false); return isAllowedByLicense(OperationMode.PLATINUM, false);
} }
public boolean areStandardRealmsAllowed() { public boolean areStandardRealmsAllowed() {
return isAllowedBySecurityAndLicense(OperationMode.GOLD, false); return isAllowedByLicense(OperationMode.GOLD, false);
} }
public boolean isCustomRoleProvidersAllowed() { public boolean isCustomRoleProvidersAllowed() {
return isAllowedBySecurityAndLicense(OperationMode.PLATINUM, true); return isAllowedByLicense(OperationMode.PLATINUM, true);
} }
/** /**
* Whether the Elasticsearch {@code TokenService} is allowed * Whether the Elasticsearch {@code TokenService} is allowed
*/ */
public boolean isTokenServiceAllowed() { public boolean isTokenServiceAllowed() {
return isAllowedBySecurityAndLicense(OperationMode.GOLD, false); return isAllowedByLicense(OperationMode.GOLD, false);
} }
/** /**
* Whether the Elasticsearch {@code ApiKeyService} is allowed * Whether the Elasticsearch {@code ApiKeyService} is allowed
*/ */
public boolean isApiKeyServiceAllowed() { public boolean isApiKeyServiceAllowed() {
return isAllowedBySecurityAndLicense(OperationMode.MISSING, false); return isAllowedByLicense(OperationMode.MISSING, false);
} }
/** /**
@ -461,7 +461,7 @@ public class XPackLicenseState {
* @see org.elasticsearch.xpack.core.security.authc.support.DelegatedAuthorizationSettings * @see org.elasticsearch.xpack.core.security.authc.support.DelegatedAuthorizationSettings
*/ */
public boolean isAuthorizationRealmAllowed() { public boolean isAuthorizationRealmAllowed() {
return isAllowedBySecurityAndLicense(OperationMode.PLATINUM, true); return isAllowedByLicense(OperationMode.PLATINUM, true);
} }
/** /**
@ -469,7 +469,7 @@ public class XPackLicenseState {
* @see org.elasticsearch.xpack.core.security.authc.support.DelegatedAuthorizationSettings * @see org.elasticsearch.xpack.core.security.authc.support.DelegatedAuthorizationSettings
*/ */
public boolean isAuthorizationEngineAllowed() { public boolean isAuthorizationEngineAllowed() {
return isAllowedBySecurityAndLicense(OperationMode.PLATINUM, true); return isAllowedByLicense(OperationMode.PLATINUM, true);
} }
public boolean isWatcherAllowed() { public boolean isWatcherAllowed() {
@ -683,32 +683,7 @@ public class XPackLicenseState {
} }
/** /**
* Test whether a feature is allowed by the status of license and security configuration. * Test whether a feature is allowed by the status of license.
* Note the difference to {@link #isAllowedByLicense(OperationMode, boolean)}
* is this method requires security to be enabled.
*
* @param minimumMode The minimum license to meet or exceed
* @param needActive Whether current license needs to be active.
*
* @return true if feature is allowed, otherwise false
*/
private boolean isAllowedBySecurityAndLicense(OperationMode minimumMode, boolean needActive) {
return checkAgainstStatus(status -> {
if (false == isSecurityEnabled(status.mode, isSecurityExplicitlyEnabled, isSecurityEnabled)) {
return false;
}
// Do not delegate to isAllowedByLicense as it also captures "status" which may be different from here
if (needActive && false == status.active) {
return false;
}
return isAllowedByOperationMode(status.mode, minimumMode);
});
}
/**
* Test whether a feature is allowed by the status of license. Note difference to
* {@link #isAllowedBySecurityAndLicense} is this method does <b>Not</b> require security
* to be enabled.
* *
* @param minimumMode The minimum license to meet or exceed * @param minimumMode The minimum license to meet or exceed
* @param needActive Whether current license needs to be active * @param needActive Whether current license needs to be active

View File

@ -61,7 +61,7 @@ public class SecurityIndexReaderWrapper implements CheckedFunction<DirectoryRead
@Override @Override
public DirectoryReader apply(final DirectoryReader reader) { public DirectoryReader apply(final DirectoryReader reader) {
if (licenseState.isDocumentAndFieldLevelSecurityAllowed() == false) { if (licenseState.isSecurityEnabled() == false || licenseState.isDocumentAndFieldLevelSecurityAllowed() == false) {
return reader; return reader;
} }

View File

@ -107,7 +107,7 @@ public class XPackLicenseStateTests extends ESTestCase {
assertThat(licenseState.isDocumentAndFieldLevelSecurityAllowed(), is(false)); assertThat(licenseState.isDocumentAndFieldLevelSecurityAllowed(), is(false));
assertThat(licenseState.isCustomRoleProvidersAllowed(), is(false)); assertThat(licenseState.isCustomRoleProvidersAllowed(), is(false));
assertThat(licenseState.isTokenServiceAllowed(), is(false)); assertThat(licenseState.isTokenServiceAllowed(), is(false));
assertThat(licenseState.isApiKeyServiceAllowed(), is(false)); assertThat(licenseState.isApiKeyServiceAllowed(), is(true));
assertThat(licenseState.isSecurityAvailable(), is(true)); assertThat(licenseState.isSecurityAvailable(), is(true));
assertThat(licenseState.isSecurityEnabled(), is(false)); assertThat(licenseState.isSecurityEnabled(), is(false));
@ -142,7 +142,7 @@ public class XPackLicenseStateTests extends ESTestCase {
assertThat(licenseState.isDocumentAndFieldLevelSecurityAllowed(), is(false)); assertThat(licenseState.isDocumentAndFieldLevelSecurityAllowed(), is(false));
assertThat(licenseState.isCustomRoleProvidersAllowed(), is(false)); assertThat(licenseState.isCustomRoleProvidersAllowed(), is(false));
assertThat(licenseState.isTokenServiceAllowed(), is(false)); assertThat(licenseState.isTokenServiceAllowed(), is(false));
assertThat(licenseState.isApiKeyServiceAllowed(), is(false)); assertThat(licenseState.isApiKeyServiceAllowed(), is(true));
} }
public void testSecurityEnabledBasicExpired() { public void testSecurityEnabledBasicExpired() {
@ -260,11 +260,6 @@ public class XPackLicenseStateTests extends ESTestCase {
private void assertSecurityNotAllowed(XPackLicenseState licenseState) { private void assertSecurityNotAllowed(XPackLicenseState licenseState) {
assertThat(licenseState.isSecurityEnabled(), is(false)); assertThat(licenseState.isSecurityEnabled(), is(false));
assertThat(licenseState.isIpFilteringAllowed(), is(false));
assertThat(licenseState.isAuditingAllowed(), is(false));
assertThat(licenseState.isStatsAndHealthAllowed(), is(true));
assertThat(licenseState.isDocumentAndFieldLevelSecurityAllowed(), is(false));
assertThat(licenseState.isCustomRoleProvidersAllowed(), is(false));
} }
public void testSecurityAckBasicToNotGoldOrStandard() { public void testSecurityAckBasicToNotGoldOrStandard() {

View File

@ -97,6 +97,7 @@ public class SecurityIndexReaderWrapperIntegrationTests extends AbstractBuilderT
QueryShardContext queryShardContext = spy(realQueryShardContext); QueryShardContext queryShardContext = spy(realQueryShardContext);
DocumentSubsetBitsetCache bitsetCache = new DocumentSubsetBitsetCache(Settings.EMPTY, Executors.newSingleThreadExecutor()); DocumentSubsetBitsetCache bitsetCache = new DocumentSubsetBitsetCache(Settings.EMPTY, Executors.newSingleThreadExecutor());
XPackLicenseState licenseState = mock(XPackLicenseState.class); XPackLicenseState licenseState = mock(XPackLicenseState.class);
when(licenseState.isSecurityEnabled()).thenReturn(true);
when(licenseState.isDocumentAndFieldLevelSecurityAllowed()).thenReturn(true); when(licenseState.isDocumentAndFieldLevelSecurityAllowed()).thenReturn(true);
Directory directory = newDirectory(); Directory directory = newDirectory();
@ -232,6 +233,7 @@ public class SecurityIndexReaderWrapperIntegrationTests extends AbstractBuilderT
DocumentSubsetBitsetCache bitsetCache = new DocumentSubsetBitsetCache(Settings.EMPTY, Executors.newSingleThreadExecutor()); DocumentSubsetBitsetCache bitsetCache = new DocumentSubsetBitsetCache(Settings.EMPTY, Executors.newSingleThreadExecutor());
XPackLicenseState licenseState = mock(XPackLicenseState.class); XPackLicenseState licenseState = mock(XPackLicenseState.class);
when(licenseState.isSecurityEnabled()).thenReturn(true);
when(licenseState.isDocumentAndFieldLevelSecurityAllowed()).thenReturn(true); when(licenseState.isDocumentAndFieldLevelSecurityAllowed()).thenReturn(true);
SecurityIndexReaderWrapper wrapper = new SecurityIndexReaderWrapper(s -> queryShardContext, SecurityIndexReaderWrapper wrapper = new SecurityIndexReaderWrapper(s -> queryShardContext,
bitsetCache, securityContext, licenseState, scriptService) { bitsetCache, securityContext, licenseState, scriptService) {

View File

@ -64,6 +64,7 @@ public class SecurityIndexReaderWrapperUnitTests extends ESTestCase {
ShardId shardId = new ShardId(index, 0); ShardId shardId = new ShardId(index, 0);
licenseState = mock(XPackLicenseState.class); licenseState = mock(XPackLicenseState.class);
when(licenseState.isSecurityEnabled()).thenReturn(true);
when(licenseState.isDocumentAndFieldLevelSecurityAllowed()).thenReturn(true); when(licenseState.isDocumentAndFieldLevelSecurityAllowed()).thenReturn(true);
securityContext = new SecurityContext(Settings.EMPTY, new ThreadContext(Settings.EMPTY)); securityContext = new SecurityContext(Settings.EMPTY, new ThreadContext(Settings.EMPTY));
IndexShard indexShard = mock(IndexShard.class); IndexShard indexShard = mock(IndexShard.class);

View File

@ -1029,7 +1029,8 @@ public class Security extends Plugin implements SystemIndexPlugin, IngestPlugin,
public Function<String, Predicate<String>> getFieldFilter() { public Function<String, Predicate<String>> getFieldFilter() {
if (enabled) { if (enabled) {
return index -> { return index -> {
if (getLicenseState().isDocumentAndFieldLevelSecurityAllowed() == false) { XPackLicenseState licenseState = getLicenseState();
if (licenseState.isSecurityEnabled() == false || licenseState.isDocumentAndFieldLevelSecurityAllowed() == false) {
return MapperPlugin.NOOP_FIELD_PREDICATE; return MapperPlugin.NOOP_FIELD_PREDICATE;
} }
IndicesAccessControl indicesAccessControl = threadContext.get().getTransient( IndicesAccessControl indicesAccessControl = threadContext.get().getTransient(

View File

@ -31,7 +31,8 @@ public class AuditTrailService {
} }
public AuditTrail get() { public AuditTrail get() {
if (compositeAuditTrail.isEmpty() == false && licenseState.isAuditingAllowed()) { if (compositeAuditTrail.isEmpty() == false &&
licenseState.isSecurityEnabled() && licenseState.isAuditingAllowed()) {
return compositeAuditTrail; return compositeAuditTrail;
} else { } else {
return NOOP_AUDIT_TRAIL; return NOOP_AUDIT_TRAIL;

View File

@ -581,11 +581,11 @@ public class ApiKeyService {
} }
private boolean isEnabled() { private boolean isEnabled() {
return enabled && licenseState.isApiKeyServiceAllowed(); return enabled && licenseState.isSecurityEnabled() && licenseState.isApiKeyServiceAllowed();
} }
public void ensureEnabled() { public void ensureEnabled() {
if (licenseState.isApiKeyServiceAllowed() == false) { if (licenseState.isSecurityEnabled() == false || licenseState.isApiKeyServiceAllowed() == false) {
throw LicenseUtils.newComplianceException("api keys"); throw LicenseUtils.newComplianceException("api keys");
} }
if (enabled == false) { if (enabled == false) {

View File

@ -1519,11 +1519,11 @@ public final class TokenService {
} }
private boolean isEnabled() { private boolean isEnabled() {
return enabled && licenseState.isTokenServiceAllowed(); return enabled && licenseState.isSecurityEnabled() && licenseState.isTokenServiceAllowed();
} }
private void ensureEnabled() { private void ensureEnabled() {
if (licenseState.isTokenServiceAllowed() == false) { if (licenseState.isSecurityEnabled() == false || licenseState.isTokenServiceAllowed() == false) {
throw LicenseUtils.newComplianceException("security tokens"); throw LicenseUtils.newComplianceException("security tokens");
} }
if (enabled == false) { if (enabled == false) {

View File

@ -80,7 +80,8 @@ public class DelegatedAuthorizationSupport {
* with a meaningful diagnostic message. * with a meaningful diagnostic message.
*/ */
public void resolve(String username, ActionListener<AuthenticationResult> resultListener) { public void resolve(String username, ActionListener<AuthenticationResult> resultListener) {
if (licenseState.isAuthorizationRealmAllowed() == false) { boolean authzOk = licenseState.isSecurityEnabled() && licenseState.isAuthorizationRealmAllowed();
if (authzOk == false) {
resultListener.onResponse(AuthenticationResult.unsuccessful( resultListener.onResponse(AuthenticationResult.unsuccessful(
DelegatedAuthorizationSettings.AUTHZ_REALMS_SUFFIX + " are not permitted", DelegatedAuthorizationSettings.AUTHZ_REALMS_SUFFIX + " are not permitted",
LicenseUtils.newComplianceException(DelegatedAuthorizationSettings.AUTHZ_REALMS_SUFFIX) LicenseUtils.newComplianceException(DelegatedAuthorizationSettings.AUTHZ_REALMS_SUFFIX)

View File

@ -365,7 +365,7 @@ public class AuthorizationService {
} }
private AuthorizationEngine getAuthorizationEngineForUser(final User user) { private AuthorizationEngine getAuthorizationEngineForUser(final User user) {
if (rbacEngine != authorizationEngine && licenseState.isAuthorizationEngineAllowed()) { if (rbacEngine != authorizationEngine && licenseState.isSecurityEnabled() && licenseState.isAuthorizationEngineAllowed()) {
if (ClientReservedRealm.isReserved(user.principal(), settings) || isInternalUser(user)) { if (ClientReservedRealm.isReserved(user.principal(), settings) || isInternalUser(user)) {
return rbacEngine; return rbacEngine;
} else { } else {

View File

@ -40,7 +40,8 @@ public class BulkShardRequestInterceptor implements RequestInterceptor {
@Override @Override
public void intercept(RequestInfo requestInfo, AuthorizationEngine authzEngine, AuthorizationInfo authorizationInfo, public void intercept(RequestInfo requestInfo, AuthorizationEngine authzEngine, AuthorizationInfo authorizationInfo,
ActionListener<Void> listener) { ActionListener<Void> listener) {
if (requestInfo.getRequest() instanceof BulkShardRequest && licenseState.isDocumentAndFieldLevelSecurityAllowed()) { boolean shouldIntercept = licenseState.isSecurityEnabled() && licenseState.isDocumentAndFieldLevelSecurityAllowed();
if (requestInfo.getRequest() instanceof BulkShardRequest && shouldIntercept) {
IndicesAccessControl indicesAccessControl = threadContext.getTransient(AuthorizationServiceField.INDICES_PERMISSIONS_KEY); IndicesAccessControl indicesAccessControl = threadContext.getTransient(AuthorizationServiceField.INDICES_PERMISSIONS_KEY);
final BulkShardRequest bulkShardRequest = (BulkShardRequest) requestInfo.getRequest(); final BulkShardRequest bulkShardRequest = (BulkShardRequest) requestInfo.getRequest();

View File

@ -38,7 +38,8 @@ abstract class FieldAndDocumentLevelSecurityRequestInterceptor implements Reques
ActionListener<Void> listener) { ActionListener<Void> listener) {
if (requestInfo.getRequest() instanceof IndicesRequest) { if (requestInfo.getRequest() instanceof IndicesRequest) {
IndicesRequest indicesRequest = (IndicesRequest) requestInfo.getRequest(); IndicesRequest indicesRequest = (IndicesRequest) requestInfo.getRequest();
if (supports(indicesRequest) && licenseState.isDocumentAndFieldLevelSecurityAllowed()) { boolean shouldIntercept = licenseState.isSecurityEnabled() && licenseState.isDocumentAndFieldLevelSecurityAllowed();
if (supports(indicesRequest) && shouldIntercept) {
final IndicesAccessControl indicesAccessControl = final IndicesAccessControl indicesAccessControl =
threadContext.getTransient(AuthorizationServiceField.INDICES_PERMISSIONS_KEY); threadContext.getTransient(AuthorizationServiceField.INDICES_PERMISSIONS_KEY);
for (String index : indicesRequest.indices()) { for (String index : indicesRequest.indices()) {

View File

@ -199,7 +199,7 @@ public class IPFilter {
} }
public boolean accept(String profile, InetSocketAddress peerAddress) { public boolean accept(String profile, InetSocketAddress peerAddress) {
if (licenseState.isIpFilteringAllowed() == false) { if (licenseState.isSecurityEnabled() == false || licenseState.isIpFilteringAllowed() == false) {
return true; return true;
} }

View File

@ -177,6 +177,7 @@ public class TransportOpenIdConnectLogoutActionTests extends OpenIdConnectTestCa
final ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool); final ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool);
final XPackLicenseState licenseState = mock(XPackLicenseState.class); final XPackLicenseState licenseState = mock(XPackLicenseState.class);
when(licenseState.isSecurityEnabled()).thenReturn(true);
when(licenseState.isTokenServiceAllowed()).thenReturn(true); when(licenseState.isTokenServiceAllowed()).thenReturn(true);
tokenService = new TokenService(settings, Clock.systemUTC(), client, licenseState, new SecurityContext(settings, threadContext), tokenService = new TokenService(settings, Clock.systemUTC(), client, licenseState, new SecurityContext(settings, threadContext),

View File

@ -204,6 +204,7 @@ public class TransportSamlInvalidateSessionActionTests extends SamlTestCase {
when(securityIndex.freeze()).thenReturn(securityIndex); when(securityIndex.freeze()).thenReturn(securityIndex);
final XPackLicenseState licenseState = mock(XPackLicenseState.class); final XPackLicenseState licenseState = mock(XPackLicenseState.class);
when(licenseState.isSecurityEnabled()).thenReturn(true);
when(licenseState.isTokenServiceAllowed()).thenReturn(true); when(licenseState.isTokenServiceAllowed()).thenReturn(true);
final ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool); final ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool);

View File

@ -207,6 +207,7 @@ public class TransportSamlLogoutActionTests extends SamlTestCase {
when(securityIndex.freeze()).thenReturn(securityIndex); when(securityIndex.freeze()).thenReturn(securityIndex);
final XPackLicenseState licenseState = mock(XPackLicenseState.class); final XPackLicenseState licenseState = mock(XPackLicenseState.class);
when(licenseState.isSecurityEnabled()).thenReturn(true);
when(licenseState.isTokenServiceAllowed()).thenReturn(true); when(licenseState.isTokenServiceAllowed()).thenReturn(true);
final ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool); final ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool);
final SecurityContext securityContext = new SecurityContext(settings, threadContext); final SecurityContext securityContext = new SecurityContext(settings, threadContext);

View File

@ -168,6 +168,7 @@ public class TransportCreateTokenActionTests extends ESTestCase {
this.clusterService = ClusterServiceUtils.createClusterService(threadPool); this.clusterService = ClusterServiceUtils.createClusterService(threadPool);
this.license = mock(XPackLicenseState.class); this.license = mock(XPackLicenseState.class);
when(license.isSecurityEnabled()).thenReturn(true);
when(license.isTokenServiceAllowed()).thenReturn(true); when(license.isTokenServiceAllowed()).thenReturn(true);
} }

View File

@ -73,6 +73,7 @@ public class TransportInvalidateTokenActionTests extends ESTestCase {
securityIndex = mock(SecurityIndexManager.class); securityIndex = mock(SecurityIndexManager.class);
this.clusterService = ClusterServiceUtils.createClusterService(threadPool); this.clusterService = ClusterServiceUtils.createClusterService(threadPool);
this.license = mock(XPackLicenseState.class); this.license = mock(XPackLicenseState.class);
when(license.isSecurityEnabled()).thenReturn(true);
when(license.isTokenServiceAllowed()).thenReturn(true); when(license.isTokenServiceAllowed()).thenReturn(true);
} }

View File

@ -50,6 +50,7 @@ public class AuditTrailServiceTests extends ESTestCase {
licenseState = mock(XPackLicenseState.class); licenseState = mock(XPackLicenseState.class);
service = new AuditTrailService(auditTrails, licenseState); service = new AuditTrailService(auditTrails, licenseState);
isAuditingAllowed = randomBoolean(); isAuditingAllowed = randomBoolean();
when(licenseState.isSecurityEnabled()).thenReturn(true);
when(licenseState.isAuditingAllowed()).thenReturn(isAuditingAllowed); when(licenseState.isAuditingAllowed()).thenReturn(isAuditingAllowed);
token = mock(AuthenticationToken.class); token = mock(AuthenticationToken.class);
request = mock(TransportRequest.class); request = mock(TransportRequest.class);

View File

@ -98,6 +98,7 @@ public class ApiKeyServiceTests extends ESTestCase {
@Before @Before
public void setupMocks() { public void setupMocks() {
this.licenseState = mock(XPackLicenseState.class); this.licenseState = mock(XPackLicenseState.class);
when(licenseState.isSecurityEnabled()).thenReturn(true);
when(licenseState.isApiKeyServiceAllowed()).thenReturn(true); when(licenseState.isApiKeyServiceAllowed()).thenReturn(true);
this.client = mock(Client.class); this.client = mock(Client.class);

View File

@ -142,6 +142,7 @@ public class TokenServiceTests extends ESTestCase {
// License state (enabled by default) // License state (enabled by default)
licenseState = mock(XPackLicenseState.class); licenseState = mock(XPackLicenseState.class);
when(licenseState.isSecurityEnabled()).thenReturn(true);
when(licenseState.isTokenServiceAllowed()).thenReturn(true); when(licenseState.isTokenServiceAllowed()).thenReturn(true);
// version 7.2 was an "inflection" point in the Token Service development (access_tokens as UUIDS, multiple concurrent refreshes, // version 7.2 was an "inflection" point in the Token Service development (access_tokens as UUIDS, multiple concurrent refreshes,

View File

@ -83,6 +83,7 @@ public abstract class KerberosRealmTestCase extends ESTestCase {
settings = buildKerberosRealmSettings(REALM_NAME, settings = buildKerberosRealmSettings(REALM_NAME,
writeKeyTab(dir.resolve("key.keytab"), "asa").toString(), 100, "10m", true, randomBoolean()); writeKeyTab(dir.resolve("key.keytab"), "asa").toString(), 100, "10m", true, randomBoolean());
licenseState = mock(XPackLicenseState.class); licenseState = mock(XPackLicenseState.class);
when(licenseState.isSecurityEnabled()).thenReturn(true);
when(licenseState.isAuthorizationRealmAllowed()).thenReturn(true); when(licenseState.isAuthorizationRealmAllowed()).thenReturn(true);
} }

View File

@ -106,6 +106,7 @@ public class LdapRealmTests extends LdapTestCase {
defaultGlobalSettings = builder.put("path.home", createTempDir()).build(); defaultGlobalSettings = builder.put("path.home", createTempDir()).build();
sslService = new SSLService(defaultGlobalSettings, TestEnvironment.newEnvironment(defaultGlobalSettings)); sslService = new SSLService(defaultGlobalSettings, TestEnvironment.newEnvironment(defaultGlobalSettings));
licenseState = mock(XPackLicenseState.class); licenseState = mock(XPackLicenseState.class);
when(licenseState.isSecurityEnabled()).thenReturn(true);
when(licenseState.isAuthorizationRealmAllowed()).thenReturn(true); when(licenseState.isAuthorizationRealmAllowed()).thenReturn(true);
} }

View File

@ -380,6 +380,7 @@ public class OpenIdConnectRealmTests extends OpenIdConnectTestCase {
private void initializeRealms(Realm... realms) { private void initializeRealms(Realm... realms) {
XPackLicenseState licenseState = mock(XPackLicenseState.class); XPackLicenseState licenseState = mock(XPackLicenseState.class);
when(licenseState.isSecurityEnabled()).thenReturn(true);
when(licenseState.isAuthorizationRealmAllowed()).thenReturn(true); when(licenseState.isAuthorizationRealmAllowed()).thenReturn(true);
final List<Realm> realmList = Arrays.asList(realms); final List<Realm> realmList = Arrays.asList(realms);

View File

@ -74,6 +74,7 @@ public class PkiRealmTests extends ESTestCase {
.put("path.home", createTempDir()) .put("path.home", createTempDir())
.build(); .build();
licenseState = mock(XPackLicenseState.class); licenseState = mock(XPackLicenseState.class);
when(licenseState.isSecurityEnabled()).thenReturn(true);
when(licenseState.isAuthorizationRealmAllowed()).thenReturn(true); when(licenseState.isAuthorizationRealmAllowed()).thenReturn(true);
} }

View File

@ -296,6 +296,7 @@ public class SamlRealmTests extends SamlTestCase {
private void initializeRealms(Realm... realms) { private void initializeRealms(Realm... realms) {
XPackLicenseState licenseState = mock(XPackLicenseState.class); XPackLicenseState licenseState = mock(XPackLicenseState.class);
when(licenseState.isSecurityEnabled()).thenReturn(true);
when(licenseState.isAuthorizationRealmAllowed()).thenReturn(true); when(licenseState.isAuthorizationRealmAllowed()).thenReturn(true);
final List<Realm> realmList = Arrays.asList(realms); final List<Realm> realmList = Arrays.asList(realms);

View File

@ -188,6 +188,7 @@ public class DelegatedAuthorizationSupportTests extends ESTestCase {
private XPackLicenseState getLicenseState(boolean authzRealmsAllowed) { private XPackLicenseState getLicenseState(boolean authzRealmsAllowed) {
final XPackLicenseState license = mock(XPackLicenseState.class); final XPackLicenseState license = mock(XPackLicenseState.class);
when(license.isSecurityEnabled()).thenReturn(true);
when(license.isAuthorizationRealmAllowed()).thenReturn(authzRealmsAllowed); when(license.isAuthorizationRealmAllowed()).thenReturn(authzRealmsAllowed);
return license; return license;
} }

View File

@ -203,6 +203,7 @@ public class AuthorizationServiceTests extends ESTestCase {
when(clusterService.state()).thenReturn(ClusterState.EMPTY_STATE); when(clusterService.state()).thenReturn(ClusterState.EMPTY_STATE);
auditTrail = mock(AuditTrail.class); auditTrail = mock(AuditTrail.class);
XPackLicenseState licenseState = mock(XPackLicenseState.class); XPackLicenseState licenseState = mock(XPackLicenseState.class);
when(licenseState.isSecurityEnabled()).thenReturn(true);
when(licenseState.isAuditingAllowed()).thenReturn(true); when(licenseState.isAuditingAllowed()).thenReturn(true);
auditTrailService = new AuditTrailService(Collections.singletonList(auditTrail), licenseState); auditTrailService = new AuditTrailService(Collections.singletonList(auditTrail), licenseState);
threadContext = new ThreadContext(settings); threadContext = new ThreadContext(settings);
@ -1454,6 +1455,7 @@ public class AuthorizationServiceTests extends ESTestCase {
}; };
XPackLicenseState licenseState = mock(XPackLicenseState.class); XPackLicenseState licenseState = mock(XPackLicenseState.class);
when(licenseState.isSecurityEnabled()).thenReturn(true);
when(licenseState.isAuthorizationEngineAllowed()).thenReturn(true); when(licenseState.isAuthorizationEngineAllowed()).thenReturn(true);
authorizationService = new AuthorizationService(Settings.EMPTY, rolesStore, clusterService, authorizationService = new AuthorizationService(Settings.EMPTY, rolesStore, clusterService,
auditTrailService, new DefaultAuthenticationFailureHandler(Collections.emptyMap()), threadPool, auditTrailService, new DefaultAuthenticationFailureHandler(Collections.emptyMap()), threadPool,

View File

@ -29,6 +29,7 @@ import org.elasticsearch.xpack.core.security.authz.AuthorizationEngine.Authoriza
import org.elasticsearch.xpack.core.security.user.User; import org.elasticsearch.xpack.core.security.user.User;
import org.elasticsearch.xpack.security.audit.AuditTrail; import org.elasticsearch.xpack.security.audit.AuditTrail;
import org.elasticsearch.xpack.security.audit.AuditTrailService; import org.elasticsearch.xpack.security.audit.AuditTrailService;
import org.mockito.Mockito;
import java.util.Collections; import java.util.Collections;
@ -133,7 +134,7 @@ public class SecuritySearchOperationListenerTests extends ESTestCase {
SearchContextMissingException expected = SearchContextMissingException expected =
expectThrows(SearchContextMissingException.class, () -> listener.validateSearchContext(testSearchContext, request)); expectThrows(SearchContextMissingException.class, () -> listener.validateSearchContext(testSearchContext, request));
assertEquals(testSearchContext.id(), expected.contextId()); assertEquals(testSearchContext.id(), expected.contextId());
verify(licenseState, times(3)).isSecurityEnabled(); verify(licenseState, Mockito.atLeast(3)).isSecurityEnabled();
verify(auditTrail).accessDenied(eq(null), eq(authentication), eq("action"), eq(request), verify(auditTrail).accessDenied(eq(null), eq(authentication), eq("action"), eq(request),
authzInfoRoles(authentication.getUser().roles())); authzInfoRoles(authentication.getUser().roles()));
} }
@ -150,7 +151,7 @@ public class SecuritySearchOperationListenerTests extends ESTestCase {
threadContext.putTransient(ORIGINATING_ACTION_KEY, "action"); threadContext.putTransient(ORIGINATING_ACTION_KEY, "action");
final InternalScrollSearchRequest request = new InternalScrollSearchRequest(); final InternalScrollSearchRequest request = new InternalScrollSearchRequest();
listener.validateSearchContext(testSearchContext, request); listener.validateSearchContext(testSearchContext, request);
verify(licenseState, times(4)).isSecurityEnabled(); verify(licenseState, Mockito.atLeast(4)).isSecurityEnabled();
verifyNoMoreInteractions(auditTrail); verifyNoMoreInteractions(auditTrail);
} }
@ -169,7 +170,7 @@ public class SecuritySearchOperationListenerTests extends ESTestCase {
SearchContextMissingException expected = SearchContextMissingException expected =
expectThrows(SearchContextMissingException.class, () -> listener.validateSearchContext(testSearchContext, request)); expectThrows(SearchContextMissingException.class, () -> listener.validateSearchContext(testSearchContext, request));
assertEquals(testSearchContext.id(), expected.contextId()); assertEquals(testSearchContext.id(), expected.contextId());
verify(licenseState, times(5)).isSecurityEnabled(); verify(licenseState, Mockito.atLeast(5)).isSecurityEnabled();
verify(auditTrail).accessDenied(eq(null), eq(authentication), eq("action"), eq(request), verify(auditTrail).accessDenied(eq(null), eq(authentication), eq("action"), eq(request),
authzInfoRoles(authentication.getUser().roles())); authzInfoRoles(authentication.getUser().roles()));
} }

View File

@ -117,6 +117,7 @@ public class CompositeRolesStoreTests extends ESTestCase {
public void testRolesWhenDlsFlsUnlicensed() throws IOException { public void testRolesWhenDlsFlsUnlicensed() throws IOException {
XPackLicenseState licenseState = mock(XPackLicenseState.class); XPackLicenseState licenseState = mock(XPackLicenseState.class);
when(licenseState.isSecurityEnabled()).thenReturn(true);
when(licenseState.isDocumentAndFieldLevelSecurityAllowed()).thenReturn(false); when(licenseState.isDocumentAndFieldLevelSecurityAllowed()).thenReturn(false);
RoleDescriptor flsRole = new RoleDescriptor("fls", null, new IndicesPrivileges[] { RoleDescriptor flsRole = new RoleDescriptor("fls", null, new IndicesPrivileges[] {
IndicesPrivileges.builder() IndicesPrivileges.builder()
@ -187,6 +188,7 @@ public class CompositeRolesStoreTests extends ESTestCase {
public void testRolesWhenDlsFlsLicensed() throws IOException { public void testRolesWhenDlsFlsLicensed() throws IOException {
XPackLicenseState licenseState = mock(XPackLicenseState.class); XPackLicenseState licenseState = mock(XPackLicenseState.class);
when(licenseState.isSecurityEnabled()).thenReturn(true);
when(licenseState.isDocumentAndFieldLevelSecurityAllowed()).thenReturn(true); when(licenseState.isDocumentAndFieldLevelSecurityAllowed()).thenReturn(true);
RoleDescriptor flsRole = new RoleDescriptor("fls", null, new IndicesPrivileges[] { RoleDescriptor flsRole = new RoleDescriptor("fls", null, new IndicesPrivileges[] {
IndicesPrivileges.builder() IndicesPrivileges.builder()

View File

@ -287,6 +287,7 @@ public class FileRolesStoreTests extends ESTestCase {
List<String> events = CapturingLogger.output(logger.getName(), Level.WARN); List<String> events = CapturingLogger.output(logger.getName(), Level.WARN);
events.clear(); events.clear();
XPackLicenseState licenseState = mock(XPackLicenseState.class); XPackLicenseState licenseState = mock(XPackLicenseState.class);
when(licenseState.isSecurityEnabled()).thenReturn(true);
when(licenseState.isDocumentAndFieldLevelSecurityAllowed()).thenReturn(false); when(licenseState.isDocumentAndFieldLevelSecurityAllowed()).thenReturn(false);
Map<String, RoleDescriptor> roles = FileRolesStore.parseFile(path, logger, Settings.EMPTY, licenseState, xContentRegistry()); Map<String, RoleDescriptor> roles = FileRolesStore.parseFile(path, logger, Settings.EMPTY, licenseState, xContentRegistry());
assertThat(roles, notNullValue()); assertThat(roles, notNullValue());

View File

@ -94,6 +94,7 @@ public class NativeRolesStoreTests extends ESTestCase {
public void testRoleDescriptorWithFlsDlsLicensing() throws IOException { public void testRoleDescriptorWithFlsDlsLicensing() throws IOException {
XPackLicenseState licenseState = mock(XPackLicenseState.class); XPackLicenseState licenseState = mock(XPackLicenseState.class);
when(licenseState.isSecurityEnabled()).thenReturn(true);
when(licenseState.isDocumentAndFieldLevelSecurityAllowed()).thenReturn(false); when(licenseState.isDocumentAndFieldLevelSecurityAllowed()).thenReturn(false);
RoleDescriptor flsRole = new RoleDescriptor("fls", null, RoleDescriptor flsRole = new RoleDescriptor("fls", null,
new IndicesPrivileges[] { IndicesPrivileges.builder().privileges("READ").indices("*") new IndicesPrivileges[] { IndicesPrivileges.builder().privileges("READ").indices("*")

View File

@ -172,6 +172,7 @@ public final class SecurityMocks {
final Client client = mock(Client.class); final Client client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool); when(client.threadPool()).thenReturn(threadPool);
final XPackLicenseState licenseState = mock(XPackLicenseState.class); final XPackLicenseState licenseState = mock(XPackLicenseState.class);
when(licenseState.isSecurityEnabled()).thenReturn(true);
when(licenseState.isTokenServiceAllowed()).thenReturn(true); when(licenseState.isTokenServiceAllowed()).thenReturn(true);
final ClusterService clusterService = mock(ClusterService.class); final ClusterService clusterService = mock(ClusterService.class);

View File

@ -60,6 +60,7 @@ public class IPFilterTests extends ESTestCase {
@Before @Before
public void init() { public void init() {
licenseState = mock(XPackLicenseState.class); licenseState = mock(XPackLicenseState.class);
when(licenseState.isSecurityEnabled()).thenReturn(true);
when(licenseState.isIpFilteringAllowed()).thenReturn(true); when(licenseState.isIpFilteringAllowed()).thenReturn(true);
when(licenseState.isAuditingAllowed()).thenReturn(true); when(licenseState.isAuditingAllowed()).thenReturn(true);
auditTrail = mock(AuditTrail.class); auditTrail = mock(AuditTrail.class);

View File

@ -56,6 +56,7 @@ public class IpFilterRemoteAddressFilterTests extends ESTestCase {
IPFilter.PROFILE_FILTER_ALLOW_SETTING, IPFilter.PROFILE_FILTER_ALLOW_SETTING,
IPFilter.PROFILE_FILTER_DENY_SETTING))); IPFilter.PROFILE_FILTER_DENY_SETTING)));
XPackLicenseState licenseState = mock(XPackLicenseState.class); XPackLicenseState licenseState = mock(XPackLicenseState.class);
when(licenseState.isSecurityEnabled()).thenReturn(true);
when(licenseState.isIpFilteringAllowed()).thenReturn(true); when(licenseState.isIpFilteringAllowed()).thenReturn(true);
AuditTrailService auditTrailService = new AuditTrailService(Collections.emptyList(), licenseState); AuditTrailService auditTrailService = new AuditTrailService(Collections.emptyList(), licenseState);
IPFilter ipFilter = new IPFilter(settings, auditTrailService, clusterSettings, licenseState); IPFilter ipFilter = new IPFilter(settings, auditTrailService, clusterSettings, licenseState);

View File

@ -59,6 +59,7 @@ public class NioIPFilterTests extends ESTestCase {
IPFilter.PROFILE_FILTER_ALLOW_SETTING, IPFilter.PROFILE_FILTER_ALLOW_SETTING,
IPFilter.PROFILE_FILTER_DENY_SETTING))); IPFilter.PROFILE_FILTER_DENY_SETTING)));
XPackLicenseState licenseState = mock(XPackLicenseState.class); XPackLicenseState licenseState = mock(XPackLicenseState.class);
when(licenseState.isSecurityEnabled()).thenReturn(true);
when(licenseState.isIpFilteringAllowed()).thenReturn(true); when(licenseState.isIpFilteringAllowed()).thenReturn(true);
AuditTrailService auditTrailService = new AuditTrailService(Collections.emptyList(), licenseState); AuditTrailService auditTrailService = new AuditTrailService(Collections.emptyList(), licenseState);
ipFilter = new IPFilter(settings, auditTrailService, clusterSettings, licenseState); ipFilter = new IPFilter(settings, auditTrailService, clusterSettings, licenseState);