Repository navigation
Razorpay: hardened operator image from source + Harbor base (0 Go CVEs) #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
99c8f2d
6dcc4ce
72346c8
00392d5
169e783
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| name: Security Checks | ||
| on: | ||
| pull_request: {} | ||
| push: | ||
| branches: ["master"] | ||
| schedule: | ||
| - cron: "0 17 * * *" | ||
| jobs: | ||
| Security-Scan: | ||
| uses: razorpay/security-action/.github/workflows/central_security_checks_prod.yml@master | ||
| secrets: inherit |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| # Razorpay: build the hardened Spark Operator image from source and push it to Harbor (c.rzp.io). | ||
| # | ||
| # Mirrors datahub's custom-base-images CI 1:1 — same self-hosted runners (linux-amd64/linux-arm64), | ||
| # the same internal razorpay/docker-image-build-push action for per-arch build and for the | ||
| # multi-arch manifest, and the same HARBOR_DOCKER_* org secrets. It builds the controller image | ||
| # from THIS repo's Dockerfile: the operator Go binary is rebuilt with the bumped go.mod (0 Go | ||
| # CVEs), FROM the Harbor-approved apache/spark:4.2.1 mirror, with the Spark base hardened (apt | ||
| # upgrade, patched jar swaps, gosu removed). The published tag is then whitelisted in | ||
| # rzp-docker-image-inventory as a custom base image. | ||
| # | ||
| # Requires (same as datahub): access to the private razorpay/docker-image-build-push action and | ||
| # the HARBOR_DOCKER_USERNAME / HARBOR_DOCKER_PASSWORD org secrets reaching this repo. | ||
|
|
||
| name: Razorpay Image Build and Push | ||
|
|
||
| on: | ||
| workflow_dispatch: {} | ||
| push: | ||
| branches: | ||
| - master | ||
| - 'feature/razorpay-**' | ||
|
|
||
| env: | ||
| DOCKER_BUILDKIT: 1 | ||
| REGISTRY: c.rzp.io | ||
| # Harbor repository under the razorpay project: c.rzp.io/razorpay/spark-operator | ||
| REPOSITORY: spark-operator | ||
| # Operator version this image ships; bump with the release. HARDEN_REV tracks the Razorpay | ||
| # hardening revision independently of the operator version. | ||
| OP_VERSION: "2.6.0" | ||
| HARDEN_REV: "hardened-v1" | ||
|
|
||
| jobs: | ||
| # Native per-arch build on the matching self-hosted runner, published with an arch-suffixed tag. | ||
| build: | ||
| name: Build controller (${{ matrix.platform }}) | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| platform: | ||
| - linux-amd64 | ||
| - linux-arm64 | ||
| runs-on: | ||
| - ${{ matrix.platform }} | ||
| steps: | ||
| - name: Checkout Codebase | ||
| # Pinned to an immutable SHA (v4.1.0), same as datahub: a mutable tag can be repointed to | ||
| # attacker code that runs on the self-hosted runner ahead of the credentialed steps. | ||
| uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 | ||
|
|
||
| - name: Resolve image tag | ||
| id: tag | ||
| env: | ||
| COMMIT_SHA: ${{ github.sha }} | ||
| run: | | ||
| set -euo pipefail | ||
| BASE="controller-${OP_VERSION}-${HARDEN_REV}" | ||
| if [ "${GITHUB_REF}" = "refs/heads/master" ]; then | ||
| TAG="${BASE}" | ||
| else | ||
| TAG="${BASE}-${COMMIT_SHA}" | ||
| fi | ||
| echo "tag=${TAG}" >> "$GITHUB_OUTPUT" | ||
| echo "Publishing: ${REGISTRY}/razorpay/${REPOSITORY}:${TAG}-${{ matrix.platform }}" | ||
|
|
||
| - name: Build and push (${{ matrix.platform }}) | ||
| # Pinned to the internal action's v1 branch HEAD, same pin datahub uses. | ||
| uses: razorpay/docker-image-build-push@149c7e92cf1a93d19239cff57a8fc3a61c48ed5e | ||
| with: | ||
| username: ${{ secrets.HARBOR_DOCKER_USERNAME }} | ||
| password: ${{ secrets.HARBOR_DOCKER_PASSWORD }} | ||
| registry: ${{ env.REGISTRY }} | ||
| repository: ${{ env.REPOSITORY }} | ||
| context: . | ||
| file: Dockerfile | ||
| custom-tag: ${{ steps.tag.outputs.tag }}-${{ matrix.platform }} | ||
| enable-login: true | ||
| push: true | ||
|
|
||
| # Publishes the multi-arch manifest tag consumers pin, from the arch-suffixed tags above. | ||
| build-multiarch: | ||
| name: Create multi-arch manifest | ||
| needs: | ||
| - build | ||
| runs-on: | ||
| - linux-amd64 | ||
| steps: | ||
| - name: Checkout Codebase | ||
| uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 | ||
|
|
||
| - name: Resolve image tag | ||
| id: tag | ||
| env: | ||
| COMMIT_SHA: ${{ github.sha }} | ||
| run: | | ||
| set -euo pipefail | ||
| BASE="controller-${OP_VERSION}-${HARDEN_REV}" | ||
| if [ "${GITHUB_REF}" = "refs/heads/master" ]; then | ||
| TAG="${BASE}" | ||
| else | ||
| TAG="${BASE}-${COMMIT_SHA}" | ||
| fi | ||
| echo "tag=${TAG}" >> "$GITHUB_OUTPUT" | ||
| echo "Publishing: ${REGISTRY}/razorpay/${REPOSITORY}:${TAG}" | ||
|
|
||
| - name: Create multiarch image | ||
| uses: razorpay/docker-image-build-push@149c7e92cf1a93d19239cff57a8fc3a61c48ed5e | ||
| with: | ||
| username: ${{ secrets.HARBOR_DOCKER_USERNAME }} | ||
| password: ${{ secrets.HARBOR_DOCKER_PASSWORD }} | ||
| registry: ${{ env.REGISTRY }} | ||
| repository: ${{ env.REPOSITORY }} | ||
| custom-tag: ${{ steps.tag.outputs.tag }} | ||
| trigger-multiarch-image-build: true | ||
| multiarch-suffixes: | | ||
| -linux-amd64 | ||
| -linux-arm64 | ||
| enable-login: true |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,9 +14,15 @@ | |||||
| # limitations under the License. | ||||||
| # | ||||||
|
|
||||||
| ARG SPARK_IMAGE=docker.io/apache/spark:4.2.1-scala2.13-java21-ubuntu@sha256:ce1d0c8407066ed44b91f699b6edd3564f143722e3ef95e19d99a67b5754b306 | ||||||
| # Razorpay hardening: build FROM the Harbor-approved Spark mirror (RSPL), not docker.io, so there | ||||||
| # is no non-Harbor base finding. Same 4.2.1 digest, just pulled from the approved registry. | ||||||
| ARG SPARK_IMAGE=c.rzp.io/razorpay-external/apache/spark@sha256:ce1d0c8407066ed44b91f699b6edd3564f143722e3ef95e19d99a67b5754b306 | ||||||
|
|
||||||
| FROM docker.io/library/golang:1.26.10@sha256:670bb5aa5349ae03b8516764718486f4f16399134bdc9acd0c46a23f043ab05c AS builder | ||||||
| # Go 1.27.4 builder (via the Harbor DockerHub proxy). The bumped go.mod (x/net 0.63, x/text 0.44, | ||||||
| # x/mod 0.43, otel/trace 1.47) + this toolchain rebuild the operator binary with 0 Go CVEs | ||||||
| # (verified with Trivy). GOTOOLCHAIN=local pins the build to this toolchain. | ||||||
| FROM c.rzp.io/proxy_dockerhub/library/golang:1.27.4@sha256:5bd30d78fe7788dc760abe3e3437434781b3164e50fadc24611fa7fbc0cfb6ba AS builder | ||||||
| ENV GOTOOLCHAIN=local | ||||||
|
|
||||||
| WORKDIR /workspace | ||||||
|
|
||||||
|
|
@@ -53,6 +59,22 @@ RUN --mount=type=cache,target=/go/pkg/mod/ \ | |||||
| FROM scratch AS artifacts | ||||||
| COPY --from=builder /workspace/bin/spark-operator /spark-operator | ||||||
|
|
||||||
| # Razorpay hardening: resolve the patched standalone jars (patch/minor bumps that are | ||||||
| # Spark-ABI-safe) via the GCS Maven Central mirror. Maven verifies each artifact's published | ||||||
| # checksum. These replace the vulnerable standalone jars the Spark base ships in /opt/spark/jars. | ||||||
| FROM c.rzp.io/proxy_dockerhub/library/maven:3.9-eclipse-temurin-21 AS jars | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔵 Low severity blocking issue identified in your code: To resolve this comment: ✨ Commit fix suggestion
Suggested change
View step-by-step instructions
💬 Ignore this findingLeave a nosemgrep comment directly above or at the end of line 65 like so Take care to validate that this is not a true positive finding before ignoring it. You can view more details about this finding in the Semgrep AppSec Platform. |
||||||
| WORKDIR /build | ||||||
| COPY patched-jars.pom.xml pom.xml | ||||||
| COPY settings.xml settings.xml | ||||||
| RUN ok=0; \ | ||||||
| for i in 1 2 3; do \ | ||||||
| if mvn -B -q -s settings.xml org.apache.maven.plugins:maven-dependency-plugin:3.8.1:copy-dependencies \ | ||||||
| -DexcludeTransitive=true -DoutputDirectory=/staging; then ok=1; break; fi; \ | ||||||
| echo "maven attempt $i failed; retrying in $((i*15))s"; sleep $((i*15)); \ | ||||||
| done; \ | ||||||
| [ "$ok" = 1 ] || { echo "FAIL: maven resolution failed"; exit 1; }; \ | ||||||
| ls -1 /staging | ||||||
|
|
||||||
| FROM ${SPARK_IMAGE} | ||||||
|
|
||||||
| ARG SPARK_UID=185 | ||||||
|
|
@@ -61,9 +83,47 @@ ARG SPARK_GID=185 | |||||
|
|
||||||
| USER root | ||||||
|
|
||||||
| RUN apt-get update \ | ||||||
| && apt-get install -y catatonit \ | ||||||
| && rm -rf /var/lib/apt/lists/* | ||||||
| # Razorpay hardening: OS security upgrade + catatonit (operator needs it) + remove gosu. | ||||||
| # gosu is a Go 1.18 setuid binary (Go EOL) the Spark base ships for its own root->user entrypoint. | ||||||
| # This operator image runs non-root as uid 185 and its entrypoint uses catatonit, never gosu, so | ||||||
| # gosu is dead weight here — removing it clears the Go-EOL finding with no functional impact. | ||||||
| RUN set -eux; \ | ||||||
| apt-get update; \ | ||||||
| DEBIAN_FRONTEND=noninteractive apt-get -y upgrade; \ | ||||||
| apt-get install -y --no-install-recommends catatonit; \ | ||||||
| rm -f /usr/sbin/gosu /usr/local/bin/gosu /usr/bin/gosu; \ | ||||||
| apt-get clean; rm -rf /var/lib/apt/lists/* | ||||||
|
|
||||||
| # Razorpay hardening: swap the vulnerable standalone jars the Spark base ships for patched | ||||||
| # versions, then verify fail-CLOSED — no old vulnerable version may remain (a missed rm name is | ||||||
| # caught here), no artifact may carry two versions on the classpath, every patched jar present. | ||||||
| RUN set -eux; cd /opt/spark/jars; \ | ||||||
| rm -f netty-*-4.2.13.Final*.jar jackson-core-2.21.2*.jar jackson-databind-2.21.2*.jar \ | ||||||
| jackson-dataformat-yaml-2.21.2*.jar jackson-datatype-jsr310-2.21.2*.jar \ | ||||||
| jackson-module-scala_2.13-2.21.2*.jar snappy-java-1.1.10.8*.jar lz4-java-1.11.0*.jar \ | ||||||
| guava-33.6.0-jre*.jar jline-3.29.0*.jar derby-10.16.1.1*.jar derbyshared-10.16.1.1*.jar \ | ||||||
| derbytools-10.16.1.1*.jar | ||||||
| COPY --from=jars --chown=185:185 /staging/ /opt/spark/jars/ | ||||||
| RUN set -eux; cd /opt/spark/jars; \ | ||||||
| if ls netty-*-4.2.13.Final*.jar >/dev/null 2>&1; then echo "FAIL: netty 4.2.13 still present"; exit 1; fi; \ | ||||||
| for v in jackson-core-2.21.2 jackson-databind-2.21.2 jackson-dataformat-yaml-2.21.2 \ | ||||||
| jackson-datatype-jsr310-2.21.2 jackson-module-scala_2.13-2.21.2 snappy-java-1.1.10.8 \ | ||||||
| lz4-java-1.11.0 guava-33.6.0-jre jline-3.29.0 derby-10.16.1.1 derbyshared-10.16.1.1 \ | ||||||
| derbytools-10.16.1.1; do \ | ||||||
| if ls ${v}*.jar >/dev/null 2>&1; then echo "FAIL: vulnerable ${v} still present:"; ls ${v}*.jar; exit 1; fi; \ | ||||||
| done; \ | ||||||
| nv=$(ls netty-*-4.2.*.Final*.jar | sed -E 's/.*-(4\.2\.[0-9]+\.Final).*/\1/' | sort -u); \ | ||||||
| [ "$nv" = 4.2.17.Final ] || { echo "FAIL: unexpected netty versions: $nv"; exit 1; }; \ | ||||||
| for a in guava snappy-java lz4-java jackson-core jackson-databind jackson-dataformat-yaml \ | ||||||
| jackson-datatype-jsr310 jackson-module-scala_2.13 derby; do \ | ||||||
| n=$(ls ${a}-*.jar 2>/dev/null | wc -l); \ | ||||||
| [ "$n" -eq 1 ] || { echo "FAIL: $a has $n versions:"; ls ${a}-*.jar 2>/dev/null; exit 1; }; \ | ||||||
| done; \ | ||||||
| jn=$(ls jline-3.*.jar 2>/dev/null | wc -l); [ "$jn" -eq 1 ] || { echo "FAIL: jline3 count=$jn"; ls jline-3.*.jar; exit 1; }; \ | ||||||
| for f in netty-handler-4.2.17.Final guava-33.7.2-jre jackson-databind-2.21.7 \ | ||||||
| snappy-java-1.1.10.9 lz4-java-1.11.4 jline-3.30.15 derby-10.17.1.0; do \ | ||||||
| [ -e "$f.jar" ] || { echo "FAIL: patched $f.jar missing"; exit 1; }; \ | ||||||
| done | ||||||
|
|
||||||
| RUN mkdir -p /etc/k8s-webhook-server/serving-certs /home/spark && \ | ||||||
| chmod -R g+rw /etc/k8s-webhook-server/serving-certs && \ | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔵 Low severity blocking issue identified in your code:
Use of non-harbor in base image is not allowed
To resolve this comment:
✨ Commit fix suggestion
View step-by-step instructions
c.rzp.io/proxy_dockerhub/...builder image with the approved Harbor or Razorpay golden Go image for Go1.27.4, using its immutable digest. For example:FROM c.rzp.io/razorpay/<approved-golang-image>:1.27.4@sha256:<approved-digest> AS builder.AS builderalias and all subsequent build steps unchanged.c.rzp.io/proxy_dockerhub/...orc.rzp.io/proxy_quay/...; these proxy namespaces are not accepted by the policy.GOTOOLCHAIN=localand that the pinned digest matches the approved image content.💬 Ignore this finding
Leave a nosemgrep comment directly above or at the end of line 24 like so
// nosemgrep: razorpay.custom-docker-base-image-checkTake care to validate that this is not a true positive finding before ignoring it.
Learn more about ignoring code, files and folders here.
You can view more details about this finding in the Semgrep AppSec Platform.