Skip to content

Commit 3c37753

Browse files
committed
fix: load the system cert pool in multistage build
1 parent 4909c21 commit 3c37753

File tree

3 files changed

+31
-9
lines changed

3 files changed

+31
-9
lines changed

e2eTests/docker-compose.template.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ services:
142142
- LEGA_MQ_QUEUE=<<INTERCEPTOR_LEGA_MQ_QUEUE>>
143143
- ENABLE_TLS=<<INTERCEPTOR_ENABLE_TLS>>
144144
- CA_CERT_PATH=<<INTERCEPTOR_CA_CERT_PATH>>
145+
- DEBUG=true
145146
volumes:
146147
- interceptor-certs:/certs
147148

services/mq-interceptor/Dockerfile

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
FROM docker.io/library/golang:1.24 AS builder
1+
FROM golang:1.24 AS builder
22

3-
ENV GOPATH=$PWD
43
ENV CGO_ENABLED=0
54
ENV GOPROXY=direct
65

6+
WORKDIR /app
77
COPY . .
88

9-
RUN go build
9+
RUN go build -o mq-interceptor ./main.go
1010

11-
RUN echo "nobody:x:65534:65534:nobody:/:/sbin/nologin" > passwd
11+
# Optional: create passwd for non-root user
12+
RUN echo "nobody:x:65534:65534:nobody:/:" > /app/passwd
1213

13-
FROM scratch
14+
# ---- Final stage ----
15+
FROM gcr.io/distroless/static:nonroot
1416

15-
COPY --from=builder /go/passwd /etc/passwd
16-
COPY --from=builder /go/mq-interceptor ./mq-interceptor
17+
COPY --from=builder /app/mq-interceptor /
18+
COPY --from=builder /app/passwd /etc/passwd
1719

1820
USER 65534
1921

20-
ENTRYPOINT [ "/mq-interceptor" ]
22+
ENTRYPOINT ["/mq-interceptor"]

services/mq-interceptor/main.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,29 @@ func selectEgaIdByElixirId(elixirId string) (egaId string, err error) {
255255
}
256256

257257
func getTLSConfig() *tls.Config {
258+
debug := os.Getenv("DEBUG") == "true"
258259
caCertPath := os.Getenv("CA_CERT_PATH")
259260
if caCertPath == "" {
260-
log.Println("CA_CERT_PATH environment variable not set, using default TLS configurations")
261+
if debug {
262+
log.Println("CA_CERT_PATH not set, using system cert pool")
263+
}
264+
systemPool, err := x509.SystemCertPool()
265+
if err != nil {
266+
log.Printf("WARNING: Failed to load system cert pool: %v", err)
267+
return &tls.Config{InsecureSkipVerify: false}
268+
}
269+
if debug {
270+
log.Println("System cert pool loaded (cannot list subjects due to security).")
271+
}
261272
return &tls.Config{
273+
RootCAs: systemPool,
262274
InsecureSkipVerify: false,
263275
}
264276
}
277+
// Load custom CA from path
278+
if debug {
279+
log.Printf("Using CA certificate from path: %s", caCertPath)
280+
}
265281
caCert, err := os.ReadFile(caCertPath)
266282
if err != nil {
267283
log.Fatalf("Failed to read CA certificate: %v", err)
@@ -270,6 +286,9 @@ func getTLSConfig() *tls.Config {
270286
if !caCertPool.AppendCertsFromPEM(caCert) {
271287
log.Fatal("Failed to add CA certificate to pool")
272288
}
289+
if debug {
290+
log.Println("Custom CA certificate loaded and added to pool")
291+
}
273292
return &tls.Config{
274293
RootCAs: caCertPool,
275294
InsecureSkipVerify: false,

0 commit comments

Comments
 (0)