Recompute active realms when license changes#76592
Conversation
This commit changes the implementation of the Realms class to listen for license changes, and recompute the set of actively licensed realms only when the license changes rather than each time the "asList" method is called. This is primarily a performance optimisation, but it also allows us to turn off the "in use" license tracking for realms when they are disabled by a change in license. Relates: elastic#76476
|
Pinging @elastic/es-security (Team:Security) |
|
|
|
@elasticmachine run elasticsearch-ci/docs |
ywangd
left a comment
There was a problem hiding this comment.
LGTM
This is probably paranoid: What if the call to license update listener fails or crashes? Is it worth to think about how Realms could correctly itself eventually in this edge case?
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/Realms.java
Outdated
Show resolved
Hide resolved
| realms = spy(new TestRealms(Settings.EMPTY, TestEnvironment.newEnvironment(settings), | ||
| Map.of(FileRealmSettings.TYPE, config -> mock(FileRealm.class), NativeRealmSettings.TYPE, config -> mock(NativeRealm.class)), | ||
| licenseState, threadContext, reservedRealm, Arrays.asList(firstRealm, secondRealm), | ||
| Collections.singletonList(firstRealm))); | ||
| Arrays.asList(firstRealm))); | ||
|
|
||
| // Needed because this is calculated in the constructor, which means the override doesn't get called correctly | ||
| realms.recomputeActiveRealms(); | ||
| assertThat(realms.asList(), contains(firstRealm, secondRealm)); |
There was a problem hiding this comment.
This subclass and spy are getting rather complicated than their worth. What prevents us from replacing them with a simple mock?
There was a problem hiding this comment.
Probably nothing, but it wasn't a task I had time to undertake in this round of changes.
x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/Realms.java
Outdated
Show resolved
Hide resolved
x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/RealmsTests.java
Outdated
Show resolved
Hide resolved
| private static boolean isBasicLicensedRealm(String type) { | ||
| return ReservedRealm.TYPE.equals(type) || InternalRealms.isBuiltinRealm(type); | ||
| } |
There was a problem hiding this comment.
This can be a separate PR: It would be great if we could consolidate these predicate methods, e.g. isBuiltinRealm, isStandardRealm and isBasicLicensedRealm, ReservedRealm.TYPE.equals(type). A consistent naming convention is also helpful.
This commit changes the implementation of the Realms class to listen for license changes, and recompute the set of actively licensed realms only when the license changes rather than each time the "asList" method is called. This is primarily a performance optimisation, but it also allows us to turn off the "in use" license tracking for realms when they are disabled by a change in license. Backport of: elastic#76592
This commit changes the implementation of the Realms class to listen for license changes, and recompute the set of actively licensed realms only when the license changes rather than each time the "asList" method is called. This is primarily a performance optimisation, but it also allows us to turn off the "in use" license tracking for realms when they are disabled by a change in license. Backport of: #76592
This commit changes the implementation of the Realms class to listen
for license changes, and recompute the set of actively licensed realms
only when the license changes rather than each time the "asList" method
is called.
This is primarily a performance optimisation, but it also allows us to
turn off the "in use" license tracking for realms when they are
disabled by a change in license.
Relates: #76476