Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/scripts/assert-minimal-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
#
# Fails if a local image ships an SSH client or server, a shell, or a package
# manager, so a distro base and its OpenSSH (SSHole, CVE-2026-123158) can't
# return to the operator image unnoticed. Matches file names only.
#
# Usage: assert-minimal-image.sh <image>
set -euo pipefail

IMAGE="${1:?usage: $0 <image>}"

# The dummy command lets images without ENTRYPOINT or CMD be created; nothing runs.
container=$(docker create "$IMAGE" unused)
trap 'docker rm -f "$container" >/dev/null' EXIT

# Listed separately so a failed export fails the check instead of passing it.
files=$(docker export "$container" | tar -tf -)
[[ -n "$files" ]] || { echo "::error::$IMAGE exported no files" >&2; exit 1; }

# Directories end in "/", so only files and links can match; "(^|/)" also covers "./" prefixes.
rc=0
found=$(grep -E \
'(^|/)(ssh[-.a-z0-9]*|scp|sftp|sftp-server|dropbear[a-z]*|sh|ash|bash|rbash|dash|zsh|ksh|mksh|csh|tcsh|fish|busybox|toybox|apk|apk\.static|apt|apt-get|dpkg|rpm|dnf|tdnf|yum|microdnf|zypper|pacman|opkg)$' \
<<<"$files") || rc=$?
# grep exits 1 for no match; anything above that is an error, not a pass.
(( rc <= 1 )) || { echo "::error::grep failed with exit $rc" >&2; exit "$rc"; }

if [[ -n "$found" ]]; then
echo "::error::$IMAGE ships files a distroless image must not have:" >&2
echo "$found" >&2
exit 1
fi
echo "OK: $IMAGE has no SSH, shell or package manager"
65 changes: 65 additions & 0 deletions .github/scripts/assert-minimal-image_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env bash
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
#
# Negative tests for assert-minimal-image.sh, using throwaway images built
# with `docker import` so no registry access is needed.
set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
WORK=$(mktemp -d)
# Unique per run so parallel runs on one daemon don't delete each other's images.
REPO="assert-minimal-image-test-$$"
cleanup() {
rm -rf "$WORK"
docker images -q "$REPO" | sort -u | xargs -r docker rmi -f >/dev/null
}
trap cleanup EXIT

# make_image <name> <path>... : image with an empty file at each path. No
# ENTRYPOINT or CMD, so every case also covers images that have neither.
make_image() {
local name="$REPO:$1" root="$WORK/$1"; shift
mkdir -p "$root/usr/sbin" "$root/tmp"
for p in "$@"; do mkdir -p "$root/$(dirname "$p")"; : > "$root/$p"; done
tar -C "$root" -c . | docker import - "$name" >/dev/null
}

# check <name> [path] : a clean image must pass; with the path added, the
# check must fail and name that path, so an unrelated error can't count.
check() {
local name="$1" path="${2:-}" out
if [[ -z "$path" ]]; then
make_image "$name" manager etc/ssl/certs/ca.pem usr/lib/rpm/macros var/cache/tdnf/x
bash "$SCRIPT_DIR/assert-minimal-image.sh" "$REPO:$name" >/dev/null
echo "PASS: clean image passes"
return
fi
make_image "$name" manager "$path"
if out=$(bash "$SCRIPT_DIR/assert-minimal-image.sh" "$REPO:$name" 2>&1); then
echo "FAIL: $path was not reported" >&2
exit 1
fi
# docker export may or may not prefix paths with "./".
if [[ $'\n'"$out"$'\n' != *$'\n'"$path"$'\n'* && $'\n'"$out"$'\n' != *$'\n'"./$path"$'\n'* ]]; then
printf 'FAIL: %s failed for another reason:\n%s\n' "$path" "$out" >&2
exit 1
fi
echo "PASS: $path reported"
}

check clean
check sshd usr/sbin/sshd
check sshd-session usr/lib/ssh/sshd-session
check sshd-pam usr/sbin/sshd.pam
check ssh-keysign usr/lib/ssh/ssh-keysign
check ssh-client usr/bin/ssh
check dropbear usr/sbin/dropbear
check shell bin/sh
check mksh bin/mksh
check busybox bin/busybox
check toybox bin/toybox
check apk sbin/apk
check apk-static sbin/apk.static
check tdnf usr/bin/tdnf
check pacman usr/bin/pacman
2 changes: 2 additions & 0 deletions .github/workflows/build_operator_images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
- 'operator/src/**'
- 'operator/cnpg-plugins/**'
- '.github/workflows/build_operator_images.yml'
- '.github/scripts/assert-minimal-image.sh'

permissions:
packages: write
Expand Down Expand Up @@ -75,6 +76,7 @@
docker build --pull --build-arg ARCH=${{ matrix.base_arch }} \
-t $IMAGE \
-f ${{ matrix.image.dockerfile }} ${{ matrix.image.context }}
bash .github/scripts/assert-minimal-image.sh "$IMAGE"
docker push $IMAGE

