From 5473e7ea51a851dea03273e243d412dddfb5878e Mon Sep 17 00:00:00 2001 From: Lukas Piwowarski Date: Wed, 21 Oct 2026 14:43:30 +0200 Subject: [PATCH 1/2] chore: standardize Containerfile image labels This commit introduces a new set of LABELS into the Containerfile to ensure that we follow as closely as possible the LABELS structure other OpenStack containers follow. Most notably: - s2i.openstack.org/stream - org.opencontainers.image.revision --- .github/workflows/build-and-push.yaml | 5 +++++ Dockerfile | 23 +++++++++++++++++++++++ Makefile | 16 ++++++++++++++-- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-push.yaml b/.github/workflows/build-and-push.yaml index 4eaaa370..4783c774 100644 --- a/.github/workflows/build-and-push.yaml +++ b/.github/workflows/build-and-push.yaml @@ -29,6 +29,7 @@ jobs: run: | SHA=${{ github.sha }} VERSION="0.1.0-${SHA::7}" + IMAGE_VERSION="${VERSION%-*}" IMAGE_TAG_BASE=${REGISTRY}/${IMAGE_ORG}/${OPERATOR_NAME} OPERATOR_IMAGE=${IMAGE_TAG_BASE}:v${VERSION} BUNDLE_IMAGE=${IMAGE_TAG_BASE}-bundle:v${VERSION} @@ -46,6 +47,7 @@ jobs: CATALOG_IMAGE_LATEST=${IMAGE_TAG_BASE}-catalog:${LATEST_TAG} echo "VERSION=$VERSION" >> $GITHUB_ENV + echo "IMAGE_VERSION=$IMAGE_VERSION" >> $GITHUB_ENV echo "IMAGE_TAG_BASE=$IMAGE_TAG_BASE" >> $GITHUB_ENV echo "OPERATOR_IMAGE=$OPERATOR_IMAGE" >> $GITHUB_ENV @@ -77,6 +79,9 @@ jobs: password: ${{ secrets.REDHATIO_PASSWORD }} - name: Build operator image + env: + STREAM: ${{ github.head_ref || github.ref_name }} + GIT_REVISION: ${{ github.event.pull_request.head.sha || github.sha }} run: | make docker-build IMG=$OPERATOR_IMAGE podman tag $OPERATOR_IMAGE $OPERATOR_IMAGE_LATEST diff --git a/Dockerfile b/Dockerfile index 1df55ef9..a9398c27 100644 --- a/Dockerfile +++ b/Dockerfile @@ -35,4 +35,27 @@ WORKDIR / COPY --from=builder /workspace/manager . USER 65532:65532 +ARG IMAGE_COMPONENT="openstack-lightspeed" +ARG IMAGE_NAME="lightspeed-operator" +ARG IMAGE_VERSION="0.1.0" +ARG IMAGE_SUMMARY="Openstack Lightspeed Operator" +ARG IMAGE_DESC="This image includes the openstack-k8s-operators/lightspeed-operator" +ARG IMAGE_TAGS="cn-openstack openstack lightspeed" +ARG STREAM +ARG GIT_REVISION + +LABEL com.redhat.component="${IMAGE_COMPONENT}" \ + name="${IMAGE_NAME}" \ + version="${IMAGE_VERSION}" \ + summary="${IMAGE_SUMMARY}" \ + io.k8s.name="${IMAGE_NAME}" \ + io.k8s.description="${IMAGE_DESC}" \ + io.openshift.tags="${IMAGE_TAGS}" \ + org.label-schema.vcs-url="https://github.com/openstack-k8s-operators/lightspeed-operator" \ + s2i.openstack.org/stream=${STREAM} \ + org.opencontainers.image.revision=${GIT_REVISION} \ + org.opencontainers.image.title="OpenStack Lightspeed Operator" \ + org.opencontainers.image.description="${IMAGE_DESC}" \ + org.opencontainers.image.source="https://github.com/openstack-k8s-operators/lightspeed-operator" + ENTRYPOINT ["/manager"] diff --git a/Makefile b/Makefile index d48c81b3..dd73a0e0 100644 --- a/Makefile +++ b/Makefile @@ -157,6 +157,10 @@ lint-config: golangci-lint ## Verify golangci-lint linter configuration ##@ Build +export STREAM ?= $(shell git branch --show-current) +export GIT_REVISION ?= $(shell git rev-parse HEAD) +export IMAGE_VERSION ?= 0.1.0 + .PHONY: build build: manifests generate fmt vet ## Build manager binary. go build -o bin/manager cmd/main.go @@ -179,7 +183,11 @@ webhook-cleanup: ## Remove the admission webhook used for local development. # More info: https://docs.docker.com/develop/develop-images/build_enhancements/ .PHONY: docker-build docker-build: ## Build docker image with the manager. - $(CONTAINER_TOOL) build -t ${IMG} . + $(CONTAINER_TOOL) build \ + --build-arg "STREAM=$${STREAM}" \ + --build-arg "GIT_REVISION=$${GIT_REVISION}" \ + --build-arg "IMAGE_VERSION=$${IMAGE_VERSION}" \ + -t "${IMG}" . .PHONY: docker-push docker-push: ## Push docker image with the manager. @@ -198,7 +206,11 @@ docker-buildx: ## Build and push docker image for the manager for cross-platform sed -e '1 s/\(^FROM\)/FROM --platform=\$$\{BUILDPLATFORM\}/; t' -e ' 1,// s//FROM --platform=\$$\{BUILDPLATFORM\}/' Dockerfile > Dockerfile.cross - $(CONTAINER_TOOL) buildx create --name lightspeed-operator-builder $(CONTAINER_TOOL) buildx use lightspeed-operator-builder - - $(CONTAINER_TOOL) buildx build --push --platform=$(PLATFORMS) --tag ${IMG} -f Dockerfile.cross . + - $(CONTAINER_TOOL) buildx build \ + --build-arg "STREAM=$${STREAM}" \ + --build-arg "GIT_REVISION=$${GIT_REVISION}" \ + --build-arg "IMAGE_VERSION=$${IMAGE_VERSION}" \ + --push --platform=$(PLATFORMS) --tag "${IMG}" -f Dockerfile.cross . - $(CONTAINER_TOOL) buildx rm lightspeed-operator-builder rm Dockerfile.cross From 77c8073b890eef645630effa8aff288f35335bd7 Mon Sep 17 00:00:00 2001 From: Lukas Piwowarski Date: Fri, 23 Oct 2026 10:54:31 +0200 Subject: [PATCH 2/2] fix: Prevent ref name shell injection Ref names are expanded into the shell script. For example, a selected branch or tag named $(id) would be interpreted as command substitution when assigned directly in Bash. Pass the ref through an environment variable so it is treated as data [1]. [1] https://docs.github.com/en/actions/concepts/security/script-injections#understanding-the-risk-of-script-injections --- .github/workflows/build-and-push.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-and-push.yaml b/.github/workflows/build-and-push.yaml index 4783c774..105c137e 100644 --- a/.github/workflows/build-and-push.yaml +++ b/.github/workflows/build-and-push.yaml @@ -26,6 +26,8 @@ jobs: - name: Prepare variables id: vars + env: + REF_NAME: ${{ github.ref_name }} run: | SHA=${{ github.sha }} VERSION="0.1.0-${SHA::7}" @@ -37,10 +39,10 @@ jobs: # `main` branch -> `latest` tag # any other branch -> `[branch-name]-latest` tag - if [[ "${{ github.ref_name }}" == "main" ]]; then + if [[ "$REF_NAME" == "main" ]]; then LATEST_TAG=latest else - LATEST_TAG=${{ github.ref_name }}-latest + LATEST_TAG="${REF_NAME}-latest" fi OPERATOR_IMAGE_LATEST=${IMAGE_TAG_BASE}:${LATEST_TAG} BUNDLE_IMAGE_LATEST=${IMAGE_TAG_BASE}-bundle:${LATEST_TAG}