-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Enable license feature usage for Security Realms #61963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
731a1f2
Enable license feature usage for Security Realms
tvernum f215cff
Merge branch 'master' into realm-feature-track
tvernum 9086265
Address feedback
tvernum f52ec43
Fix delegated authoriztion
tvernum 5039fbc
Merge branch 'master' into realm-feature-track
elasticmachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.common.util.set.Sets; | ||
| import org.elasticsearch.env.Environment; | ||
| import org.elasticsearch.license.XPackLicenseState; | ||
| import org.elasticsearch.threadpool.ThreadPool; | ||
| import org.elasticsearch.watcher.ResourceWatcherService; | ||
| import org.elasticsearch.xpack.core.security.authc.Realm; | ||
|
|
@@ -52,13 +53,18 @@ | |
| public final class InternalRealms { | ||
|
|
||
| /** | ||
| * The list of all <em>internal</em> realm types, excluding {@link ReservedRealm#TYPE}. | ||
| * The map of all <em>internal</em> realm types, excluding {@link ReservedRealm#TYPE}, to their relevant license feature | ||
| */ | ||
| private static final Set<String> XPACK_TYPES = Collections | ||
| .unmodifiableSet(Sets.newHashSet(NativeRealmSettings.TYPE, FileRealmSettings.TYPE, LdapRealmSettings.AD_TYPE, | ||
| LdapRealmSettings.LDAP_TYPE, PkiRealmSettings.TYPE, SamlRealmSettings.TYPE, KerberosRealmSettings.TYPE, | ||
| OpenIdConnectRealmSettings.TYPE)); | ||
|
|
||
| private static final Map<String, XPackLicenseState.Feature> XPACK_TYPES = Map.ofEntries( | ||
| Map.entry(NativeRealmSettings.TYPE, XPackLicenseState.Feature.SECURITY), | ||
| Map.entry(FileRealmSettings.TYPE, XPackLicenseState.Feature.SECURITY), | ||
| Map.entry(LdapRealmSettings.AD_TYPE, XPackLicenseState.Feature.SECURITY_AD_REALM), | ||
| Map.entry(LdapRealmSettings.LDAP_TYPE, XPackLicenseState.Feature.SECURITY_LDAP_REALM), | ||
| Map.entry(PkiRealmSettings.TYPE, XPackLicenseState.Feature.SECURITY_PKI_REALM), | ||
| Map.entry(SamlRealmSettings.TYPE, XPackLicenseState.Feature.SECURITY_SAML_REALM), | ||
| Map.entry(OpenIdConnectRealmSettings.TYPE, XPackLicenseState.Feature.SECURITY_OIDC_REALM), | ||
| Map.entry(KerberosRealmSettings.TYPE, XPackLicenseState.Feature.SECURITY_KERBEROS_REALM) | ||
| ); | ||
| /** | ||
| * The list of all standard realm types, which are those provided by x-pack and do not have extensive | ||
| * interaction with third party sources | ||
|
|
@@ -71,14 +77,14 @@ public final class InternalRealms { | |
| * including the {@link ReservedRealm} | ||
| */ | ||
| static boolean isXPackRealm(String type) { | ||
| if (XPACK_TYPES.contains(type)) { | ||
| if (XPACK_TYPES.containsKey(type)) { | ||
| return true; | ||
| } | ||
| return ReservedRealm.TYPE.equals(type); | ||
| } | ||
|
|
||
| public static Collection<String> getConfigurableRealmsTypes() { | ||
| return Collections.unmodifiableSet(XPACK_TYPES); | ||
| return XPACK_TYPES.keySet(); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -102,34 +108,34 @@ public static Map<String, Realm.Factory> getFactories(ThreadPool threadPool, Res | |
| SecurityIndexManager securityIndex) { | ||
|
|
||
| return Map.of( | ||
| // file realm | ||
| FileRealmSettings.TYPE, | ||
| config -> new FileRealm(config, resourceWatcherService, threadPool), | ||
| // native realm | ||
| NativeRealmSettings.TYPE, | ||
| config -> { | ||
| final NativeRealm nativeRealm = new NativeRealm(config, nativeUsersStore, threadPool); | ||
| securityIndex.addIndexStateListener(nativeRealm::onSecurityIndexStateChange); | ||
| return nativeRealm; | ||
| }, | ||
| // active directory realm | ||
| LdapRealmSettings.AD_TYPE, | ||
| config -> new LdapRealm(config, sslService, resourceWatcherService, nativeRoleMappingStore, threadPool), | ||
| // LDAP realm | ||
| LdapRealmSettings.LDAP_TYPE, | ||
| config -> new LdapRealm(config, sslService, resourceWatcherService, nativeRoleMappingStore, threadPool), | ||
| // PKI realm | ||
| PkiRealmSettings.TYPE, | ||
| config -> new PkiRealm(config, resourceWatcherService, nativeRoleMappingStore), | ||
| // SAML realm | ||
| SamlRealmSettings.TYPE, | ||
| config -> SamlRealm.create(config, sslService, resourceWatcherService, nativeRoleMappingStore), | ||
| // Kerberos realm | ||
| KerberosRealmSettings.TYPE, | ||
| config -> new KerberosRealm(config, nativeRoleMappingStore, threadPool), | ||
| // OpenID Connect realm | ||
| OpenIdConnectRealmSettings.TYPE, | ||
| config -> new OpenIdConnectRealm(config, sslService, nativeRoleMappingStore, resourceWatcherService)); | ||
| // file realm | ||
| FileRealmSettings.TYPE, | ||
| config -> new FileRealm(config, resourceWatcherService, threadPool), | ||
| // native realm | ||
| NativeRealmSettings.TYPE, | ||
| config -> { | ||
| final NativeRealm nativeRealm = new NativeRealm(config, nativeUsersStore, threadPool); | ||
| securityIndex.addIndexStateListener(nativeRealm::onSecurityIndexStateChange); | ||
| return nativeRealm; | ||
| }, | ||
| // active directory realm | ||
| LdapRealmSettings.AD_TYPE, | ||
| config -> new LdapRealm(config, sslService, resourceWatcherService, nativeRoleMappingStore, threadPool), | ||
| // LDAP realm | ||
| LdapRealmSettings.LDAP_TYPE, | ||
| config -> new LdapRealm(config, sslService, resourceWatcherService, nativeRoleMappingStore, threadPool), | ||
| // PKI realm | ||
| PkiRealmSettings.TYPE, | ||
| config -> new PkiRealm(config, resourceWatcherService, nativeRoleMappingStore), | ||
| // SAML realm | ||
| SamlRealmSettings.TYPE, | ||
| config -> SamlRealm.create(config, sslService, resourceWatcherService, nativeRoleMappingStore), | ||
| // Kerberos realm | ||
| KerberosRealmSettings.TYPE, | ||
| config -> new KerberosRealm(config, nativeRoleMappingStore, threadPool), | ||
| // OpenID Connect realm | ||
| OpenIdConnectRealmSettings.TYPE, | ||
| config -> new OpenIdConnectRealm(config, sslService, nativeRoleMappingStore, resourceWatcherService)); | ||
| } | ||
|
|
||
| private InternalRealms() { | ||
|
|
@@ -146,4 +152,11 @@ public static List<BootstrapCheck> getBootstrapChecks(final Settings globalSetti | |
| .collect(Collectors.toList()); | ||
| return checks; | ||
| } | ||
|
|
||
| public static XPackLicenseState.Feature getLicenseFeature(String type) { | ||
| if (ReservedRealm.TYPE.equals(type)) { | ||
| return XPackLicenseState.Feature.SECURITY; | ||
| } | ||
| return XPACK_TYPES.getOrDefault(type, XPackLicenseState.Feature.SECURITY_CUSTOM_REALM); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: It is a bit weird that a method of "Internal"Realms can check for custom realm type. |
||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than
InternalRealms#getConfigurableRealmsTypes, is there any other reason for this map to not include theReservedRealm? In other places where this map is used, e.g.isXPackRealm, it feels better ifReversedRealmis in it.getConfigurableRealmsTypesseems to be the only exception. It is only used for tests as far as I can tell. Would it be better to removeReservedRealminside this method only instead of not having it in the Map?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably. There's a lot that could be cleaned up here. I tried to keep this PR as self contained as possible and didn't want to change the meaning of
XPACK_TYPESunnecessarily.