68
68
import static org .hamcrest .Matchers .is ;
69
69
import static org .hamcrest .Matchers .not ;
70
70
import static org .hamcrest .Matchers .nullValue ;
71
+ import static org .hamcrest .Matchers .startsWith ;
71
72
import static org .junit .Assume .assumeFalse ;
72
73
import static org .junit .Assume .assumeTrue ;
73
74
@@ -139,7 +140,7 @@ public void test040JavaUsesTheOsProvidedKeystore() {
139
140
/**
140
141
* Checks that there are Amazon trusted certificates in the cacaerts keystore.
141
142
*/
142
- public void test043AmazonCaCertsAreInTheKeystore () {
143
+ public void test041AmazonCaCertsAreInTheKeystore () {
143
144
final boolean matches = Arrays .stream (
144
145
sh .run ("jdk/bin/keytool -cacerts -storepass changeit -list | grep trustedCertEntry" ).stdout .split ("\n " )
145
146
).anyMatch (line -> line .contains ("amazonrootca" ));
@@ -251,8 +252,8 @@ public void test080ConfigurePasswordThroughEnvironmentVariableFile() throws Exce
251
252
waitForElasticsearch ("green" , null , installation , "elastic" , "hunter2" );
252
253
} catch (Exception e ) {
253
254
throw new AssertionError (
254
- "Failed to check whether Elasticsearch had started. This could be because authentication isn't working properly. "
255
- + "Check the container logs" ,
255
+ "Failed to check whether Elasticsearch had started. This could be because "
256
+ + "authentication isn't working properly. Check the container logs" ,
256
257
e
257
258
);
258
259
}
@@ -335,8 +336,7 @@ public void test083EnvironmentVariablesUsingFilesHaveCorrectPermissions() throws
335
336
336
337
Files .write (tempDir .resolve (passwordFilename ), "hunter2\n " .getBytes (StandardCharsets .UTF_8 ));
337
338
338
- Map <String , String > envVars = new HashMap <>();
339
- envVars .put ("ELASTIC_PASSWORD_FILE" , "/run/secrets/" + passwordFilename );
339
+ Map <String , String > envVars = singletonMap ("ELASTIC_PASSWORD_FILE" , "/run/secrets/" + passwordFilename );
340
340
341
341
// Set invalid file permissions
342
342
Files .setPosixFilePermissions (tempDir .resolve (passwordFilename ), p660 );
@@ -484,7 +484,6 @@ public void test101AllFilesAreGroupZero() {
484
484
485
485
/**
486
486
* Check that the Docker image has the expected "Label Schema" labels.
487
- *
488
487
* @see <a href="http://label-schema.org/">Label Schema website</a>
489
488
*/
490
489
public void test110OrgLabelSchemaLabels () throws Exception {
@@ -526,7 +525,6 @@ public void test110OrgLabelSchemaLabels() throws Exception {
526
525
527
526
/**
528
527
* Check that the Docker image has the expected "Open Containers Annotations" labels.
529
- *
530
528
* @see <a href="https://github.com/opencontainers/image-spec/blob/master/annotations.md">Open Containers Annotations</a>
531
529
*/
532
530
public void test110OrgOpencontainersLabels () throws Exception {
@@ -577,10 +575,10 @@ public void test120DockerLogsIncludeElasticsearchLogs() throws Exception {
577
575
}
578
576
579
577
/**
580
- * Check that the Java process running inside the container has the expect PID, UID and username.
578
+ * Check that the Java process running inside the container has the expected UID, GID and username.
581
579
*/
582
- public void test130JavaHasCorrectPidAndOwnership () {
583
- final List <String > processes = Arrays .stream (sh .run ("ps -o pid, uid,user -C java" ).stdout .split ("\n " ))
580
+ public void test130JavaHasCorrectOwnership () {
581
+ final List <String > processes = Arrays .stream (sh .run ("ps -o uid,gid ,user -C java" ).stdout .split ("\n " ))
584
582
.skip (1 )
585
583
.collect (Collectors .toList ());
586
584
@@ -589,11 +587,34 @@ public void test130JavaHasCorrectPidAndOwnership() {
589
587
final String [] fields = processes .get (0 ).trim ().split ("\\ s+" );
590
588
591
589
assertThat (fields , arrayWithSize (3 ));
592
- assertThat ("Incorrect PID " , fields [0 ], equalTo ("1 " ));
593
- assertThat ("Incorrect UID " , fields [1 ], equalTo ("1000 " ));
590
+ assertThat ("Incorrect UID " , fields [0 ], equalTo ("1000 " ));
591
+ assertThat ("Incorrect GID " , fields [1 ], equalTo ("0 " ));
594
592
assertThat ("Incorrect username" , fields [2 ], equalTo ("elasticsearch" ));
595
593
}
596
594
595
+ /**
596
+ * Check that the init process running inside the container has the expected PID, UID, GID and user.
597
+ * The PID is particularly important because PID 1 handles signal forwarding and child reaping.
598
+ */
599
+ public void test131InitProcessHasCorrectPID () {
600
+ final List <String > processes = Arrays .stream (sh .run ("ps -o pid,uid,gid,command -p 1" ).stdout .split ("\n " ))
601
+ .skip (1 )
602
+ .collect (Collectors .toList ());
603
+
604
+ assertThat ("Expected a single process" , processes , hasSize (1 ));
605
+
606
+ final String [] fields = processes .get (0 ).trim ().split ("\\ s+" , 4 );
607
+
608
+ assertThat (fields , arrayWithSize (4 ));
609
+ assertThat ("Incorrect PID" , fields [0 ], equalTo ("1" ));
610
+ assertThat ("Incorrect UID" , fields [1 ], equalTo ("0" ));
611
+ assertThat ("Incorrect GID" , fields [2 ], equalTo ("0" ));
612
+ assertThat ("Incorrect init command" , fields [3 ], startsWith ("/tini" ));
613
+ }
614
+
615
+ /**
616
+ * Check that Elasticsearch reports per-node cgroup information.
617
+ */
597
618
public void test140CgroupOsStatsAreAvailable () throws Exception {
598
619
waitForElasticsearch (installation );
599
620
0 commit comments