Skip to content

Commit 2980b21

Browse files
Merge pull request #132 from hmcts/fix/fix-certs
fix: add startup script to import certs in /etc/certs into java keystore
2 parents 9578fde + 6baa8f5 commit 2980b21

File tree

7 files changed

+81
-53
lines changed

7 files changed

+81
-53
lines changed

.github/workflows/ci-build-publish.yml

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,6 @@ jobs:
120120
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
121121
AZURE_DEVOPS_ARTIFACT_USERNAME: ${{ secrets.AZURE_DEVOPS_ARTIFACT_USERNAME }}
122122
AZURE_DEVOPS_ARTIFACT_TOKEN: ${{ secrets.AZURE_DEVOPS_ARTIFACT_TOKEN }}
123-
AMP_BACKEND_URL: ${{ secrets.AMP_BACKEND_URL }}
124-
CP_BACKEND_URL: ${{ secrets.CP_BACKEND_URL }}
125-
CJSCPPUID: ${{ secrets.CJSCPPUID }}
126123
ENVIRONMENT: ${{ inputs.environment }}
127124
run: |
128125
echo "Active environment=$ENVIRONMENT"
@@ -142,10 +139,7 @@ jobs:
142139
-DGITHUB_ACTOR=${{ github.actor }} \
143140
-DGITHUB_TOKEN=$GITHUB_TOKEN \
144141
-DAZURE_DEVOPS_ARTIFACT_USERNAME=$AZURE_DEVOPS_ARTIFACT_USERNAME \
145-
-DAZURE_DEVOPS_ARTIFACT_TOKEN=$AZURE_DEVOPS_ARTIFACT_TOKEN \
146-
-DAMP_BACKEND_URL=$AMP_BACKEND_URL \
147-
-DCP_BACKEND_URL=$CP_BACKEND_URL \
148-
-DCJSCPPUID=$CJSCPPUID
142+
-DAZURE_DEVOPS_ARTIFACT_TOKEN=$AZURE_DEVOPS_ARTIFACT_TOKEN
149143
150144
Build-Docker:
151145
needs: [ Provider-Deploy, Build, Artefact-Version ]
@@ -184,9 +178,6 @@ jobs:
184178
build-args: |
185179
BASE_IMAGE=eclipse-temurin:21
186180
JAR_FILENAME=${{ needs.Build.outputs.artefact_name }}.jar
187-
AMP_BACKEND_URL=${{ secrets.AMP_BACKEND_URL }}
188-
CP_BACKEND_URL=${{ secrets.CP_BACKEND_URL }}
189-
CJSCPPUID=${{ secrets.CJSCPPUID }}
190181
191182
Deploy:
192183
needs: [ Provider-Deploy, Build, Artefact-Version ]

Dockerfile

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,18 @@
1-
# ---- Base image (default fallback) ----
2-
ARG BASE_IMAGE
3-
FROM ${BASE_IMAGE:-eclipse-temurin:21}
1+
FROM eclipse-temurin:21
42

5-
# ---- Runtime arguments ----
6-
ARG JAR_FILENAME
7-
ARG JAR_FILE_PATH
8-
ARG AMP_BACKEND_URL
9-
ARG CP_BACKEND_URL
10-
ARG CJSCPPUID
11-
12-
ENV JAR_FILENAME=${JAR_FILENAME:-app.jar}
13-
ENV JAR_FILE_PATH=${JAR_FILE_PATH:-build/libs}
14-
ENV JAR_FULL_PATH=$JAR_FILE_PATH/$JAR_FILENAME
15-
16-
ENV AMP_BACKEND_URL=$AMP_BACKEND_URL
17-
ENV CP_BACKEND_URL=$CP_BACKEND_URL
18-
ENV CJSCPPUID=$CJSCPPUID
19-
20-
21-
# ---- Set runtime ENV for Spring Boot to bind port
22-
ARG SERVER_PORT
23-
ENV SERVER_PORT=${SERVER_PORT:-4550}
3+
WORKDIR /app
244

