|
@@ -66,6 +66,7 @@ import java.util.Map;
|
|
|
import java.util.Set;
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.function.BiConsumer;
|
|
|
import java.util.function.Consumer;
|
|
|
import java.util.function.Function;
|
|
@@ -74,9 +75,11 @@ import java.util.function.Predicate;
|
|
|
import static org.elasticsearch.mock.orig.Mockito.times;
|
|
|
import static org.elasticsearch.mock.orig.Mockito.verifyNoMoreInteractions;
|
|
|
import static org.hamcrest.Matchers.anyOf;
|
|
|
+import static org.hamcrest.Matchers.is;
|
|
|
+import static org.hamcrest.Matchers.nullValue;
|
|
|
+import static org.hamcrest.Matchers.containsInAnyOrder;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
import static org.hamcrest.Matchers.hasItem;
|
|
|
-import static org.hamcrest.Matchers.is;
|
|
|
import static org.mockito.Matchers.any;
|
|
|
import static org.mockito.Matchers.anySetOf;
|
|
|
import static org.mockito.Matchers.eq;
|
|
@@ -143,25 +146,35 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
when(fileRolesStore.roleDescriptors(Collections.singleton("dls"))).thenReturn(Collections.singleton(dlsRole));
|
|
|
when(fileRolesStore.roleDescriptors(Collections.singleton("fls_dls"))).thenReturn(Collections.singleton(flsDlsRole));
|
|
|
when(fileRolesStore.roleDescriptors(Collections.singleton("no_fls_dls"))).thenReturn(Collections.singleton(noFlsDlsRole));
|
|
|
+ final AtomicReference<Collection<RoleDescriptor>> effectiveRoleDescriptors = new AtomicReference<Collection<RoleDescriptor>>();
|
|
|
CompositeRolesStore compositeRolesStore = new CompositeRolesStore(Settings.EMPTY, fileRolesStore, nativeRolesStore,
|
|
|
reservedRolesStore, mock(NativePrivilegeStore.class), Collections.emptyList(),
|
|
|
- new ThreadContext(Settings.EMPTY), licenseState, cache, mock(ApiKeyService.class));
|
|
|
+ new ThreadContext(Settings.EMPTY), licenseState, cache, mock(ApiKeyService.class),
|
|
|
+ rds -> effectiveRoleDescriptors.set(rds));
|
|
|
|
|
|
PlainActionFuture<Role> roleFuture = new PlainActionFuture<>();
|
|
|
compositeRolesStore.roles(Collections.singleton("fls"), roleFuture);
|
|
|
assertEquals(Role.EMPTY, roleFuture.actionGet());
|
|
|
+ assertThat(effectiveRoleDescriptors.get().isEmpty(), is(true));
|
|
|
+ effectiveRoleDescriptors.set(null);
|
|
|
|
|
|
roleFuture = new PlainActionFuture<>();
|
|
|
compositeRolesStore.roles(Collections.singleton("dls"), roleFuture);
|
|
|
assertEquals(Role.EMPTY, roleFuture.actionGet());
|
|
|
+ assertThat(effectiveRoleDescriptors.get().isEmpty(), is(true));
|
|
|
+ effectiveRoleDescriptors.set(null);
|
|
|
|
|
|
roleFuture = new PlainActionFuture<>();
|
|
|
compositeRolesStore.roles(Collections.singleton("fls_dls"), roleFuture);
|
|
|
assertEquals(Role.EMPTY, roleFuture.actionGet());
|
|
|
+ assertThat(effectiveRoleDescriptors.get().isEmpty(), is(true));
|
|
|
+ effectiveRoleDescriptors.set(null);
|
|
|
|
|
|
roleFuture = new PlainActionFuture<>();
|
|
|
compositeRolesStore.roles(Collections.singleton("no_fls_dls"), roleFuture);
|
|
|
assertNotEquals(Role.EMPTY, roleFuture.actionGet());
|
|
|
+ assertThat(effectiveRoleDescriptors.get(), containsInAnyOrder(noFlsDlsRole));
|
|
|
+ effectiveRoleDescriptors.set(null);
|
|
|
}
|
|
|
|
|
|
public void testRolesWhenDlsFlsLicensed() throws IOException {
|
|
@@ -208,25 +221,35 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
when(fileRolesStore.roleDescriptors(Collections.singleton("dls"))).thenReturn(Collections.singleton(dlsRole));
|
|
|
when(fileRolesStore.roleDescriptors(Collections.singleton("fls_dls"))).thenReturn(Collections.singleton(flsDlsRole));
|
|
|
when(fileRolesStore.roleDescriptors(Collections.singleton("no_fls_dls"))).thenReturn(Collections.singleton(noFlsDlsRole));
|
|
|
+ final AtomicReference<Collection<RoleDescriptor>> effectiveRoleDescriptors = new AtomicReference<Collection<RoleDescriptor>>();
|
|
|
CompositeRolesStore compositeRolesStore = new CompositeRolesStore(Settings.EMPTY, fileRolesStore, nativeRolesStore,
|
|
|
reservedRolesStore, mock(NativePrivilegeStore.class), Collections.emptyList(),
|
|
|
- new ThreadContext(Settings.EMPTY), licenseState, cache, mock(ApiKeyService.class));
|
|
|
+ new ThreadContext(Settings.EMPTY), licenseState, cache, mock(ApiKeyService.class),
|
|
|
+ rds -> effectiveRoleDescriptors.set(rds));
|
|
|
|
|
|
PlainActionFuture<Role> roleFuture = new PlainActionFuture<>();
|
|
|
compositeRolesStore.roles(Collections.singleton("fls"), roleFuture);
|
|
|
assertNotEquals(Role.EMPTY, roleFuture.actionGet());
|
|
|
+ assertThat(effectiveRoleDescriptors.get(), containsInAnyOrder(flsRole));
|
|
|
+ effectiveRoleDescriptors.set(null);
|
|
|
|
|
|
roleFuture = new PlainActionFuture<>();
|
|
|
compositeRolesStore.roles(Collections.singleton("dls"), roleFuture);
|
|
|
assertNotEquals(Role.EMPTY, roleFuture.actionGet());
|
|
|
+ assertThat(effectiveRoleDescriptors.get(), containsInAnyOrder(dlsRole));
|
|
|
+ effectiveRoleDescriptors.set(null);
|
|
|
|
|
|
roleFuture = new PlainActionFuture<>();
|
|
|
compositeRolesStore.roles(Collections.singleton("fls_dls"), roleFuture);
|
|
|
assertNotEquals(Role.EMPTY, roleFuture.actionGet());
|
|
|
+ assertThat(effectiveRoleDescriptors.get(), containsInAnyOrder(flsDlsRole));
|
|
|
+ effectiveRoleDescriptors.set(null);
|
|
|
|
|
|
roleFuture = new PlainActionFuture<>();
|
|
|
compositeRolesStore.roles(Collections.singleton("no_fls_dls"), roleFuture);
|
|
|
assertNotEquals(Role.EMPTY, roleFuture.actionGet());
|
|
|
+ assertThat(effectiveRoleDescriptors.get(), containsInAnyOrder(noFlsDlsRole));
|
|
|
+ effectiveRoleDescriptors.set(null);
|
|
|
}
|
|
|
|
|
|
public void testNegativeLookupsAreCached() {
|
|
@@ -249,16 +272,20 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
return null;
|
|
|
}).when(nativePrivilegeStore).getPrivileges(isA(Set.class), isA(Set.class), any(ActionListener.class));
|
|
|
|
|
|
+ final AtomicReference<Collection<RoleDescriptor>> effectiveRoleDescriptors = new AtomicReference<Collection<RoleDescriptor>>();
|
|
|
final CompositeRolesStore compositeRolesStore =
|
|
|
new CompositeRolesStore(SECURITY_ENABLED_SETTINGS, fileRolesStore, nativeRolesStore, reservedRolesStore,
|
|
|
nativePrivilegeStore, Collections.emptyList(), new ThreadContext(SECURITY_ENABLED_SETTINGS),
|
|
|
- new XPackLicenseState(SECURITY_ENABLED_SETTINGS), cache, mock(ApiKeyService.class));
|
|
|
+ new XPackLicenseState(SECURITY_ENABLED_SETTINGS), cache, mock(ApiKeyService.class),
|
|
|
+ rds -> effectiveRoleDescriptors.set(rds));
|
|
|
verify(fileRolesStore).addListener(any(Consumer.class)); // adds a listener in ctor
|
|
|
|
|
|
final String roleName = randomAlphaOfLengthBetween(1, 10);
|
|
|
PlainActionFuture<Role> future = new PlainActionFuture<>();
|
|
|
compositeRolesStore.roles(Collections.singleton(roleName), future);
|
|
|
final Role role = future.actionGet();
|
|
|
+ assertThat(effectiveRoleDescriptors.get().isEmpty(), is(true));
|
|
|
+ effectiveRoleDescriptors.set(null);
|
|
|
assertEquals(Role.EMPTY, role);
|
|
|
verify(reservedRolesStore).accept(anySetOf(String.class), any(ActionListener.class));
|
|
|
verify(fileRolesStore).accept(anySetOf(String.class), any(ActionListener.class));
|
|
@@ -275,6 +302,12 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
future = new PlainActionFuture<>();
|
|
|
compositeRolesStore.roles(names, future);
|
|
|
future.actionGet();
|
|
|
+ if (getSuperuserRole && i == 0) {
|
|
|
+ assertThat(effectiveRoleDescriptors.get(), containsInAnyOrder(ReservedRolesStore.SUPERUSER_ROLE_DESCRIPTOR));
|
|
|
+ effectiveRoleDescriptors.set(null);
|
|
|
+ } else {
|
|
|
+ assertThat(effectiveRoleDescriptors.get(), is(nullValue()));
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (getSuperuserRole && numberOfTimesToCall > 0) {
|
|
@@ -301,15 +334,18 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
final Settings settings = Settings.builder().put(SECURITY_ENABLED_SETTINGS)
|
|
|
.put("xpack.security.authz.store.roles.negative_lookup_cache.max_size", 0)
|
|
|
.build();
|
|
|
+ final AtomicReference<Collection<RoleDescriptor>> effectiveRoleDescriptors = new AtomicReference<Collection<RoleDescriptor>>();
|
|
|
final CompositeRolesStore compositeRolesStore = new CompositeRolesStore(settings, fileRolesStore, nativeRolesStore,
|
|
|
reservedRolesStore, mock(NativePrivilegeStore.class), Collections.emptyList(), new ThreadContext(settings),
|
|
|
- new XPackLicenseState(settings), cache, mock(ApiKeyService.class));
|
|
|
+ new XPackLicenseState(settings), cache, mock(ApiKeyService.class), rds -> effectiveRoleDescriptors.set(rds));
|
|
|
verify(fileRolesStore).addListener(any(Consumer.class)); // adds a listener in ctor
|
|
|
|
|
|
final String roleName = randomAlphaOfLengthBetween(1, 10);
|
|
|
PlainActionFuture<Role> future = new PlainActionFuture<>();
|
|
|
compositeRolesStore.roles(Collections.singleton(roleName), future);
|
|
|
final Role role = future.actionGet();
|
|
|
+ assertThat(effectiveRoleDescriptors.get().isEmpty(), is(true));
|
|
|
+ effectiveRoleDescriptors.set(null);
|
|
|
assertEquals(Role.EMPTY, role);
|
|
|
verify(reservedRolesStore).accept(anySetOf(String.class), any(ActionListener.class));
|
|
|
verify(fileRolesStore).accept(anySetOf(String.class), any(ActionListener.class));
|
|
@@ -334,16 +370,20 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
}).when(nativeRolesStore).getRoleDescriptors(isA(Set.class), any(ActionListener.class));
|
|
|
final ReservedRolesStore reservedRolesStore = spy(new ReservedRolesStore());
|
|
|
|
|
|
+ final AtomicReference<Collection<RoleDescriptor>> effectiveRoleDescriptors = new AtomicReference<Collection<RoleDescriptor>>();
|
|
|
final CompositeRolesStore compositeRolesStore =
|
|
|
new CompositeRolesStore(SECURITY_ENABLED_SETTINGS, fileRolesStore, nativeRolesStore, reservedRolesStore,
|
|
|
mock(NativePrivilegeStore.class), Collections.emptyList(), new ThreadContext(SECURITY_ENABLED_SETTINGS),
|
|
|
- new XPackLicenseState(SECURITY_ENABLED_SETTINGS), cache, mock(ApiKeyService.class));
|
|
|
+ new XPackLicenseState(SECURITY_ENABLED_SETTINGS), cache, mock(ApiKeyService.class),
|
|
|
+ rds -> effectiveRoleDescriptors.set(rds));
|
|
|
verify(fileRolesStore).addListener(any(Consumer.class)); // adds a listener in ctor
|
|
|
|
|
|
final String roleName = randomAlphaOfLengthBetween(1, 10);
|
|
|
PlainActionFuture<Role> future = new PlainActionFuture<>();
|
|
|
compositeRolesStore.roles(Collections.singleton(roleName), future);
|
|
|
final Role role = future.actionGet();
|
|
|
+ assertThat(effectiveRoleDescriptors.get().isEmpty(), is(true));
|
|
|
+ effectiveRoleDescriptors.set(null);
|
|
|
assertEquals(Role.EMPTY, role);
|
|
|
verify(reservedRolesStore).accept(anySetOf(String.class), any(ActionListener.class));
|
|
|
verify(fileRolesStore).accept(anySetOf(String.class), any(ActionListener.class));
|
|
@@ -357,6 +397,8 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
future = new PlainActionFuture<>();
|
|
|
compositeRolesStore.roles(names, future);
|
|
|
future.actionGet();
|
|
|
+ assertThat(effectiveRoleDescriptors.get().isEmpty(), is(true));
|
|
|
+ effectiveRoleDescriptors.set(null);
|
|
|
}
|
|
|
|
|
|
assertFalse(compositeRolesStore.isValueInNegativeLookupCache(roleName));
|
|
@@ -381,17 +423,22 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
}).when(nativeRolesStore).getRoleDescriptors(isA(Set.class), any(ActionListener.class));
|
|
|
final ReservedRolesStore reservedRolesStore = spy(new ReservedRolesStore());
|
|
|
|
|
|
+ final RoleDescriptor roleAProvider1 = new RoleDescriptor("roleA", null,
|
|
|
+ new IndicesPrivileges[] {
|
|
|
+ IndicesPrivileges.builder().privileges("READ").indices("foo").grantedFields("*").build()
|
|
|
+ }, null);
|
|
|
final InMemoryRolesProvider inMemoryProvider1 = spy(new InMemoryRolesProvider((roles) -> {
|
|
|
Set<RoleDescriptor> descriptors = new HashSet<>();
|
|
|
if (roles.contains("roleA")) {
|
|
|
- descriptors.add(new RoleDescriptor("roleA", null,
|
|
|
- new IndicesPrivileges[] {
|
|
|
- IndicesPrivileges.builder().privileges("READ").indices("foo").grantedFields("*").build()
|
|
|
- }, null));
|
|
|
+ descriptors.add(roleAProvider1);
|
|
|
}
|
|
|
return RoleRetrievalResult.success(descriptors);
|
|
|
}));
|
|
|
|
|
|
+ final RoleDescriptor roleBProvider2 = new RoleDescriptor("roleB", null,
|
|
|
+ new IndicesPrivileges[] {
|
|
|
+ IndicesPrivileges.builder().privileges("READ").indices("bar").grantedFields("*").build()
|
|
|
+ }, null);
|
|
|
final InMemoryRolesProvider inMemoryProvider2 = spy(new InMemoryRolesProvider((roles) -> {
|
|
|
Set<RoleDescriptor> descriptors = new HashSet<>();
|
|
|
if (roles.contains("roleA")) {
|
|
@@ -403,24 +450,24 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
}, null));
|
|
|
}
|
|
|
if (roles.contains("roleB")) {
|
|
|
- descriptors.add(new RoleDescriptor("roleB", null,
|
|
|
- new IndicesPrivileges[] {
|
|
|
- IndicesPrivileges.builder().privileges("READ").indices("bar").grantedFields("*").build()
|
|
|
- }, null));
|
|
|
+ descriptors.add(roleBProvider2);
|
|
|
}
|
|
|
return RoleRetrievalResult.success(descriptors);
|
|
|
}));
|
|
|
|
|
|
+ final AtomicReference<Collection<RoleDescriptor>> effectiveRoleDescriptors = new AtomicReference<Collection<RoleDescriptor>>();
|
|
|
final CompositeRolesStore compositeRolesStore =
|
|
|
new CompositeRolesStore(SECURITY_ENABLED_SETTINGS, fileRolesStore, nativeRolesStore, reservedRolesStore,
|
|
|
mock(NativePrivilegeStore.class), Arrays.asList(inMemoryProvider1, inMemoryProvider2),
|
|
|
- new ThreadContext(SECURITY_ENABLED_SETTINGS), new XPackLicenseState(SECURITY_ENABLED_SETTINGS), cache,
|
|
|
- mock(ApiKeyService.class));
|
|
|
+ new ThreadContext(SECURITY_ENABLED_SETTINGS), new XPackLicenseState(SECURITY_ENABLED_SETTINGS),
|
|
|
+ cache, mock(ApiKeyService.class), rds -> effectiveRoleDescriptors.set(rds));
|
|
|
|
|
|
final Set<String> roleNames = Sets.newHashSet("roleA", "roleB", "unknown");
|
|
|
PlainActionFuture<Role> future = new PlainActionFuture<>();
|
|
|
compositeRolesStore.roles(roleNames, future);
|
|
|
final Role role = future.actionGet();
|
|
|
+ assertThat(effectiveRoleDescriptors.get(), containsInAnyOrder(roleAProvider1, roleBProvider2));
|
|
|
+ effectiveRoleDescriptors.set(null);
|
|
|
|
|
|
// make sure custom roles providers populate roles correctly
|
|
|
assertEquals(2, role.indices().groups().length);
|
|
@@ -438,6 +485,12 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
future = new PlainActionFuture<>();
|
|
|
compositeRolesStore.roles(Collections.singleton("unknown"), future);
|
|
|
future.actionGet();
|
|
|
+ if (i == 0) {
|
|
|
+ assertThat(effectiveRoleDescriptors.get().isEmpty(), is(true));
|
|
|
+ } else {
|
|
|
+ assertThat(effectiveRoleDescriptors.get(), is(nullValue()));
|
|
|
+ }
|
|
|
+ effectiveRoleDescriptors.set(null);
|
|
|
}
|
|
|
|
|
|
verifyNoMoreInteractions(inMemoryProvider1, inMemoryProvider2);
|
|
@@ -616,11 +669,12 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
final BiConsumer<Set<String>, ActionListener<RoleRetrievalResult>> failingProvider =
|
|
|
(roles, listener) -> listener.onFailure(new Exception("fake failure"));
|
|
|
|
|
|
+ final AtomicReference<Collection<RoleDescriptor>> effectiveRoleDescriptors = new AtomicReference<Collection<RoleDescriptor>>();
|
|
|
final CompositeRolesStore compositeRolesStore =
|
|
|
new CompositeRolesStore(SECURITY_ENABLED_SETTINGS, fileRolesStore, nativeRolesStore, reservedRolesStore,
|
|
|
mock(NativePrivilegeStore.class), Arrays.asList(inMemoryProvider1, failingProvider),
|
|
|
- new ThreadContext(SECURITY_ENABLED_SETTINGS), new XPackLicenseState(SECURITY_ENABLED_SETTINGS), cache,
|
|
|
- mock(ApiKeyService.class));
|
|
|
+ new ThreadContext(SECURITY_ENABLED_SETTINGS), new XPackLicenseState(SECURITY_ENABLED_SETTINGS),
|
|
|
+ cache, mock(ApiKeyService.class), rds -> effectiveRoleDescriptors.set(rds));
|
|
|
|
|
|
final Set<String> roleNames = Sets.newHashSet("roleA", "roleB", "unknown");
|
|
|
PlainActionFuture<Role> future = new PlainActionFuture<>();
|
|
@@ -630,6 +684,7 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
fail("provider should have thrown a failure");
|
|
|
} catch (ExecutionException e) {
|
|
|
assertEquals("fake failure", e.getCause().getMessage());
|
|
|
+ assertThat(effectiveRoleDescriptors.get(), is(nullValue()));
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -646,13 +701,14 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
}).when(nativeRolesStore).getRoleDescriptors(isA(Set.class), any(ActionListener.class));
|
|
|
final ReservedRolesStore reservedRolesStore = new ReservedRolesStore();
|
|
|
|
|
|
+ final RoleDescriptor roleA = new RoleDescriptor("roleA", null,
|
|
|
+ new IndicesPrivileges[] {
|
|
|
+ IndicesPrivileges.builder().privileges("READ").indices("foo").grantedFields("*").build()
|
|
|
+ }, null);
|
|
|
final InMemoryRolesProvider inMemoryProvider = new InMemoryRolesProvider((roles) -> {
|
|
|
Set<RoleDescriptor> descriptors = new HashSet<>();
|
|
|
if (roles.contains("roleA")) {
|
|
|
- descriptors.add(new RoleDescriptor("roleA", null,
|
|
|
- new IndicesPrivileges[] {
|
|
|
- IndicesPrivileges.builder().privileges("READ").indices("foo").grantedFields("*").build()
|
|
|
- }, null));
|
|
|
+ descriptors.add(roleA);
|
|
|
}
|
|
|
return RoleRetrievalResult.success(descriptors);
|
|
|
});
|
|
@@ -660,27 +716,34 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
UpdatableLicenseState xPackLicenseState = new UpdatableLicenseState(SECURITY_ENABLED_SETTINGS);
|
|
|
// these licenses don't allow custom role providers
|
|
|
xPackLicenseState.update(randomFrom(OperationMode.BASIC, OperationMode.GOLD, OperationMode.STANDARD), true, null);
|
|
|
+ final AtomicReference<Collection<RoleDescriptor>> effectiveRoleDescriptors = new AtomicReference<Collection<RoleDescriptor>>();
|
|
|
CompositeRolesStore compositeRolesStore = new CompositeRolesStore(
|
|
|
Settings.EMPTY, fileRolesStore, nativeRolesStore, reservedRolesStore, mock(NativePrivilegeStore.class),
|
|
|
- Arrays.asList(inMemoryProvider), new ThreadContext(Settings.EMPTY), xPackLicenseState, cache, mock(ApiKeyService.class));
|
|
|
+ Arrays.asList(inMemoryProvider), new ThreadContext(Settings.EMPTY), xPackLicenseState, cache,
|
|
|
+ mock(ApiKeyService.class), rds -> effectiveRoleDescriptors.set(rds));
|
|
|
|
|
|
Set<String> roleNames = Sets.newHashSet("roleA");
|
|
|
PlainActionFuture<Role> future = new PlainActionFuture<>();
|
|
|
compositeRolesStore.roles(roleNames, future);
|
|
|
Role role = future.actionGet();
|
|
|
+ assertThat(effectiveRoleDescriptors.get().isEmpty(), is(true));
|
|
|
+ effectiveRoleDescriptors.set(null);
|
|
|
|
|
|
// no roles should've been populated, as the license doesn't permit custom role providers
|
|
|
assertEquals(0, role.indices().groups().length);
|
|
|
|
|
|
compositeRolesStore = new CompositeRolesStore(
|
|
|
Settings.EMPTY, fileRolesStore, nativeRolesStore, reservedRolesStore, mock(NativePrivilegeStore.class),
|
|
|
- Arrays.asList(inMemoryProvider), new ThreadContext(Settings.EMPTY), xPackLicenseState, cache, mock(ApiKeyService.class));
|
|
|
+ Arrays.asList(inMemoryProvider), new ThreadContext(Settings.EMPTY), xPackLicenseState, cache,
|
|
|
+ mock(ApiKeyService.class), rds -> effectiveRoleDescriptors.set(rds));
|
|
|
// these licenses allow custom role providers
|
|
|
xPackLicenseState.update(randomFrom(OperationMode.PLATINUM, OperationMode.TRIAL), true, null);
|
|
|
roleNames = Sets.newHashSet("roleA");
|
|
|
future = new PlainActionFuture<>();
|
|
|
compositeRolesStore.roles(roleNames, future);
|
|
|
role = future.actionGet();
|
|
|
+ assertThat(effectiveRoleDescriptors.get(), containsInAnyOrder(roleA));
|
|
|
+ effectiveRoleDescriptors.set(null);
|
|
|
|
|
|
// roleA should've been populated by the custom role provider, because the license allows it
|
|
|
assertEquals(1, role.indices().groups().length);
|
|
@@ -688,13 +751,15 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
// license expired, don't allow custom role providers
|
|
|
compositeRolesStore = new CompositeRolesStore(
|
|
|
Settings.EMPTY, fileRolesStore, nativeRolesStore, reservedRolesStore, mock(NativePrivilegeStore.class),
|
|
|
- Arrays.asList(inMemoryProvider), new ThreadContext(Settings.EMPTY), xPackLicenseState, cache, mock(ApiKeyService.class));
|
|
|
+ Arrays.asList(inMemoryProvider), new ThreadContext(Settings.EMPTY), xPackLicenseState, cache,
|
|
|
+ mock(ApiKeyService.class), rds -> effectiveRoleDescriptors.set(rds));
|
|
|
xPackLicenseState.update(randomFrom(OperationMode.PLATINUM, OperationMode.TRIAL), false, null);
|
|
|
roleNames = Sets.newHashSet("roleA");
|
|
|
future = new PlainActionFuture<>();
|
|
|
compositeRolesStore.roles(roleNames, future);
|
|
|
role = future.actionGet();
|
|
|
assertEquals(0, role.indices().groups().length);
|
|
|
+ assertThat(effectiveRoleDescriptors.get().isEmpty(), is(true));
|
|
|
}
|
|
|
|
|
|
private SecurityIndexManager.State dummyState(ClusterHealthStatus indexStatus) {
|
|
@@ -713,7 +778,7 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
CompositeRolesStore compositeRolesStore = new CompositeRolesStore(
|
|
|
Settings.EMPTY, fileRolesStore, nativeRolesStore, reservedRolesStore,
|
|
|
mock(NativePrivilegeStore.class), Collections.emptyList(), new ThreadContext(Settings.EMPTY),
|
|
|
- new XPackLicenseState(SECURITY_ENABLED_SETTINGS), cache, mock(ApiKeyService.class)) {
|
|
|
+ new XPackLicenseState(SECURITY_ENABLED_SETTINGS), cache, mock(ApiKeyService.class), rds -> {}) {
|
|
|
@Override
|
|
|
public void invalidateAll() {
|
|
|
numInvalidation.incrementAndGet();
|
|
@@ -765,7 +830,7 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
CompositeRolesStore compositeRolesStore = new CompositeRolesStore(SECURITY_ENABLED_SETTINGS,
|
|
|
fileRolesStore, nativeRolesStore, reservedRolesStore,
|
|
|
mock(NativePrivilegeStore.class), Collections.emptyList(), new ThreadContext(SECURITY_ENABLED_SETTINGS),
|
|
|
- new XPackLicenseState(SECURITY_ENABLED_SETTINGS), cache, mock(ApiKeyService.class)) {
|
|
|
+ new XPackLicenseState(SECURITY_ENABLED_SETTINGS), cache, mock(ApiKeyService.class), rds -> {}) {
|
|
|
@Override
|
|
|
public void invalidateAll() {
|
|
|
numInvalidation.incrementAndGet();
|
|
@@ -799,10 +864,9 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
final CompositeRolesStore compositeRolesStore =
|
|
|
new CompositeRolesStore(SECURITY_ENABLED_SETTINGS, fileRolesStore, nativeRolesStore, reservedRolesStore,
|
|
|
mock(NativePrivilegeStore.class), Collections.emptyList(), new ThreadContext(SECURITY_ENABLED_SETTINGS),
|
|
|
- new XPackLicenseState(SECURITY_ENABLED_SETTINGS), cache, mock(ApiKeyService.class));
|
|
|
+ new XPackLicenseState(SECURITY_ENABLED_SETTINGS), cache, mock(ApiKeyService.class), rds -> {});
|
|
|
verify(fileRolesStore).addListener(any(Consumer.class)); // adds a listener in ctor
|
|
|
|
|
|
-
|
|
|
PlainActionFuture<Role> rolesFuture = new PlainActionFuture<>();
|
|
|
final User user = new User("no role user");
|
|
|
Authentication auth = new Authentication(user, new RealmRef("name", "type", "node"), null);
|
|
@@ -839,7 +903,7 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
final CompositeRolesStore compositeRolesStore =
|
|
|
new CompositeRolesStore(settings, fileRolesStore, nativeRolesStore, reservedRolesStore,
|
|
|
mock(NativePrivilegeStore.class), Collections.emptyList(), new ThreadContext(settings),
|
|
|
- new XPackLicenseState(settings), cache, mock(ApiKeyService.class));
|
|
|
+ new XPackLicenseState(settings), cache, mock(ApiKeyService.class), rds -> {});
|
|
|
verify(fileRolesStore).addListener(any(Consumer.class)); // adds a listener in ctor
|
|
|
|
|
|
PlainActionFuture<Role> rolesFuture = new PlainActionFuture<>();
|
|
@@ -863,10 +927,12 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
}).when(nativeRolesStore).getRoleDescriptors(isA(Set.class), any(ActionListener.class));
|
|
|
final ReservedRolesStore reservedRolesStore = spy(new ReservedRolesStore());
|
|
|
|
|
|
+ final AtomicReference<Collection<RoleDescriptor>> effectiveRoleDescriptors = new AtomicReference<Collection<RoleDescriptor>>();
|
|
|
final CompositeRolesStore compositeRolesStore =
|
|
|
new CompositeRolesStore(SECURITY_ENABLED_SETTINGS, fileRolesStore, nativeRolesStore, reservedRolesStore,
|
|
|
mock(NativePrivilegeStore.class), Collections.emptyList(), new ThreadContext(SECURITY_ENABLED_SETTINGS),
|
|
|
- new XPackLicenseState(SECURITY_ENABLED_SETTINGS), cache, mock(ApiKeyService.class));
|
|
|
+ new XPackLicenseState(SECURITY_ENABLED_SETTINGS), cache, mock(ApiKeyService.class),
|
|
|
+ rds -> effectiveRoleDescriptors.set(rds));
|
|
|
verify(fileRolesStore).addListener(any(Consumer.class)); // adds a listener in ctor
|
|
|
|
|
|
PlainActionFuture<Role> rolesFuture = new PlainActionFuture<>();
|
|
@@ -874,6 +940,7 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
compositeRolesStore.getRoles(XPackUser.INSTANCE, auth, rolesFuture);
|
|
|
final Role roles = rolesFuture.actionGet();
|
|
|
assertThat(roles, equalTo(XPackUser.ROLE));
|
|
|
+ assertThat(effectiveRoleDescriptors.get(), is(nullValue()));
|
|
|
verifyNoMoreInteractions(fileRolesStore, nativeRolesStore, reservedRolesStore);
|
|
|
}
|
|
|
|
|
@@ -890,13 +957,16 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
}).when(nativeRolesStore).getRoleDescriptors(isA(Set.class), any(ActionListener.class));
|
|
|
final ReservedRolesStore reservedRolesStore = spy(new ReservedRolesStore());
|
|
|
|
|
|
+ final AtomicReference<Collection<RoleDescriptor>> effectiveRoleDescriptors = new AtomicReference<Collection<RoleDescriptor>>();
|
|
|
final CompositeRolesStore compositeRolesStore =
|
|
|
new CompositeRolesStore(SECURITY_ENABLED_SETTINGS, fileRolesStore, nativeRolesStore, reservedRolesStore,
|
|
|
mock(NativePrivilegeStore.class), Collections.emptyList(), new ThreadContext(SECURITY_ENABLED_SETTINGS),
|
|
|
- new XPackLicenseState(SECURITY_ENABLED_SETTINGS), cache, mock(ApiKeyService.class));
|
|
|
+ new XPackLicenseState(SECURITY_ENABLED_SETTINGS), cache, mock(ApiKeyService.class),
|
|
|
+ rds -> effectiveRoleDescriptors.set(rds));
|
|
|
verify(fileRolesStore).addListener(any(Consumer.class)); // adds a listener in ctor
|
|
|
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class,
|
|
|
() -> compositeRolesStore.getRoles(SystemUser.INSTANCE, null, null));
|
|
|
+ assertThat(effectiveRoleDescriptors.get(), is(nullValue()));
|
|
|
assertEquals("the user [_system] is the system user and we should never try to get its roles", iae.getMessage());
|
|
|
}
|
|
|
|
|
@@ -921,10 +991,13 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
listener.onResponse(Collections.emptyList());
|
|
|
return Void.TYPE;
|
|
|
}).when(nativePrivStore).getPrivileges(any(Collection.class), any(Collection.class), any(ActionListener.class));
|
|
|
+
|
|
|
+ final AtomicReference<Collection<RoleDescriptor>> effectiveRoleDescriptors = new AtomicReference<Collection<RoleDescriptor>>();
|
|
|
final CompositeRolesStore compositeRolesStore =
|
|
|
new CompositeRolesStore(SECURITY_ENABLED_SETTINGS, fileRolesStore, nativeRolesStore, reservedRolesStore,
|
|
|
nativePrivStore, Collections.emptyList(), new ThreadContext(SECURITY_ENABLED_SETTINGS),
|
|
|
- new XPackLicenseState(SECURITY_ENABLED_SETTINGS), cache, apiKeyService);
|
|
|
+ new XPackLicenseState(SECURITY_ENABLED_SETTINGS), cache, apiKeyService,
|
|
|
+ rds -> effectiveRoleDescriptors.set(rds));
|
|
|
AuditUtil.getOrGenerateRequestId(threadContext);
|
|
|
final Authentication authentication = new Authentication(new User("test api key user", "superuser"),
|
|
|
new RealmRef("_es_api_key", "_es_api_key", "node"), null, Version.CURRENT, AuthenticationType.API_KEY, Collections.emptyMap());
|
|
@@ -938,7 +1011,7 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
PlainActionFuture<Role> roleFuture = new PlainActionFuture<>();
|
|
|
compositeRolesStore.getRoles(authentication.getUser(), authentication, roleFuture);
|
|
|
roleFuture.actionGet();
|
|
|
-
|
|
|
+ assertThat(effectiveRoleDescriptors.get(), is(nullValue()));
|
|
|
verify(apiKeyService).getRoleForApiKey(eq(authentication), any(ActionListener.class));
|
|
|
}
|
|
|
|
|
@@ -963,10 +1036,13 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
listener.onResponse(Collections.emptyList());
|
|
|
return Void.TYPE;
|
|
|
}).when(nativePrivStore).getPrivileges(any(Collection.class), any(Collection.class), any(ActionListener.class));
|
|
|
+
|
|
|
+ final AtomicReference<Collection<RoleDescriptor>> effectiveRoleDescriptors = new AtomicReference<Collection<RoleDescriptor>>();
|
|
|
final CompositeRolesStore compositeRolesStore =
|
|
|
new CompositeRolesStore(SECURITY_ENABLED_SETTINGS, fileRolesStore, nativeRolesStore, reservedRolesStore,
|
|
|
nativePrivStore, Collections.emptyList(), new ThreadContext(SECURITY_ENABLED_SETTINGS),
|
|
|
- new XPackLicenseState(SECURITY_ENABLED_SETTINGS), cache, apiKeyService);
|
|
|
+ new XPackLicenseState(SECURITY_ENABLED_SETTINGS), cache, apiKeyService,
|
|
|
+ rds -> effectiveRoleDescriptors.set(rds));
|
|
|
AuditUtil.getOrGenerateRequestId(threadContext);
|
|
|
final Authentication authentication = new Authentication(new User("test api key user", "api_key"),
|
|
|
new RealmRef("_es_api_key", "_es_api_key", "node"), null, Version.CURRENT, AuthenticationType.API_KEY, Collections.emptyMap());
|
|
@@ -983,6 +1059,7 @@ public class CompositeRolesStoreTests extends ESTestCase {
|
|
|
compositeRolesStore.getRoles(authentication.getUser(), authentication, roleFuture);
|
|
|
Role role = roleFuture.actionGet();
|
|
|
assertThat(role.checkClusterAction("cluster:admin/foo", Empty.INSTANCE), is(false));
|
|
|
+ assertThat(effectiveRoleDescriptors.get(), is(nullValue()));
|
|
|
verify(apiKeyService).getRoleForApiKey(eq(authentication), any(ActionListener.class));
|
|
|
}
|
|
|
|