# ---------------------------------------------------------------------------
Expand Down Expand Up @@ -106,7 +108,7 @@
DIGEST=$(docker buildx imagetools inspect ghcr.io/${{ github.repository }}/${{ matrix.image }}:${{ env.IMAGE_TAG }} \
| awk '/^Digest:/ { print $2 }')
echo "Signing manifest-list@${DIGEST}"
cosign sign ghcr.io/${{ github.repository }}/${{ matrix.image }}@${DIGEST} -y

Check warning on line 111 in .github/workflows/build_operator_images.yml

View workflow job for this annotation

GitHub Actions / lint

[actionlint] reported by reviewdog 🐶 shellcheck reported issue in this script: SC2086:info:4:66: Double quote to prevent globbing and word splitting [shellcheck] Raw Output: i:.github/workflows/build_operator_images.yml:111:74: shellcheck reported issue in this script: SC2086:info:4:66: Double quote to prevent globbing and word splitting [shellcheck]

- name: Verify manifest signature (keyless)
run: |
Expand All @@ -115,4 +117,4 @@
cosign verify \
--certificate-identity "https://github.com/${{ github.repository }}/.github/workflows/build_operator_images.yml@${{ github.ref }}" \
--certificate-oidc-issuer "https://token.actions.githubusercontent.com" \
ghcr.io/${{ github.repository }}/${{ matrix.image }}@${DIGEST}

Check warning on line 120 in .github/workflows/build_operator_images.yml

View workflow job for this annotation

GitHub Actions / lint

[actionlint] reported by reviewdog 🐶 shellcheck reported issue in this script: SC2086:info:6:56: Double quote to prevent globbing and word splitting [shellcheck] Raw Output: i:.github/workflows/build_operator_images.yml:120:64: shellcheck reported issue in this script: SC2086:info:6:56: Double quote to prevent globbing and word splitting [shellcheck]
42 changes: 25 additions & 17 deletions .github/workflows/test-build-and-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@

echo "✓ Operator Docker image built successfully for ${{ matrix.arch }}"

- name: Check operator image has no SSH, shell or package manager
run: |
bash .github/scripts/assert-minimal-image_test.sh
bash .github/scripts/assert-minimal-image.sh \
ghcr.io/${{ github.repository_owner }}/documentdb-kubernetes-operator/operator:${{ env.IMAGE_TAG }}-${{ matrix.arch }}

- name: Save operator Docker image as artifact
run: |
echo "Saving operator ${{ matrix.arch }} Docker image as tar file..."
Expand Down Expand Up @@ -846,7 +852,7 @@
helm package documentdb-chart-${{ matrix.arch }} --version ${{ env.CHART_VERSION }}-${{ matrix.arch }}

echo "Generated chart package for ${{ matrix.arch }}:"
ls -la *.tgz

Check warning on line 855 in .github/workflows/test-build-and-package.yml

View workflow job for this annotation

GitHub Actions / lint

