|
208 | 208 | import org.elasticsearch.xpack.core.security.authc.RealmConfig;
|
209 | 209 | import org.elasticsearch.xpack.core.security.authc.RealmSettings;
|
210 | 210 | import org.elasticsearch.xpack.core.security.authc.Subject;
|
| 211 | +import org.elasticsearch.xpack.core.security.authc.service.ServiceAccountTokenStore; |
211 | 212 | import org.elasticsearch.xpack.core.security.authc.support.UserRoleMapper;
|
212 | 213 | import org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken;
|
213 | 214 | import org.elasticsearch.xpack.core.security.authz.AuthorizationEngine;
|
|
310 | 311 | import org.elasticsearch.xpack.security.authc.esnative.ReservedRealm;
|
311 | 312 | import org.elasticsearch.xpack.security.authc.jwt.JwtRealm;
|
312 | 313 | import org.elasticsearch.xpack.security.authc.service.CachingServiceAccountTokenStore;
|
| 314 | +import org.elasticsearch.xpack.security.authc.service.CompositeServiceAccountTokenStore; |
313 | 315 | import org.elasticsearch.xpack.security.authc.service.FileServiceAccountTokenStore;
|
314 | 316 | import org.elasticsearch.xpack.security.authc.service.IndexServiceAccountTokenStore;
|
315 | 317 | import org.elasticsearch.xpack.security.authc.service.ServiceAccountService;
|
@@ -915,12 +917,53 @@ Collection<Object> createComponents(
|
915 | 917 | this.realms.set(realms);
|
916 | 918 |
|
917 | 919 | systemIndices.getMainIndexManager().addStateListener(nativeRoleMappingStore::onSecurityIndexStateChange);
|
918 |
| - |
919 | 920 | final CacheInvalidatorRegistry cacheInvalidatorRegistry = new CacheInvalidatorRegistry();
|
920 |
| - cacheInvalidatorRegistry.registerAlias("service", Set.of("file_service_account_token", "index_service_account_token")); |
921 | 921 | components.add(cacheInvalidatorRegistry);
|
922 |
| - systemIndices.getMainIndexManager().addStateListener(cacheInvalidatorRegistry::onSecurityIndexStateChange); |
923 | 922 |
|
| 923 | + final IndexServiceAccountTokenStore indexServiceAccountTokenStore = new IndexServiceAccountTokenStore( |
| 924 | + settings, |
| 925 | + threadPool, |
| 926 | + getClock(), |
| 927 | + client, |
| 928 | + systemIndices.getMainIndexManager(), |
| 929 | + clusterService, |
| 930 | + cacheInvalidatorRegistry |
| 931 | + ); |
| 932 | + components.add(indexServiceAccountTokenStore); |
| 933 | + |
| 934 | + final FileServiceAccountTokenStore fileServiceAccountTokenStore = new FileServiceAccountTokenStore( |
| 935 | + environment, |
| 936 | + resourceWatcherService, |
| 937 | + threadPool, |
| 938 | + clusterService, |
| 939 | + cacheInvalidatorRegistry |
| 940 | + ); |
| 941 | + components.add(fileServiceAccountTokenStore); |
| 942 | + cacheInvalidatorRegistry.registerAlias("service", Set.of("file_service_account_token", "index_service_account_token")); |
| 943 | + |
| 944 | + List<ServiceAccountTokenStore> extensionTokenStores = securityExtensions.stream() |
| 945 | + .map(extension -> extension.getServiceAccountTokenStore(extensionComponents)) |
| 946 | + .toList(); |
| 947 | + |
| 948 | + ServiceAccountService serviceAccountService; |
| 949 | + |
| 950 | + if (extensionTokenStores.isEmpty()) { |
| 951 | + serviceAccountService = new ServiceAccountService(client, fileServiceAccountTokenStore, indexServiceAccountTokenStore); |
| 952 | + } else { |
| 953 | + // Completely handover service account token management to the extension if provided, this will disable the index managed |
| 954 | + // service account tokens managed through the service account token API |
| 955 | + logger.debug("Service account authentication handled by extension, disabling file and index token stores"); |
| 956 | + components.addAll(extensionTokenStores); |
| 957 | + serviceAccountService = new ServiceAccountService( |
| 958 | + client, |
| 959 | + new CompositeServiceAccountTokenStore(extensionTokenStores, client.threadPool().getThreadContext()) |
| 960 | + ); |
| 961 | + // TODO Should this also register with the cacheInvalidatorRegistry? |
| 962 | + } |
| 963 | + |
| 964 | + components.add(serviceAccountService); |
| 965 | + |
| 966 | + systemIndices.getMainIndexManager().addStateListener(cacheInvalidatorRegistry::onSecurityIndexStateChange); |
924 | 967 | final NativePrivilegeStore privilegeStore = new NativePrivilegeStore(
|
925 | 968 | settings,
|
926 | 969 | client,
|
@@ -1004,33 +1047,6 @@ Collection<Object> createComponents(
|
1004 | 1047 | );
|
1005 | 1048 | components.add(apiKeyService);
|
1006 | 1049 |
|
1007 |
| - final IndexServiceAccountTokenStore indexServiceAccountTokenStore = new IndexServiceAccountTokenStore( |
1008 |
| - settings, |
1009 |
| - threadPool, |
1010 |
| - getClock(), |
1011 |
| - client, |
1012 |
| - systemIndices.getMainIndexManager(), |
1013 |
| - clusterService, |
1014 |
| - cacheInvalidatorRegistry |
1015 |
| - ); |
1016 |
| - components.add(indexServiceAccountTokenStore); |
1017 |
| - |
1018 |
| - final FileServiceAccountTokenStore fileServiceAccountTokenStore = new FileServiceAccountTokenStore( |
1019 |
| - environment, |
1020 |
| - resourceWatcherService, |
1021 |
| - threadPool, |
1022 |
| - clusterService, |
1023 |
| - cacheInvalidatorRegistry |
1024 |
| - ); |
1025 |
| - components.add(fileServiceAccountTokenStore); |
1026 |
| - |
1027 |
| - final ServiceAccountService serviceAccountService = new ServiceAccountService( |
1028 |
| - client, |
1029 |
| - fileServiceAccountTokenStore, |
1030 |
| - indexServiceAccountTokenStore |
1031 |
| - ); |
1032 |
| - components.add(serviceAccountService); |
1033 |
| - |
1034 | 1050 | final RoleProviders roleProviders = new RoleProviders(
|
1035 | 1051 | reservedRolesStore,
|
1036 | 1052 | fileRolesStore.get(),
|
|
0 commit comments