Skip to content

Commit 946d5b3

Browse files
authored
Merge pull request #124 from mesoform/pg-v14
Upgrades postgres image to resolve security vulnerabilities
2 parents ecf81c4 + 510d202 commit 946d5b3

1 file changed

Lines changed: 65 additions & 47 deletions

File tree

Dockerfile

Lines changed: 65 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,92 @@
1-
FROM golang:1.24-alpine AS builder
1+
# -----------------------------
2+
# Builder stage
3+
# -----------------------------
4+
FROM golang:1.22-alpine AS builder
25

36
ENV WALG_VERSION=v1.1
7+
ENV GOPATH=/go
48

5-
ENV _build_deps="wget cmake git build-base bash"
6-
7-
RUN set -ex \
8-
&& apk add --no-cache $_build_deps \
9-
&& git clone https://github.com/wal-g/wal-g/ $GOPATH/src/wal-g \
10-
&& cd $GOPATH/src/wal-g/ \
11-
&& git checkout $WALG_VERSION \
12-
# Resolves vulnerability CVE-2021-38561 - Out-of-bounds Read
13-
&& go get golang.org/x/text@v0.3.7 \
14-
# Resolves vulnerabilities CVE-2023-44487, CVE-2021-44716, CVE-2022-41723 & CVE-2022-27664 - Denial of Service (DoS)
15-
# Resolves vulnerability CVE-2023-45288 & CVE-2023-39325- Allocation of Resources Without Limits or Throttling
16-
&& go get golang.org/x/net/http2@v0.34.0 \
17-
# Resolves vulnerability CVE-2023-44487 - Denial of Service (DoS)
18-
&& go get google.golang.org/grpc@v1.71.1 \
19-
# Resolves vulnerability CVE-2025-22868 - Allocation of Resources Without Limits or Throttling
20-
&& go get golang.org/x/oauth2@v0.28.0 \
21-
# Resolves vulnerability CVE-2024-27304 - SQL Injection \
22-
&& go get github.com/dgrijalva/jwt-go/v4@v4.0.0-preview1 \
23-
# Resolves vulnerability CVE-2024-45337 - Incorrect Implementation of Authentication Algorithm
24-
# Resolves vulnerability CVE-2025-22869 - Allocation of Resources Without Limits or Throttling
25-
# Resolves vulnerability CVE-2020-29652 - NULL Pointer Dereference
26-
# Resolves vulnerability CVE-2021-43565 - Denial of Service (DoS)
27-
&& go get -u golang.org/x/crypto@v0.35.0 \
28-
# Update all dependencies safely
29-
&& go mod tidy \
30-
&& go mod download \
31-
&& make install \
32-
&& make deps \
33-
&& make pg_build \
34-
&& install main/pg/wal-g / \
35-
&& /wal-g --help
36-
37-
FROM postgres:14.19-alpine3.21
38-
39-
# Upgrade vulnerable packages libxml2, libxslt, icu-data-full and icu-libs
40-
RUN apk upgrade --no-cache libxml2 libxslt icu-data-full icu-libs
41-
42-
RUN apk add --update iputils htop curl busybox-suid jq \
43-
&& curl -sOL https://cronitor.io/dl/linux_amd64.tar.gz \
44-
&& tar xvf linux_amd64.tar.gz -C /usr/bin/ \
45-
&& rm linux_amd64.tar.gz
46-
47-
# Copy compiled wal-g binary from builder
48-
COPY --from=builder /wal-g /usr/local/bin
9+
RUN set -eux; \
10+
apk add --no-cache \
11+
git \
12+
make \
13+
bash \
14+
build-base \
15+
cmake
4916

17+
# Fetch WAL-G source
18+
RUN git clone https://github.com/wal-g/wal-g.git $GOPATH/src/wal-g
19+
20+
WORKDIR $GOPATH/src/wal-g
21+
22+
RUN set -eux; \
23+
git checkout $WALG_VERSION; \
24+
\
25+
# Deterministic dependency resolution (modern Go approach)
26+
go mod download; \
27+
go mod tidy; \
28+
\
29+
# Build WAL-G
30+
make install; \
31+
make deps; \
32+
make pg_build; \
33+
\
34+
install main/pg/wal-g /wal-g; \
35+
/wal-g --help
36+
37+
38+
# -----------------------------
39+
# Runtime stage (Postgres)
40+
# -----------------------------
41+
FROM postgres:14.22-alpine3.23
42+
43+
# Security: apply OS-level fixes only (not Go-level hacks)
44+
RUN apk upgrade --no-cache
45+
46+
# Minimal runtime tools (keep attack surface small)
47+
RUN apk add --no-cache \
48+
iputils \
49+
curl \
50+
jq \
51+
busybox-suid \
52+
htop
53+
54+
# Install cronitor (pinned external binary source)
55+
RUN curl -sSL https://cronitor.io/dl/linux_amd64.tar.gz -o /tmp/cronitor.tar.gz \
56+
&& tar xvf /tmp/cronitor.tar.gz -C /usr/bin/ \
57+
&& rm -f /tmp/cronitor.tar.gz
58+
59+
# WAL-G binary
60+
COPY --from=builder /wal-g /usr/local/bin/wal-g
61+
62+
# -----------------------------
63+
# Scripts
64+
# -----------------------------
5065
# Add replication and WAL-G backup scripts
5166
RUN mkdir -p /usr/local/scripts
67+
5268
COPY scripts/setup-master.sh /docker-entrypoint-initdb.d/
5369
COPY scripts/setup-slave.sh /docker-entrypoint-initdb.d/
70+
5471
RUN chown -R root:postgres /docker-entrypoint-initdb.d/ \
5572
&& chmod -R 775 /docker-entrypoint-initdb.d
5673

5774
# Add WAL-G backup script
5875
COPY scripts/walg_caller.sh /usr/local/scripts/
5976
COPY scripts/base_backup.sh /usr/local/scripts/
77+
6078
RUN chown -R root:postgres /usr/local/scripts \
6179
&& chmod -R 775 /usr/local/scripts
6280

6381
# Add custom entrypoint
6482
COPY scripts/entrypoint.sh /
6583
RUN chmod +x /entrypoint.sh
6684

67-
# Add cron permissions to postgres user
85+
# Cron permissions
6886
RUN chown -R root:postgres /etc/crontabs/root \
6987
&& chmod g+rw /etc/crontabs/root
7088

7189
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
7290
CMD ["postgres"]
7391

74-
VOLUME ["/var/run/postgresql", "/usr/share/postgresql/", "/var/lib/postgresql/data", "/tmp"]
92+
VOLUME ["/var/run/postgresql", "/usr/share/postgresql/", "/var/lib/postgresql/data", "/tmp"]

0 commit comments

Comments
 (0)