Skip to content

Commit a703a7e

Browse files
committed
Watch SSL files instead of directories
With the introduction of entitlements (#120243) and exclusive file access (#123087) it is no longer safe to watch a whole directory. In a lot of deployments, the parent directory for SSL config files will be the main config directory, which also contains exclusive files such as SAML realm metadata or File realm users. Watching that directory will cause entitlement warnings because it is not permissible for core/ssl-config to read files that are exclusively owned by the security module (or other modules)
1 parent 4ce06d1 commit a703a7e

File tree

1 file changed

+4
-17
lines changed

1 file changed

+4
-17
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ssl/SSLConfigurationReloader.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@
2222
import java.util.ArrayList;
2323
import java.util.Collection;
2424
import java.util.HashMap;
25-
import java.util.HashSet;
2625
import java.util.List;
2726
import java.util.Map;
28-
import java.util.Set;
2927
import java.util.concurrent.ExecutionException;
3028
import java.util.concurrent.Future;
3129
import java.util.function.Consumer;
@@ -80,7 +78,7 @@ private static Consumer<SslConfiguration> reloadConsumer(Future<SSLService> futu
8078
}
8179

8280
/**
83-
* Collects all of the directories that need to be monitored for the provided {@link SslConfiguration} instances and ensures that
81+
* Collects all of the files that need to be monitored for the provided {@link SslConfiguration} instances and ensures that
8482
* they are being watched for changes
8583
*/
8684
private static void startWatching(
@@ -91,8 +89,8 @@ private static void startWatching(
9189
Map<Path, List<SslConfiguration>> pathToConfigurationsMap = new HashMap<>();
9290
for (SslConfiguration sslConfiguration : sslConfigurations) {
9391
final Collection<Path> filesToMonitor = sslConfiguration.getDependentFiles();
94-
for (Path directory : directoriesToMonitor(filesToMonitor)) {
95-
pathToConfigurationsMap.compute(directory, (path, list) -> {
92+
for (Path file : filesToMonitor) {
93+
pathToConfigurationsMap.compute(file, (path, list) -> {
9694
if (list == null) {
9795
list = new ArrayList<>();
9896
}
@@ -109,22 +107,11 @@ private static void startWatching(
109107
try {
110108
resourceWatcherService.add(fileWatcher, Frequency.HIGH);
111109
} catch (IOException | SecurityException e) {
112-
logger.error("failed to start watching directory [{}] for ssl configurations [{}] - {}", path, configurations, e);
110+
logger.error("failed to start watching file [{}] for ssl configurations [{}] - {}", path, configurations, e);
113111
}
114112
});
115113
}
116114

117-
/**
118-
* Returns a unique set of directories that need to be monitored based on the provided file paths
119-
*/
120-
private static Set<Path> directoriesToMonitor(Iterable<Path> filePaths) {
121-
Set<Path> paths = new HashSet<>();
122-
for (Path path : filePaths) {
123-
paths.add(path.getParent());
124-
}
125-
return paths;
126-
}
127-
128115
private static class ChangeListener implements FileChangesListener {
129116

130117
private final List<SslConfiguration> sslConfigurations;

0 commit comments

Comments
 (0)