Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
65cf24c
WIP: making realm order config mandatory
ywangd Jan 17, 2020
d186b0a
Support explicit order parameter for RealmConfig
ywangd Jan 19, 2020
82e08d2
Fix security plugin tests for required order param
ywangd Jan 19, 2020
71bfb3e
Fix more tests for required order param
ywangd Jan 19, 2020
5370163
Fix ci/2 failures
ywangd Jan 19, 2020
1132f5f
Merge branch 'master' into issue-37614-realm-order
elasticmachine Jan 19, 2020
7fa20a3
Fix more require order parameter failure
ywangd Jan 19, 2020
3d724e8
Enforce no same order for realms.
ywangd Jan 20, 2020
adca1bf
Fix duplicate order for tests
ywangd Jan 20, 2020
0f60b22
Add realm order to breaking change doc
ywangd Jan 20, 2020
3cb7a83
Start updating docs for realm order
ywangd Jan 20, 2020
22399ce
Add missing order config in docs
ywangd Jan 21, 2020
0edef24
Merge branch 'master' into issue-37614-realm-order
elasticmachine Jan 21, 2020
b439a49
Update docs/reference/migration/migrate_8_0/security.asciidoc
ywangd Jan 21, 2020
9548e2f
Merge branch 'master' into issue-37614-realm-order
elasticmachine Jan 21, 2020
a74482e
Update for docs feedback
ywangd Jan 21, 2020
e0aa65b
Update doc to address feedback
ywangd Jan 22, 2020
994c0af
More wording changes based on feedback
ywangd Jan 22, 2020
da8e7e3
Address feedback for docs
ywangd Jan 24, 2020
7fbf061
Address feedback to revert accident change
ywangd Jan 24, 2020
472b2d6
Merge remote-tracking branch 'origin/master' into issue-37614-realm-o…
ywangd Jan 24, 2020
64d0292
Update based on discussion with Tim.
ywangd Jan 24, 2020
aad6d19
Address feedback for consistent err msg
ywangd Jan 24, 2020
84cb684
Update x-pack/docs/en/security/authentication/custom-realm.asciidoc
ywangd Jan 27, 2020
4c61828
Update x-pack/docs/en/security/authentication/realm-chains.asciidoc
ywangd Jan 27, 2020
c264e31
Address feedback for docs
ywangd Jan 27, 2020
43fffa3
Merge remote-tracking branch 'origin/master' into issue-37614-realm-o…
ywangd Jan 27, 2020
0614cbc
Update docs/reference/migration/migrate_8_0/security.asciidoc
ywangd Jan 28, 2020
fe13c71
Update x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/s…
ywangd Jan 28, 2020
ad7a1b5
Merge remote-tracking branch 'origin/master' into issue-37614-realm-o…
ywangd Jan 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,24 @@ public class RealmConfig {
private final ThreadContext threadContext;

public RealmConfig(RealmIdentifier identifier, Settings settings, Environment env, ThreadContext threadContext) {
this(identifier, settings, env, threadContext, null);
}

public RealmConfig(RealmIdentifier identifier, Settings settings, Environment env, ThreadContext threadContext, Integer order) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better for this constructor to be protected, and update the tests to pass through real Settings object with an order config.

I know that's going to be a pain - so please feel free to convince me if you feel otherwise.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you suggesting the caller should create a Settings object that actually includes an order? In this case, this constructor is no longer necessary? Am I getting this right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially actual prefer to not adding another constructor. But the number of call site changes made me change my mind. But I am happy to drop the constructor and make more call site changes if you favour this approach. Please let me know. Thanks

this.identifier = identifier;
this.settings = settings;
this.env = env;
this.enabled = getSetting(RealmSettings.ENABLED_SETTING);
this.order = getSetting(RealmSettings.ORDER_SETTING);
if (order != null) {
this.order = order;
} else if (order == null && hasSetting(RealmSettings.ORDER_SETTING.apply(type())) == false) {
throw new IllegalArgumentException("'order' is a mandatory parameter for realm config. " +
"Found invalid realm config: '" + identifier.name + "'\n" +
"Please see the breaking changes documentation."
);
} else {
this.order = getSetting(RealmSettings.ORDER_SETTING);
}
this.threadContext = threadContext;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,13 @@ private void addNativeRealms(List<Realm> realms) throws Exception {
if (fileRealm != null) {
realms.add(fileRealm.create(new RealmConfig(
new RealmConfig.RealmIdentifier(FileRealmSettings.TYPE, "default_" + FileRealmSettings.TYPE),
settings, env, threadContext)));
settings, env, threadContext, Integer.MIN_VALUE)));
}
Realm.Factory indexRealmFactory = factories.get(NativeRealmSettings.TYPE);
if (indexRealmFactory != null) {
realms.add(indexRealmFactory.create(new RealmConfig(
new RealmConfig.RealmIdentifier(NativeRealmSettings.TYPE, "default_" + NativeRealmSettings.TYPE),
settings, env, threadContext)));
settings, env, threadContext, Integer.MIN_VALUE)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public class ReservedRealm extends CachingUsernamePasswordRealm {

public ReservedRealm(Environment env, Settings settings, NativeUsersStore nativeUsersStore, AnonymousUser anonymousUser,
SecurityIndexManager securityIndex, ThreadPool threadPool) {
super(new RealmConfig(new RealmConfig.RealmIdentifier(TYPE, TYPE), settings, env, threadPool.getThreadContext()), threadPool);
super(new RealmConfig(new RealmConfig.RealmIdentifier(TYPE, TYPE), settings, env, threadPool.getThreadContext(),
Integer.MIN_VALUE), threadPool);
this.nativeUsersStore = nativeUsersStore;
this.realmEnabled = XPackSettings.RESERVED_REALM_ENABLED_SETTING.get(settings);
this.anonymousUser = anonymousUser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void setup() throws Exception {

final RealmConfig.RealmIdentifier realmIdentifier = new RealmConfig.RealmIdentifier("oidc", REALM_NAME);

final RealmConfig realmConfig = new RealmConfig(realmIdentifier, settings, env, threadContext);
final RealmConfig realmConfig = new RealmConfig(realmIdentifier, settings, env, threadContext, Integer.MAX_VALUE);
oidcRealm = new OpenIdConnectRealm(realmConfig, new SSLService(TestEnvironment.newEnvironment(sslSettings)),
mock(UserRoleMapper.class), mock(ResourceWatcherService.class));
when(realms.realm(realmConfig.name())).thenReturn(oidcRealm);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ void doExecute(ActionType<Response> action, Request request, ActionListener<Resp
final RealmConfig realmConfig = new RealmConfig(
realmId,
settings,
env, threadContext);
env, threadContext, Integer.MAX_VALUE);
samlRealm = SamlRealmTestHelper.buildRealm(realmConfig, null);
when(realms.realm(realmConfig.name())).thenReturn(samlRealm);
when(realms.stream()).thenAnswer(i -> Stream.of(samlRealm));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public void setup() throws Exception {

final RealmIdentifier realmIdentifier = new RealmIdentifier("saml", REALM_NAME);

final RealmConfig realmConfig = new RealmConfig(realmIdentifier, settings, env, threadContext);
final RealmConfig realmConfig = new RealmConfig(realmIdentifier, settings, env, threadContext, Integer.MAX_VALUE);
samlRealm = SamlRealm.create(realmConfig, mock(SSLService.class), mock(ResourceWatcherService.class), mock(UserRoleMapper.class));
when(realms.realm(realmConfig.name())).thenReturn(samlRealm);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public void testNativeRealmRegistersIndexHealthChangeListener() throws Exception
final RealmConfig.RealmIdentifier realmId = new RealmConfig.RealmIdentifier(NativeRealmSettings.TYPE, "test");
final Environment env = TestEnvironment.newEnvironment(settings);
final ThreadContext threadContext = new ThreadContext(settings);
factories.get(NativeRealmSettings.TYPE).create(new RealmConfig(realmId, settings, env, threadContext));
factories.get(NativeRealmSettings.TYPE).create(new RealmConfig(realmId, settings, env, threadContext, Integer.MAX_VALUE));
verify(securityIndex).addIndexStateListener(isA(BiConsumer.class));

factories.get(NativeRealmSettings.TYPE).create(new RealmConfig(realmId, settings, env, threadContext));
factories.get(NativeRealmSettings.TYPE).create(new RealmConfig(realmId, settings, env, threadContext, Integer.MAX_VALUE));
verify(securityIndex, times(2)).addIndexStateListener(isA(BiConsumer.class));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.xpack.core.security.authc.RealmConfig;
import org.elasticsearch.xpack.core.security.authc.RealmSettings;
import org.elasticsearch.xpack.core.security.index.RestrictedIndicesNames;
import org.elasticsearch.xpack.security.support.SecurityIndexManager;

Expand All @@ -38,8 +39,9 @@ public void testCacheClearOnIndexHealthChange() {
when(threadPool.getThreadContext()).thenReturn(threadContext);
final AtomicInteger numInvalidation = new AtomicInteger(0);
int expectedInvalidation = 0;
Settings settings = Settings.builder().put("path.home", createTempDir()).build();
RealmConfig.RealmIdentifier realmId = new RealmConfig.RealmIdentifier("native", "native");
Settings settings = Settings.builder().put("path.home", createTempDir())
.put(RealmSettings.realmSettingPrefix(realmId) + "order", 0).build();
RealmConfig config = new RealmConfig(realmId, settings, TestEnvironment.newEnvironment(settings), new ThreadContext(settings));
final NativeRealm nativeRealm = new NativeRealm(config, mock(NativeUsersStore.class), threadPool) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public void init() throws Exception {
userPasswdStore = mock(FileUserPasswdStore.class);
userRolesStore = mock(FileUserRolesStore.class);
globalSettings = Settings.builder().put("path.home", createTempDir()).put("xpack.security.authc.password_hashing.algorithm",
randomFrom("bcrypt9", "pbkdf2")).build();
randomFrom("bcrypt9", "pbkdf2")).
put(RealmSettings.realmSettingPrefix(REALM_IDENTIFIER) + "order", 0).build();
threadPool = mock(ThreadPool.class);
threadContext = new ThreadContext(globalSettings);
when(threadPool.getThreadContext()).thenReturn(threadContext);
Expand Down Expand Up @@ -243,8 +244,8 @@ public void testUsageStats() throws Exception {

final int order = randomIntBetween(0, 10);
Settings settings = Settings.builder()
.put(RealmSettings.realmSettingPrefix(REALM_IDENTIFIER) + "order", order)
.put(globalSettings)
.put(RealmSettings.realmSettingPrefix(REALM_IDENTIFIER) + "order", order)
.build();

RealmConfig config = getRealmConfig(settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void testStore_AutoReload() throws Exception {

private RealmConfig getRealmConfig() {
final RealmConfig.RealmIdentifier identifier = new RealmConfig.RealmIdentifier("file", "file-test");
return new RealmConfig(identifier, settings, env, threadPool.getThreadContext());
return new RealmConfig(identifier, settings, env, threadPool.getThreadContext(), Integer.MAX_VALUE);
}

public void testStore_AutoReload_WithParseFailures() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void testStore_ConfiguredWithUnreadableFile() throws Exception {
Files.write(file, lines, StandardCharsets.UTF_16);

RealmConfig.RealmIdentifier realmId = new RealmConfig.RealmIdentifier("file", "file-test");
RealmConfig config = new RealmConfig(realmId, settings, env, new ThreadContext(Settings.EMPTY));
RealmConfig config = new RealmConfig(realmId, settings, env, new ThreadContext(Settings.EMPTY), Integer.MAX_VALUE);
ResourceWatcherService watcherService = new ResourceWatcherService(settings, threadPool);
FileUserRolesStore store = new FileUserRolesStore(config, watcherService);
assertThat(store.entriesCount(), is(0));
Expand All @@ -88,7 +88,7 @@ public void testStoreAutoReload() throws Exception {


final RealmConfig.RealmIdentifier realmId = new RealmConfig.RealmIdentifier("file", "file-test");
RealmConfig config = new RealmConfig(realmId, settings, env, new ThreadContext(Settings.EMPTY));
RealmConfig config = new RealmConfig(realmId, settings, env, new ThreadContext(Settings.EMPTY), Integer.MAX_VALUE);
ResourceWatcherService watcherService = new ResourceWatcherService(settings, threadPool);
final CountDownLatch latch = new CountDownLatch(1);

Expand Down Expand Up @@ -134,7 +134,7 @@ public void testStoreAutoReloadWithParseFailure() throws Exception {
Files.copy(users, tmp, StandardCopyOption.REPLACE_EXISTING);

final RealmConfig.RealmIdentifier realmId = new RealmConfig.RealmIdentifier("file", "file-test");
RealmConfig config = new RealmConfig(realmId, settings, env, new ThreadContext(Settings.EMPTY));
RealmConfig config = new RealmConfig(realmId, settings, env, new ThreadContext(Settings.EMPTY), Integer.MAX_VALUE);
ResourceWatcherService watcherService = new ResourceWatcherService(settings, threadPool);
final CountDownLatch latch = new CountDownLatch(1);

Expand Down Expand Up @@ -224,7 +224,7 @@ public void testParseFileEmptyRolesDoesNotCauseNPE() throws Exception {

Environment env = TestEnvironment.newEnvironment(settings);
final RealmConfig.RealmIdentifier realmId = new RealmConfig.RealmIdentifier("file", "file-test");
RealmConfig config = new RealmConfig(realmId, settings, env, new ThreadContext(Settings.EMPTY));
RealmConfig config = new RealmConfig(realmId, settings, env, new ThreadContext(Settings.EMPTY), Integer.MAX_VALUE);
ResourceWatcherService watcherService = new ResourceWatcherService(settings, threadPool);
FileUserRolesStore store = new FileUserRolesStore(config, watcherService);
assertThat(store.roles("user"), equalTo(Strings.EMPTY_ARRAY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public void testAuthenticateDifferentFailureScenarios() throws LoginException, G
public void testDelegatedAuthorizationFailedToResolve() throws Exception {
final String username = randomPrincipalName();
final MockLookupRealm otherRealm = new MockLookupRealm(new RealmConfig(new RealmConfig.RealmIdentifier("mock", "other_realm"),
globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings)));
globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings), Integer.MAX_VALUE));
final User lookupUser = new User(randomAlphaOfLength(5));
otherRealm.registerUser(lookupUser);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void testKerberosRealmSettings() throws IOException {
keytabPathConfig, maxUsers, cacheTTL, enableDebugLogs, removeRealmName);
final RealmIdentifier identifier = new RealmIdentifier(KerberosRealmSettings.TYPE, KerberosRealmTestCase.REALM_NAME);
final RealmConfig config = new RealmConfig(identifier,
settings, TestEnvironment.newEnvironment(settings), new ThreadContext(settings));
settings, TestEnvironment.newEnvironment(settings), new ThreadContext(settings), Integer.MAX_VALUE);

assertThat(config.getSetting(KerberosRealmSettings.HTTP_SERVICE_KEYTAB_PATH), equalTo(keytabPathConfig));
assertThat(config.getSetting(KerberosRealmSettings.CACHE_TTL_SETTING),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected KerberosRealm createKerberosRealm(final String... userForRoleMapping)
protected KerberosRealm createKerberosRealm(final List<Realm> delegatedRealms, final String... userForRoleMapping) {
final RealmConfig.RealmIdentifier id = new RealmConfig.RealmIdentifier(KerberosRealmSettings.TYPE, REALM_NAME);
config = new RealmConfig(id, merge(id, settings, globalSettings),
TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings));
TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings), Integer.MAX_VALUE);
mockNativeRoleMappingStore = roleMappingStore(Arrays.asList(userForRoleMapping));
mockKerberosTicketValidator = mock(KerberosTicketValidator.class);
final KerberosRealm kerberosRealm =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ private void assertKerberosRealmConstructorFails(final String keytabPath, final
final String realmName = "test-kerb-realm";
settings = buildKerberosRealmSettings(realmName, keytabPath, 100, "10m", true, randomBoolean(), globalSettings);
config = new RealmConfig(new RealmConfig.RealmIdentifier(KerberosRealmSettings.TYPE, realmName), settings,
TestEnvironment.newEnvironment(settings), new ThreadContext(settings));
TestEnvironment.newEnvironment(settings), new ThreadContext(settings), Integer.MAX_VALUE);
mockNativeRoleMappingStore = roleMappingStore(Arrays.asList("user"));
mockKerberosTicketValidator = mock(KerberosTicketValidator.class);
final IllegalArgumentException iae = expectThrows(IllegalArgumentException.class,
Expand All @@ -175,7 +175,7 @@ public void testDelegatedAuthorization() throws Exception {
final String username = randomPrincipalName();
final String expectedUsername = maybeRemoveRealmName(username);
final MockLookupRealm otherRealm = spy(new MockLookupRealm(new RealmConfig(new RealmConfig.RealmIdentifier("mock", "other_realm"),
globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings))));
globalSettings, TestEnvironment.newEnvironment(globalSettings), new ThreadContext(globalSettings), Integer.MAX_VALUE)));
final User lookupUser = new User(expectedUsername, new String[] { "admin-role" }, expectedUsername,
expectedUsername + "@example.com", Collections.singletonMap("k1", "v1"), true);
otherRealm.registerUser(lookupUser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ private RealmConfig setupRealm(RealmConfig.RealmIdentifier realmIdentifier, Sett
return new RealmConfig(
realmIdentifier,
mergedSettings,
env, new ThreadContext(mergedSettings)
env, new ThreadContext(mergedSettings),
Integer.MAX_VALUE
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ protected static RealmConfig config(RealmConfig.RealmIdentifier realmId, Setting
if (settings.hasValue("path.home") == false) {
settings = Settings.builder().put(settings).put("path.home", createTempDir()).build();
}
return new RealmConfig(realmId, settings, TestEnvironment.newEnvironment(settings), new ThreadContext(Settings.EMPTY));
return new RealmConfig(realmId, settings, TestEnvironment.newEnvironment(settings), new ThreadContext(Settings.EMPTY),
Integer.MAX_VALUE);
}

protected abstract String ldapUrl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void testAuthenticateSubTreeGroupSearch() throws Exception {

private RealmConfig getRealmConfig(RealmConfig.RealmIdentifier identifier, Settings settings) {
final Environment env = TestEnvironment.newEnvironment(settings);
return new RealmConfig(identifier, settings, env, new ThreadContext(settings));
return new RealmConfig(identifier, settings, env, new ThreadContext(settings), Integer.MAX_VALUE);
}

public void testAuthenticateOneLevelGroupSearch() throws Exception {
Expand Down Expand Up @@ -271,14 +271,14 @@ public void testDelegatedAuthorization() throws Exception {

final Settings realmSettings = builder.build();
final Environment env = TestEnvironment.newEnvironment(defaultGlobalSettings);
RealmConfig config = new RealmConfig(REALM_IDENTIFIER, realmSettings, env, threadPool.getThreadContext());
RealmConfig config = new RealmConfig(REALM_IDENTIFIER, realmSettings, env, threadPool.getThreadContext(), Integer.MAX_VALUE);

final LdapSessionFactory ldapFactory = new LdapSessionFactory(config, sslService, threadPool);
final DnRoleMapper roleMapper = buildGroupAsRoleMapper(resourceWatcherService);
final LdapRealm ldap = new LdapRealm(config, ldapFactory, roleMapper, threadPool);

final MockLookupRealm mockLookup = new MockLookupRealm(new RealmConfig(new RealmConfig.RealmIdentifier("mock", "mock_lookup"),
defaultGlobalSettings, env, threadPool.getThreadContext()));
defaultGlobalSettings, env, threadPool.getThreadContext(), Integer.MAX_VALUE));

ldap.initialize(Arrays.asList(ldap, mockLookup), licenseState);
mockLookup.initialize(Arrays.asList(ldap, mockLookup), licenseState);
Expand Down
Loading