Skip to content

Recompute active realms when license changes#76592

Merged
tvernum merged 3 commits intoelastic:masterfrom
tvernum:realms-listen-license
Aug 17, 2021
Merged

Recompute active realms when license changes#76592
tvernum merged 3 commits intoelastic:masterfrom
tvernum:realms-listen-license

Conversation

@tvernum
Copy link
Copy Markdown
Contributor

@tvernum tvernum commented Aug 17, 2021

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

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
@tvernum tvernum added >non-issue :Security/Authentication Logging in, Usernames/passwords, Realms (Native/LDAP/AD/SAML/PKI/etc) v8.0.0 v7.15.0 labels Aug 17, 2021
@tvernum tvernum requested a review from ywangd August 17, 2021 01:34
@elasticmachine elasticmachine added the Team:Security Meta label for security team label Aug 17, 2021
@elasticmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-security (Team:Security)

@tvernum
Copy link
Copy Markdown
Contributor Author

tvernum commented Aug 17, 2021

> non-issue because the enhancement is covered by #76476

@tvernum
Copy link
Copy Markdown
Contributor Author

tvernum commented Aug 17, 2021

@elasticmachine run elasticsearch-ci/docs

11:39:34 INFO:build_docs:Building docs
11:39:34 INFO:build_docs:Error executing: git archive --format=tar -o /tmp/docsbuild/WTIgbKZC9H/stack-docs/.temp_git_archive.tar master docs/en in GIT_DIR /docs_build/.repos/stack-docs.git
11:39:34 INFO:build_docs:---out---
11:39:34 INFO:build_docs:
11:39:34 INFO:build_docs:---err---
11:39:34 INFO:build_docs:fatal: Not a valid object name
11:39:34 INFO:build_docs:
11:39:34 INFO:build_docs:---

Copy link
Copy Markdown
Member

@ywangd ywangd left a comment

Choose a reason for hiding this comment

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

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?

Comment on lines +233 to +240
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));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This subclass and spy are getting rather complicated than their worth. What prevents us from replacing them with a simple mock?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Probably nothing, but it wasn't a task I had time to undertake in this round of changes.

Comment on lines +164 to +166
private static boolean isBasicLicensedRealm(String type) {
return ReservedRealm.TYPE.equals(type) || InternalRealms.isBuiltinRealm(type);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@tvernum tvernum merged commit c1a3244 into elastic:master Aug 17, 2021
tvernum added a commit to tvernum/elasticsearch that referenced this pull request Aug 17, 2021
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
tvernum added a commit that referenced this pull request Aug 18, 2021
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>non-issue :Security/Authentication Logging in, Usernames/passwords, Realms (Native/LDAP/AD/SAML/PKI/etc) Team:Security Meta label for security team v7.15.0 v8.0.0-alpha2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants