6868import static org .hamcrest .Matchers .is ;
6969import static org .hamcrest .Matchers .not ;
7070import static org .hamcrest .Matchers .nullValue ;
71+ import static org .hamcrest .Matchers .startsWith ;
7172import static org .junit .Assume .assumeFalse ;
7273import static org .junit .Assume .assumeTrue ;
7374
@@ -139,7 +140,7 @@ public void test040JavaUsesTheOsProvidedKeystore() {
139140 /**
140141 * Checks that there are Amazon trusted certificates in the cacaerts keystore.
141142 */
142- public void test043AmazonCaCertsAreInTheKeystore () {
143+ public void test041AmazonCaCertsAreInTheKeystore () {
143144 final boolean matches = Arrays .stream (
144145 sh .run ("jdk/bin/keytool -cacerts -storepass changeit -list | grep trustedCertEntry" ).stdout .split ("\n " )
145146 ).anyMatch (line -> line .contains ("amazonrootca" ));
@@ -251,8 +252,8 @@ public void test080ConfigurePasswordThroughEnvironmentVariableFile() throws Exce
251252 waitForElasticsearch ("green" , null , installation , "elastic" , "hunter2" );
252253 } catch (Exception e ) {
253254 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" ,
256257 e
257258 );
258259 }
@@ -335,8 +336,7 @@ public void test083EnvironmentVariablesUsingFilesHaveCorrectPermissions() throws
335336
336337 Files .write (tempDir .resolve (passwordFilename ), "hunter2\n " .getBytes (StandardCharsets .UTF_8 ));
337338
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 );
340340
341341 // Set invalid file permissions
342342 Files .setPosixFilePermissions (tempDir .resolve (passwordFilename ), p660 );
@@ -484,7 +484,6 @@ public void test101AllFilesAreGroupZero() {
484484
485485 /**
486486 * Check that the Docker image has the expected "Label Schema" labels.
487- *
488487 * @see <a href="http://label-schema.org/">Label Schema website</a>
489488 */
490489 public void test110OrgLabelSchemaLabels () throws Exception {
@@ -526,7 +525,6 @@ public void test110OrgLabelSchemaLabels() throws Exception {
526525
527526 /**
528527 * Check that the Docker image has the expected "Open Containers Annotations" labels.
529- *
530528 * @see <a href="https://github.com/opencontainers/image-spec/blob/master/annotations.md">Open Containers Annotations</a>
531529 */
532530 public void test110OrgOpencontainersLabels () throws Exception {
@@ -577,10 +575,10 @@ public void test120DockerLogsIncludeElasticsearchLogs() throws Exception {
577575 }
578576
579577 /**
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.
581579 */
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 " ))
584582 .skip (1 )
585583 .collect (Collectors .toList ());
586584
@@ -589,11 +587,34 @@ public void test130JavaHasCorrectPidAndOwnership() {
589587 final String [] fields = processes .get (0 ).trim ().split ("\\ s+" );
590588
591589 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 " ));
594592 assertThat ("Incorrect username" , fields [2 ], equalTo ("elasticsearch" ));
595593 }
596594
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+ */
597618 public void test140CgroupOsStatsAreAvailable () throws Exception {
598619 waitForElasticsearch (installation );
599620
0 commit comments