255
# ---- Dependencies ----
266
RUN apt-get update \
277
&& apt-get install -y curl \
288
&& rm -rf /var/lib/apt/lists/*
299

3010
# ---- Application files ----
31-
COPY $JAR_FULL_PATH /opt/app/app.jar
32-
COPY lib/applicationinsights.json /opt/app/
33-
34-
# ---- Permissions ----
35-
RUN chmod 755 /opt/app/app.jar
11+
COPY docker/* /app/
12+
COPY build/libs/*.jar /app/
13+
COPY lib/applicationinsights.json /app/
3614

3715
# ---- Runtime ----
3816
EXPOSE 4550
3917

40-
CMD ["java", "-Dcom.sun.net.ssl.checkRevocation=false", "-jar", "/opt/app/app.jar"]
18+
ENTRYPOINT ["/bin/sh","./startup.sh"]

docker/README-certs.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Some useful keytool commands
2+
#
3+
Ignore warning "Warning: use -cacerts option to access cacerts keystore"
4+
Think the finger print for cpp-nonline is A0:AF:DB:4F:...:CA:DA:14:C6
5+
```
6+
keytool -list -keystore $KEYSTORE -storepass changeit
7+
keytool -list -keystore $KEYSTORE -storepass changeit | grep "A0:AF:DB"
8+
keytool -delete -keystore $KEYSTORE -storepass changeit -alias localcert1
9+
keytool -delete -keystore $KEYSTORE -storepass changeit -alias mykey
10+
```
11+

docker/startup.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env sh
2+
# Script to add ssl trust certs into the current truststore / keystore before we start our spring boot app
3+
# We use self signed certificates in our dev and test environments so we need to add these to our chain of trust
4+
# The kubernetes startup will load any self signed certificates into /etc/certs
5+
# We load any certs found in the /etc/certs into the default keystore
6+
#
7+
logmsg() {
8+
SCRIPTNAME=$(basename $0)
9+
echo "$SCRIPTNAME : $1"
10+
}
11+
12+
logmsg "running and loading certificates ..."
13+
export KEYSTORE="$JAVA_HOME/lib/security/cacerts"
14+
if [ -z "$CERTS_DIR" ]; then
15+
logmsg "Warning - expects \$CERTS_DIR to be set. i.e. export CERTS_DIR="/etc/certs
16+
logmsg "Defaulting to /etc/certs"
17+
export CERTS_DIR="/etc/certs"
18+
fi
19+
20+
if [ ! -f "$KEYSTORE" ]; then
21+
logmsg "Error - expects keystore to already exist"
22+
exit 1
23+
fi
24+
25+
export count=1
26+
logmsg "Loading certificates from $CERTS_DIR into keystore $KEYSTORE"
27+
for FILE in $(ls $CERTS_DIR)
28+
do
29+
alias="mojcert$count"
30+
logmsg "Adding $CERTS_DIR/$FILE to keystore with alias $alias"
31+
keytool -importcert -file $CERTS_DIR/$FILE -keystore $KEYSTORE -storepass changeit -alias $alias -noprompt
32+
count=$((count+1))
33+
done
34+
35+
keytool -list -keystore $KEYSTORE -storepass changeit | grep "Your keystore contains"
36+
37+
export LOCALJARFILE=$(ls ./build/libs/*.jar 2>/dev/null | grep -v 'plain' | head -n1)
38+
export DOCKERJARFILE=$(ls /app/*.jar 2>/dev/null | grep -v 'plain' | head -n1)
39+
if [ -f "$DOCKERJARFILE" ]; then
40+
logmsg "Running docker java jarfile $DOCKERJARFILE"
41+
java -jar $DOCKERJARFILE
42+
elif [ -f "$LOCALJARFILE" ]; then
43+
logmsg "Running local java jarfile $LOCALJARFILE"
44+
java -jar $LOCALJARFILE
45+
else
46+
logmsg "ERROR - No jarfile found. Unable to start application"
47+
fi

gradle/test.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
tasks.named('test') {
22
useJUnitPlatform {
3-
excludeTags 'pact'
43
}
54
systemProperty 'API_SPEC_VERSION', project.version
65
failFast = true

src/main/java/uk/gov/hmcts/cp/repositories/CourtScheduleClientImpl.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
import lombok.Getter;
55
import lombok.RequiredArgsConstructor;
66
import lombok.extern.slf4j.Slf4j;
7+
import org.owasp.encoder.Encode;
78
import org.springframework.beans.factory.annotation.Value;
89
import org.springframework.context.annotation.Primary;
910
import org.springframework.http.HttpStatus;
1011
import org.springframework.stereotype.Component;
1112
import org.springframework.web.util.UriComponentsBuilder;
1213
import uk.gov.hmcts.cp.domain.HearingResponse;
1314
import uk.gov.hmcts.cp.domain.HearingResponse.HearingSchedule.Judiciary;
14-
15-
import uk.gov.hmcts.cp.openapi.model.Hearing;
15+
import uk.gov.hmcts.cp.openapi.model.CourtSchedule;
1616
import uk.gov.hmcts.cp.openapi.model.CourtScheduleResponse;
1717
import uk.gov.hmcts.cp.openapi.model.CourtSitting;
18-
import uk.gov.hmcts.cp.openapi.model.CourtSchedule;
18+
import uk.gov.hmcts.cp.openapi.model.Hearing;
1919

2020
import java.io.IOException;
2121
import java.net.URI;
@@ -62,10 +62,12 @@ public CourtScheduleResponse getCourtScheduleByCaseId(final String caseId) {
6262
}
6363

6464
private List<Hearing> getHearings(final String caseId) {
65+
final String url = buildUrl(caseId);
66+
log.info("Getting hearings from {}", Encode.forJava(url));
6567
List<Hearing> hearingSchedule = Collections.emptyList();
6668
try {
6769
final HttpRequest request = HttpRequest.newBuilder()
68-
.uri(new URI(buildUrl(caseId)))
70+
.uri(new URI(Encode.forJava(url)))
6971
.GET()
7072
.header("Accept", "application/vnd.listing.search.hearings+json")
7173
.header("CJSCPPUID", getCjscppuid())

src/main/java/uk/gov/hmcts/cp/services/CaseUrnMapperService.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,21 @@
44
import lombok.NonNull;
55
import lombok.RequiredArgsConstructor;
66
import lombok.extern.slf4j.Slf4j;
7+
import org.owasp.encoder.Encode;
78
import org.springframework.beans.factory.annotation.Value;
9+
import org.springframework.http.HttpEntity;
10+
import org.springframework.http.HttpHeaders;
11+
import org.springframework.http.HttpMethod;
12+
import org.springframework.http.HttpStatus;
13+
import org.springframework.http.MediaType;
14+
import org.springframework.http.ResponseEntity;
815
import org.springframework.stereotype.Service;
916
import org.springframework.web.client.RestClientException;
1017
import org.springframework.web.client.RestTemplate;
1118
import org.springframework.web.server.ResponseStatusException;
1219
import org.springframework.web.util.UriComponentsBuilder;
1320
import uk.gov.hmcts.cp.domain.CaseMapperResponse;
1421

15-
import org.springframework.http.HttpEntity;
16-
import org.springframework.http.HttpHeaders;
17-
import org.springframework.http.HttpMethod;
18-
import org.springframework.http.MediaType;
19-
import org.springframework.http.ResponseEntity;
20-
import org.springframework.http.HttpStatus;
21-
import org.owasp.encoder.Encode;
22-
23-
2422

2523
@Service
2624
@RequiredArgsConstructor
@@ -39,9 +37,11 @@ public class CaseUrnMapperService {
3937

4038
public String getCaseId(final String caseUrn) {
4139
final String sanitizedCaseUrn = Encode.forJava(caseUrn);
40+
final String url = getCaseIdUrl(caseUrn);
41+
log.info("Getting caseId from {}", url);
4242
try {
4343
final ResponseEntity<CaseMapperResponse> responseEntity = restTemplate.exchange(
44-
getCaseIdUrl(caseUrn),
44+
url,
4545
HttpMethod.GET,
4646
getRequestEntity(),
4747
CaseMapperResponse.class

0 commit comments

Comments
 (0)