|
37 | 37 | import org.elasticsearch.test.http.MockWebServer;
|
38 | 38 | import org.elasticsearch.threadpool.TestThreadPool;
|
39 | 39 | import org.elasticsearch.threadpool.ThreadPool;
|
| 40 | +import org.elasticsearch.watcher.FileWatcher; |
| 41 | +import org.elasticsearch.watcher.ResourceWatcher; |
40 | 42 | import org.elasticsearch.watcher.ResourceWatcherService;
|
41 | 43 | import org.junit.After;
|
42 | 44 | import org.junit.Before;
|
|
66 | 68 | import java.security.cert.CertificateException;
|
67 | 69 | import java.util.Collection;
|
68 | 70 | import java.util.Collections;
|
| 71 | +import java.util.HashSet; |
69 | 72 | import java.util.List;
|
| 73 | +import java.util.Set; |
70 | 74 | import java.util.concurrent.CountDownLatch;
|
71 | 75 | import java.util.concurrent.CyclicBarrier;
|
72 | 76 | import java.util.concurrent.TimeUnit;
|
|
79 | 83 | import javax.net.ssl.SSLSocket;
|
80 | 84 |
|
81 | 85 | import static org.elasticsearch.test.TestMatchers.throwableWithMessage;
|
| 86 | +import static org.hamcrest.Matchers.containsInAnyOrder; |
82 | 87 | import static org.hamcrest.Matchers.containsString;
|
83 | 88 | import static org.hamcrest.Matchers.sameInstance;
|
84 | 89 |
|
@@ -559,6 +564,38 @@ public void testFailureToReadFileDoesntFail() throws Exception {
|
559 | 564 | }
|
560 | 565 | }
|
561 | 566 |
|
| 567 | + /** |
| 568 | + * Due to exclusive access entitlements |
| 569 | + * (see {@link org.elasticsearch.entitlement.runtime.policy.entitlements.FilesEntitlement.FileData#exclusive}), |
| 570 | + * it is not safe to monitor a directory or any files that are not an explicit part of this SSL configuration. |
| 571 | + */ |
| 572 | + public void testReloaderOnlyWatchesSpecifiedFiles() throws Exception { |
| 573 | + final Set<Path> watchedPaths = new HashSet<>(); |
| 574 | + final ResourceWatcherService mockResourceWatcher = Mockito.mock(ResourceWatcherService.class); |
| 575 | + Mockito.when(mockResourceWatcher.add(Mockito.any(ResourceWatcher.class), Mockito.any(ResourceWatcherService.Frequency.class))) |
| 576 | + .then(inv -> { |
| 577 | + final FileWatcher fileWatcher = asInstanceOf(FileWatcher.class, inv.getArguments()[0]); |
| 578 | + watchedPaths.add(fileWatcher.getPath()); |
| 579 | + return null; |
| 580 | + }); |
| 581 | + |
| 582 | + final Path tempDir = createTempDir(); |
| 583 | + final Path clientCertPath = tempDir.resolve("testclient.crt"); |
| 584 | + Settings settings = baseKeystoreSettings(tempDir, null).putList( |
| 585 | + "xpack.security.transport.ssl.certificate_authorities", |
| 586 | + clientCertPath.toString() |
| 587 | + ).put("path.home", createTempDir()).build(); |
| 588 | + |
| 589 | + final Environment env = newEnvironment(settings); |
| 590 | + final Collection<SslConfiguration> configurations = SSLService.getSSLConfigurations(env).values(); |
| 591 | + new SSLConfigurationReloader(ignore -> {}, mockResourceWatcher, configurations); |
| 592 | + |
| 593 | + assertThat( |
| 594 | + watchedPaths, |
| 595 | + containsInAnyOrder(tempDir.resolve("testclient.pem"), tempDir.resolve("testclient.crt"), tempDir.resolve("testclientcert.crt")) |
| 596 | + ); |
| 597 | + } |
| 598 | + |
562 | 599 | private Settings.Builder baseKeystoreSettings(Path tempDir, MockSecureSettings secureSettings) throws IOException {
|
563 | 600 | final Path keyPath = tempDir.resolve("testclient.pem");
|
564 | 601 | final Path certPath = tempDir.resolve("testclientcert.crt"); // testclient.crt filename already used in #testPEMTrustReloadException
|
|
0 commit comments