56
56
import static org .elasticsearch .packaging .util .FileUtils .append ;
57
57
import static org .elasticsearch .packaging .util .FileUtils .getTempDir ;
58
58
import static org .elasticsearch .packaging .util .FileUtils .rm ;
59
- import static org .elasticsearch .packaging .util .ServerUtils .makeRequest ;
60
59
import static org .hamcrest .Matchers .arrayWithSize ;
61
60
import static org .hamcrest .Matchers .containsString ;
62
61
import static org .hamcrest .Matchers .emptyString ;
@@ -211,38 +210,10 @@ public void test071BindMountCustomPathWithDifferentUID() throws Exception {
211
210
});
212
211
}
213
212
214
- /**
215
- * Check that environment variables can be populated by setting variables with the suffix "_FILE",
216
- * which point to files that hold the required values.
217
- */
218
- public void test080SetEnvironmentVariablesUsingFiles () throws Exception {
219
- final String optionsFilename = "esJavaOpts.txt" ;
220
-
221
- // ES_JAVA_OPTS_FILE
222
- Files .writeString (tempDir .resolve (optionsFilename ), "-XX:-UseCompressedOops\n " );
223
-
224
- Map <String , String > envVars = Map .of ("ES_JAVA_OPTS_FILE" , "/run/secrets/" + optionsFilename );
225
-
226
- // File permissions need to be secured in order for the ES wrapper to accept
227
- // them for populating env var values
228
- Files .setPosixFilePermissions (tempDir .resolve (optionsFilename ), p600 );
229
-
230
- final Map <Path , Path > volumes = Map .of (tempDir , Path .of ("/run/secrets" ));
231
-
232
- // Restart the container
233
- runContainer (distribution (), volumes , envVars );
234
-
235
- waitForElasticsearch (installation );
236
-
237
- final String nodesResponse = makeRequest (Request .Get ("http://localhost:9200/_nodes" ));
238
-
239
- assertThat (nodesResponse , containsString ("\" using_compressed_ordinary_object_pointers\" :\" false\" " ));
240
- }
241
-
242
213
/**
243
214
* Check that the elastic user's password can be configured via a file and the ELASTIC_PASSWORD_FILE environment variable.
244
215
*/
245
- public void test081ConfigurePasswordThroughEnvironmentVariableFile () throws Exception {
216
+ public void test080ConfigurePasswordThroughEnvironmentVariableFile () throws Exception {
246
217
// Test relies on configuring security
247
218
assumeTrue (distribution .isDefault ());
248
219
@@ -289,7 +260,7 @@ public void test081ConfigurePasswordThroughEnvironmentVariableFile() throws Exce
289
260
* Check that when verifying the file permissions of _FILE environment variables, symlinks
290
261
* are followed.
291
262
*/
292
- public void test082SymlinksAreFollowedWithEnvironmentVariableFiles () throws Exception {
263
+ public void test081SymlinksAreFollowedWithEnvironmentVariableFiles () throws Exception {
293
264
// Test relies on configuring security
294
265
assumeTrue (distribution .isDefault ());
295
266
// Test relies on symlinks
@@ -329,47 +300,42 @@ public void test082SymlinksAreFollowedWithEnvironmentVariableFiles() throws Exce
329
300
/**
330
301
* Check that environment variables cannot be used with _FILE environment variables.
331
302
*/
332
- public void test083CannotUseEnvVarsAndFiles () throws Exception {
333
- final String optionsFilename = "esJavaOpts .txt" ;
303
+ public void test082CannotUseEnvVarsAndFiles () throws Exception {
304
+ final String passwordFilename = "password .txt" ;
334
305
335
- // ES_JAVA_OPTS_FILE
336
- Files .writeString (tempDir .resolve (optionsFilename ), "-XX:-UseCompressedOops\n " );
306
+ Files .writeString (tempDir .resolve (passwordFilename ), "other_hunter2\n " );
337
307
338
- Map <String , String > envVars = Map .of (
339
- "ES_JAVA_OPTS" ,
340
- "-XX:+UseCompressedOops" ,
341
- "ES_JAVA_OPTS_FILE" ,
342
- "/run/secrets/" + optionsFilename
343
- );
308
+ Map <String , String > envVars = new HashMap <>();
309
+ envVars .put ("ELASTIC_PASSWORD" , "hunter2" );
310
+ envVars .put ("ELASTIC_PASSWORD_FILE" , "/run/secrets/" + passwordFilename );
344
311
345
312
// File permissions need to be secured in order for the ES wrapper to accept
346
313
// them for populating env var values
347
- Files .setPosixFilePermissions (tempDir .resolve (optionsFilename ), p600 );
314
+ Files .setPosixFilePermissions (tempDir .resolve (passwordFilename ), p600 );
348
315
349
316
final Map <Path , Path > volumes = Map .of (tempDir , Path .of ("/run/secrets" ));
350
317
351
318
final Result dockerLogs = runContainerExpectingFailure (distribution , volumes , envVars );
352
319
353
320
assertThat (
354
321
dockerLogs .stderr ,
355
- containsString ("ERROR: Both ES_JAVA_OPTS_FILE and ES_JAVA_OPTS are set. These are mutually exclusive." )
322
+ containsString ("ERROR: Both ELASTIC_PASSWORD_FILE and ELASTIC_PASSWORD are set. These are mutually exclusive." )
356
323
);
357
324
}
358
325
359
326
/**
360
327
* Check that when populating environment variables by setting variables with the suffix "_FILE",
361
328
* the files' permissions are checked.
362
329
*/
363
- public void test084EnvironmentVariablesUsingFilesHaveCorrectPermissions () throws Exception {
364
- final String optionsFilename = "esJavaOpts .txt" ;
330
+ public void test083EnvironmentVariablesUsingFilesHaveCorrectPermissions () throws Exception {
331
+ final String passwordFilename = "password .txt" ;
365
332
366
- // ES_JAVA_OPTS_FILE
367
- Files .writeString (tempDir .resolve (optionsFilename ), "-XX:-UseCompressedOops\n " );
333
+ Files .writeString (tempDir .resolve (passwordFilename ), "hunter2\n " );
368
334
369
- Map <String , String > envVars = Map .of ("ES_JAVA_OPTS_FILE " , "/run/secrets/" + optionsFilename );
335
+ Map <String , String > envVars = Map .of ("ELASTIC_PASSWORD_FILE " , "/run/secrets/" + passwordFilename );
370
336
371
337
// Set invalid file permissions
372
- Files .setPosixFilePermissions (tempDir .resolve (optionsFilename ), p660 );
338
+ Files .setPosixFilePermissions (tempDir .resolve (passwordFilename ), p660 );
373
339
374
340
final Map <Path , Path > volumes = Map .of (tempDir , Path .of ("/run/secrets" ));
375
341
@@ -378,15 +344,17 @@ public void test084EnvironmentVariablesUsingFilesHaveCorrectPermissions() throws
378
344
379
345
assertThat (
380
346
dockerLogs .stderr ,
381
- containsString ("ERROR: File /run/secrets/" + optionsFilename + " from ES_JAVA_OPTS_FILE must have file permissions 400 or 600" )
347
+ containsString (
348
+ "ERROR: File /run/secrets/" + passwordFilename + " from ELASTIC_PASSWORD_FILE must have file permissions 400 or 600"
349
+ )
382
350
);
383
351
}
384
352
385
353
/**
386
354
* Check that when verifying the file permissions of _FILE environment variables, symlinks
387
355
* are followed, and that invalid target permissions are detected.
388
356
*/
389
- public void test085SymlinkToFileWithInvalidPermissionsIsRejected () throws Exception {
357
+ public void test084SymlinkToFileWithInvalidPermissionsIsRejected () throws Exception {
390
358
// Test relies on configuring security
391
359
assumeTrue (distribution .isDefault ());
392
360
// Test relies on symlinks
@@ -435,7 +403,7 @@ public void test085SymlinkToFileWithInvalidPermissionsIsRejected() throws Except
435
403
* Check that environment variables are translated to -E options even for commands invoked under
436
404
* `docker exec`, where the Docker image's entrypoint is not executed.
437
405
*/
438
- public void test086EnvironmentVariablesAreRespectedUnderDockerExec () {
406
+ public void test085EnvironmentVariablesAreRespectedUnderDockerExec () {
439
407
// This test relies on a CLI tool attempting to connect to Elasticsearch, and the
440
408
// tool in question is only in the default distribution.
441
409
assumeTrue (distribution .isDefault ());
0 commit comments