42
42
import static org .elasticsearch .packaging .util .FileUtils .append ;
43
43
import static org .elasticsearch .packaging .util .FileUtils .getTempDir ;
44
44
import static org .elasticsearch .packaging .util .FileUtils .rm ;
45
- import static org .elasticsearch .packaging .util .ServerUtils .makeRequest ;
46
45
import static org .hamcrest .Matchers .arrayWithSize ;
47
46
import static org .hamcrest .Matchers .containsString ;
48
47
import static org .hamcrest .Matchers .emptyString ;
@@ -270,38 +269,10 @@ public void test071BindMountCustomPathWithDifferentUID() throws Exception {
270
269
});
271
270
}
272
271
273
- /**
274
- * Check that environment variables can be populated by setting variables with the suffix "_FILE",
275
- * which point to files that hold the required values.
276
- */
277
- public void test080SetEnvironmentVariablesUsingFiles () throws Exception {
278
- final String optionsFilename = "esJavaOpts.txt" ;
279
-
280
- // ES_JAVA_OPTS_FILE
281
- append (tempDir .resolve (optionsFilename ), "-XX:-UseCompressedOops\n " );
282
-
283
- Map <String , String > envVars = singletonMap ("ES_JAVA_OPTS_FILE" , "/run/secrets/" + optionsFilename );
284
-
285
- // File permissions need to be secured in order for the ES wrapper to accept
286
- // them for populating env var values
287
- Files .setPosixFilePermissions (tempDir .resolve (optionsFilename ), p600 );
288
-
289
- final Map <Path , Path > volumes = singletonMap (tempDir , Paths .get ("/run/secrets" ));
290
-
291
- // Restart the container
292
- runContainer (distribution (), volumes , envVars );
293
-
294
- waitForElasticsearch (installation );
295
-
296
- final String nodesResponse = makeRequest (Request .Get ("http://localhost:9200/_nodes" ));
297
-
298
- assertThat (nodesResponse , containsString ("\" using_compressed_ordinary_object_pointers\" :\" false\" " ));
299
- }
300
-
301
272
/**
302
273
* Check that the elastic user's password can be configured via a file and the ELASTIC_PASSWORD_FILE environment variable.
303
274
*/
304
- public void test081ConfigurePasswordThroughEnvironmentVariableFile () throws Exception {
275
+ public void test080ConfigurePasswordThroughEnvironmentVariableFile () throws Exception {
305
276
// Test relies on configuring security
306
277
assumeTrue (distribution .isDefault ());
307
278
@@ -344,7 +315,7 @@ public void test081ConfigurePasswordThroughEnvironmentVariableFile() throws Exce
344
315
* Check that when verifying the file permissions of _FILE environment variables, symlinks
345
316
* are followed.
346
317
*/
347
- public void test082SymlinksAreFollowedWithEnvironmentVariableFiles () throws Exception {
318
+ public void test081SymlinksAreFollowedWithEnvironmentVariableFiles () throws Exception {
348
319
// Test relies on configuring security
349
320
assumeTrue (distribution .isDefault ());
350
321
// Test relies on symlinks
@@ -381,44 +352,42 @@ public void test082SymlinksAreFollowedWithEnvironmentVariableFiles() throws Exce
381
352
/**
382
353
* Check that environment variables cannot be used with _FILE environment variables.
383
354
*/
384
- public void test083CannotUseEnvVarsAndFiles () throws Exception {
385
- final String optionsFilename = "esJavaOpts .txt" ;
355
+ public void test082CannotUseEnvVarsAndFiles () throws Exception {
356
+ final String passwordFilename = "password .txt" ;
386
357
387
- // ES_JAVA_OPTS_FILE
388
- append (tempDir .resolve (optionsFilename ), "-XX:-UseCompressedOops\n " );
358
+ Files .writeString (tempDir .resolve (passwordFilename ), "other_hunter2\n " );
389
359
390
360
Map <String , String > envVars = new HashMap <>();
391
- envVars .put ("ES_JAVA_OPTS " , "-XX:+UseCompressedOops " );
392
- envVars .put ("ES_JAVA_OPTS_FILE " , "/run/secrets/" + optionsFilename );
361
+ envVars .put ("ELASTIC_PASSWORD " , "hunter2 " );
362
+ envVars .put ("ELASTIC_PASSWORD_FILE " , "/run/secrets/" + passwordFilename );
393
363
394
364
// File permissions need to be secured in order for the ES wrapper to accept
395
365
// them for populating env var values
396
- Files .setPosixFilePermissions (tempDir .resolve (optionsFilename ), p600 );
366
+ Files .setPosixFilePermissions (tempDir .resolve (passwordFilename ), p600 );
397
367
398
368
final Map <Path , Path > volumes = singletonMap (tempDir , Paths .get ("/run/secrets" ));
399
369
400
370
final Result dockerLogs = runContainerExpectingFailure (distribution , volumes , envVars );
401
371
402
372
assertThat (
403
373
dockerLogs .stderr ,
404
- containsString ("ERROR: Both ES_JAVA_OPTS_FILE and ES_JAVA_OPTS are set. These are mutually " + " exclusive." )
374
+ containsString ("ERROR: Both ELASTIC_PASSWORD_FILE and ELASTIC_PASSWORD are set. These are mutually exclusive." )
405
375
);
406
376
}
407
377
408
378
/**
409
379
* Check that when populating environment variables by setting variables with the suffix "_FILE",
410
380
* the files' permissions are checked.
411
381
*/
412
- public void test084EnvironmentVariablesUsingFilesHaveCorrectPermissions () throws Exception {
413
- final String optionsFilename = "esJavaOpts .txt" ;
382
+ public void test083EnvironmentVariablesUsingFilesHaveCorrectPermissions () throws Exception {
383
+ final String passwordFilename = "password .txt" ;
414
384
415
- // ES_JAVA_OPTS_FILE
416
- append (tempDir .resolve (optionsFilename ), "-XX:-UseCompressedOops\n " );
385
+ Files .writeString (tempDir .resolve (passwordFilename ), "hunter2\n " );
417
386
418
- Map <String , String > envVars = singletonMap ( "ES_JAVA_OPTS_FILE " , "/run/secrets/" + optionsFilename );
387
+ Map <String , String > envVars = Map . of ( "ELASTIC_PASSWORD_FILE " , "/run/secrets/" + passwordFilename );
419
388
420
389
// Set invalid file permissions
421
- Files .setPosixFilePermissions (tempDir .resolve (optionsFilename ), p660 );
390
+ Files .setPosixFilePermissions (tempDir .resolve (passwordFilename ), p660 );
422
391
423
392
final Map <Path , Path > volumes = singletonMap (tempDir , Paths .get ("/run/secrets" ));
424
393
@@ -428,7 +397,7 @@ public void test084EnvironmentVariablesUsingFilesHaveCorrectPermissions() throws
428
397
assertThat (
429
398
dockerLogs .stderr ,
430
399
containsString (
431
- "ERROR: File /run/secrets/" + optionsFilename + " from ES_JAVA_OPTS_FILE must have " + " file permissions 400 or 600"
400
+ "ERROR: File /run/secrets/" + passwordFilename + " from ELASTIC_PASSWORD_FILE must have file permissions 400 or 600"
432
401
)
433
402
);
434
403
}
@@ -437,7 +406,7 @@ public void test084EnvironmentVariablesUsingFilesHaveCorrectPermissions() throws
437
406
* Check that when verifying the file permissions of _FILE environment variables, symlinks
438
407
* are followed, and that invalid target permissions are detected.
439
408
*/
440
- public void test085SymlinkToFileWithInvalidPermissionsIsRejected () throws Exception {
409
+ public void test084SymlinkToFileWithInvalidPermissionsIsRejected () throws Exception {
441
410
// Test relies on configuring security
442
411
assumeTrue (distribution .isDefault ());
443
412
// Test relies on symlinks
@@ -483,7 +452,7 @@ public void test085SymlinkToFileWithInvalidPermissionsIsRejected() throws Except
483
452
* Check that environment variables are translated to -E options even for commands invoked under
484
453
* `docker exec`, where the Docker image's entrypoint is not executed.
485
454
*/
486
- public void test086EnvironmentVariablesAreRespectedUnderDockerExec () {
455
+ public void test085EnvironmentVariablesAreRespectedUnderDockerExec () {
487
456
// This test relies on a CLI tool attempting to connect to Elasticsearch, and the
488
457
// tool in question is only in the default distribution.
489
458
assumeTrue (distribution .isDefault ());
0 commit comments