Skip to content

Commit

Permalink
Use alpine base image with individual ca cert files
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed May 24, 2024
1 parent 83ecbfd commit 8e31e4e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
4 changes: 4 additions & 0 deletions Dockerfile.dbg
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ FROM {ARG_FROM}

LABEL org.opencontainers.image.source https://github.com/kubeops/csi-driver-cacerts

RUN set -x \
&& apt-get update \
&& apt-get install -y --no-install-recommends apt-transport-https ca-certificates

ADD bin/{ARG_OS}_{ARG_ARCH}/{ARG_BIN} /{ARG_BIN}
COPY --from=java /etc/ssl/certs/java/cacerts /etc/ssl/certs/java/cacerts
COPY --from=centos /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt /etc/ssl/certs/ca-bundle.trust.crt
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ FROM {ARG_FROM}

LABEL org.opencontainers.image.source https://github.com/kubeops/csi-driver-cacerts

RUN set -x \
&& apk add --update ca-certificates

ADD bin/{ARG_OS}_{ARG_ARCH}/{ARG_BIN} /{ARG_BIN}
COPY --from=java /etc/ssl/certs/java/cacerts /etc/ssl/certs/java/cacerts
COPY --from=centos /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt /etc/ssl/certs/ca-bundle.trust.crt
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ BIN_PLATFORMS := $(DOCKER_PLATFORMS)
OS := $(if $(GOOS),$(GOOS),$(shell go env GOOS))
ARCH := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH))

BASEIMAGE_PROD ?= gcr.io/distroless/static-debian12
# BASEIMAGE_PROD ?= gcr.io/distroless/static-debian12
BASEIMAGE_PROD ?= alpine
BASEIMAGE_DBG ?= debian:bookworm

IMAGE := $(REGISTRY)/$(BIN)
Expand Down
38 changes: 23 additions & 15 deletions pkg/driver/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,23 +333,27 @@ func updateCACerts(certs map[uint64]*x509.Certificate, osFamily OsFamily, srcDir
}

payload := map[string]atomic_writer.FileProjection{}
entries, err := os.ReadDir(srcDir)
if err != nil {
return errors.Wrap(err, "error reading directory "+srcDir)
}
for _, entry := range entries {
name := entry.Name()
if entry.IsDir() ||
name == "ca-certificates.crt" ||
name == "ca-bundle.pem" {
continue
}

data, err := os.ReadFile(filepath.Join(srcDir, name))
switch osFamily {
case OsFamilyDebian, OsFamilyUbuntu, OsFamilyAlpine, OsFamilyOpensuse:
entries, err := os.ReadDir(srcDir)
if err != nil {
return err
return errors.Wrap(err, "error reading directory "+srcDir)
}
for _, entry := range entries {
name := entry.Name()
if entry.IsDir() ||
name == "ca-certificates.crt" ||
name == "ca-bundle.pem" {
continue
}

data, err := os.ReadFile(filepath.Join(srcDir, name))
if err != nil {
return err
}
payload[name] = atomic_writer.FileProjection{Data: data, Mode: 0o444}
}
payload[name] = atomic_writer.FileProjection{Data: data, Mode: 0o444}
}

var caBuf bytes.Buffer
Expand All @@ -372,7 +376,11 @@ func updateCACerts(certs map[uint64]*x509.Certificate, osFamily OsFamily, srcDir
if err != nil {
return err
}
payload[fmt.Sprintf("%d.pem", certId)] = atomic_writer.FileProjection{Data: pemBuf.Bytes(), Mode: 0o444}

switch osFamily {
case OsFamilyDebian, OsFamilyUbuntu, OsFamilyAlpine, OsFamilyOpensuse:
payload[fmt.Sprintf("%d.pem", certId)] = atomic_writer.FileProjection{Data: pemBuf.Bytes(), Mode: 0o444}
}

caBuf.Write(pemBuf.Bytes())
}
Expand Down

0 comments on commit 8e31e4e

Please sign in to comment.