[actionlint] reported by reviewdog 🐶 shellcheck reported issue in this script: SC2035:info:14:8: Use ./*glob* or -- *glob* so names with dashes won't become options [shellcheck] Raw Output: i:.github/workflows/test-build-and-package.yml:855:16: shellcheck reported issue in this script: SC2035:info:14:8: Use ./*glob* or -- *glob* so names with dashes won't become options [shellcheck]

- name: Upload platform-specific Helm chart artifact
uses: actions/upload-artifact@v4
Expand All @@ -863,20 +869,22 @@
steps:
- name: Generate Build Summary
run: |
echo "## Build Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Configuration:" >> $GITHUB_STEP_SUMMARY
echo "- **Version**: ${{ inputs.version }}" >> $GITHUB_STEP_SUMMARY
echo "- **Generated Tag**: ${{ env.VERSION }}" >> $GITHUB_STEP_SUMMARY
echo "- **Build Mode**: Platform-specific artifacts with architecture suffixes" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY

echo "### Built Artifacts:" >> $GITHUB_STEP_SUMMARY
echo "- **Operator Images**: Platform-specific (AMD64 + ARM64) with suffix tags" >> $GITHUB_STEP_SUMMARY
echo "- **Sidecar Images**: Platform-specific (AMD64 + ARM64) with suffix tags" >> $GITHUB_STEP_SUMMARY
echo "- **Helm Charts**: Platform-specific charts for AMD64 and ARM64" >> $GITHUB_STEP_SUMMARY

echo "" >> $GITHUB_STEP_SUMMARY
echo "### Job Results:" >> $GITHUB_STEP_SUMMARY
echo "- **Consolidate Images**: ${{ needs.consolidate-images.result }}" >> $GITHUB_STEP_SUMMARY
echo "- **Create Charts**: ${{ needs.create-helm-chart.result }}" >> $GITHUB_STEP_SUMMARY
{
echo "## Build Summary"
echo ""
echo "### Configuration:"
echo "- **Version**: ${{ inputs.version }}"
echo "- **Generated Tag**: ${{ env.VERSION }}"
echo "- **Build Mode**: Platform-specific artifacts with architecture suffixes"
echo ""

echo "### Built Artifacts:"
echo "- **Operator Images**: Platform-specific (AMD64 + ARM64) with suffix tags"
echo "- **Sidecar Images**: Platform-specific (AMD64 + ARM64) with suffix tags"
echo "- **Helm Charts**: Platform-specific charts for AMD64 and ARM64"

echo ""
echo "### Job Results:"
echo "- **Consolidate Images**: ${{ needs.consolidate-images.result }}"
echo "- **Create Charts**: ${{ needs.create-helm-chart.result }}"
} >> "$GITHUB_STEP_SUMMARY"
2 changes: 2 additions & 0 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ on:
- '.github/actions/**'
- '.github/dockerfiles/Dockerfile_combined'
- '.github/scripts/assert-combined-image.sh'
- '.github/scripts/assert-minimal-image.sh'
- '.github/scripts/assert-minimal-image_test.sh'
- '.github/scripts/resolve-documentdb-version.sh'
workflow_dispatch:
inputs:
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## [Unreleased]

### Security
- The operator image moves from the Alpine dev container base to Azure Linux distroless, so it no longer ships OpenSSH (SSHole, CVE-2026-123158), BusyBox, `apk`, `sudo` or `git`. Earlier images ship only the OpenSSH client and never run `sshd`, so they were not exploitable. The image no longer has a shell; use `kubectl debug` to troubleshoot the operator pod.

## [1.2.1] - 2026-11-20

Security release. The default DocumentDB engine moves from `1.0.0` to `1.0.1`: the same engine (extension schema `1.0-0`) rebuilt on patched Debian packages. Unpinned clusters roll onto the new images when the operator is upgraded; there is no schema migration. The CRDs are unchanged from `1.2.0`; when upgrading from `1.1.x` or earlier, apply the `1.2.1` CRDs before `helm upgrade`.
Expand Down
4 changes: 2 additions & 2 deletions docs/designs/image-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ The build process:
### Dockerfile Details

#### Operator (`operator/src/Dockerfile`)
- **Base**: `mcr.microsoft.com/oss/go/microsoft/golang:1.26.11-azurelinux3.0` → `scratch`
- **Multi-stage**: 2 stages (builder → scratch)
- **Base**: `mcr.microsoft.com/oss/go/microsoft/golang:1.26.11-azurelinux3.0` → `mcr.microsoft.com/azurelinux/distroless/minimal:3.0`
- **Multi-stage**: 2 stages (builder → distroless, which keeps CA certificates, tzdata and `/tmp`)
- **Entrypoint**: `/manager`

#### Sidecar (`operator/cnpg-plugins/sidecar-injector/Dockerfile`)
Expand Down
6 changes: 3 additions & 3 deletions operator/documentdb-helm-chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ operator:
seccompProfile:
type: RuntimeDefault
containerSecurityContext:
# The operator image (operator/src/Dockerfile) runs as the Alpine `manager`
# user, which is uid 100. We pin runAsUser explicitly so Kubernetes can
# verify the user is non-root without depending on the image's USER directive.
# The operator image (operator/src/Dockerfile) runs as USER 100:101. We pin
# runAsUser explicitly so Kubernetes can verify the user is non-root
# without depending on the image's USER directive.
# If the operator Dockerfile is changed to use a different uid, update this
# value in lockstep with the appVersion bump.
runAsUser: 100
Expand Down
11 changes: 5 additions & 6 deletions operator/src/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ COPY internal/ internal/
# The ARCH build arg can be used to override the target architecture (e.g., amd64, arm64)
RUN GOEXPERIMENT=nosystemcrypto CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${ARCH:-${TARGETARCH}} go build -a -o manager cmd/main.go

# Use Microsoft official image from MCR as minimal base image to package the manager binary
FROM --platform=${TARGETOS:-linux}/${ARCH:-${TARGETARCH}} mcr.microsoft.com/devcontainers/base:alpine
# The manager is static, so the runtime image needs no shell, package manager
# or SSH, only CA certificates, tzdata and /tmp.
FROM --platform=${TARGETOS:-linux}/${ARCH:-${TARGETARCH}} mcr.microsoft.com/azurelinux/distroless/minimal:3.0
WORKDIR /
# Pick up package fixes published since the base image was built.
RUN apk upgrade --no-cache
COPY --from=builder /workspace/manager .
RUN addgroup -S manager && adduser -S manager -G manager
USER manager
# Same uid/gid as the old Alpine `manager` user; the chart pins runAsUser/runAsGroup to it.
USER 100:101

ENTRYPOINT ["/manager"]
Loading