From e63f4f8c8e86734c5e905e813cab0b3bddcbb0e1 Mon Sep 17 00:00:00 2001 From: Armel Soro Date: Mon, 23 Nov 2026 13:49:40 +0100 Subject: [PATCH 1/2] ci: enforce NetworkPolicies in Kind test clusters Kind's default CNI (kindnet) does not enforce NetworkPolicies, so the NetworkPolicies shipped by the Operator were silently ignored and the upstream tests could pass even when the policies were wrong or incomplete. Create the Kind clusters with the default CNI disabled and install Calico before running the integration, E2E, and upgrade tests. Calico is pinned to a release tested against the Kubernetes version shipped by the kind-action used in these workflows. Assisted-by: OpenCode Signed-off-by: Armel Soro --- .../nightly-postgresql-upgrade-test.yaml | 8 +++ .github/workflows/nightly-upgrade-test.yaml | 9 +++ .github/workflows/nightly.yaml | 16 +++++ .github/workflows/pr.yaml | 7 +++ hack/install-calico.sh | 60 +++++++++++++++++++ hack/kind-config.yaml | 13 ++++ tests/e2e/README.md | 8 ++- 7 files changed, 120 insertions(+), 1 deletion(-) create mode 100755 hack/install-calico.sh create mode 100644 hack/kind-config.yaml diff --git a/.github/workflows/nightly-postgresql-upgrade-test.yaml b/.github/workflows/nightly-postgresql-upgrade-test.yaml index bc901566f..a106de2de 100644 --- a/.github/workflows/nightly-postgresql-upgrade-test.yaml +++ b/.github/workflows/nightly-postgresql-upgrade-test.yaml @@ -68,6 +68,9 @@ jobs: cat < "$RUNNER_TEMP/kind-config.yaml" apiVersion: kind.x-k8s.io/v1alpha4 kind: Cluster + networking: + disableDefaultCNI: true + podSubnet: "192.168.0.0/16" nodes: - role: control-plane extraPortMappings: @@ -91,8 +94,13 @@ jobs: with: cluster_name: test-cluster config: ${{ runner.temp }}/kind-config.yaml + # Nodes stay NotReady until a CNI is installed, so don't wait here. + wait: "0" ignore_failed_clean: true + - name: Install Calico CNI (NetworkPolicy enforcement) + run: ./hack/install-calico.sh + - name: Load target operator image run: kind load docker-image --name test-cluster "$TO_OPERATOR_IMAGE" diff --git a/.github/workflows/nightly-upgrade-test.yaml b/.github/workflows/nightly-upgrade-test.yaml index e8e2e9dc8..e75e1375c 100644 --- a/.github/workflows/nightly-upgrade-test.yaml +++ b/.github/workflows/nightly-upgrade-test.yaml @@ -83,6 +83,9 @@ jobs: cat < /tmp/kind-config.yaml apiVersion: kind.x-k8s.io/v1alpha4 kind: Cluster + networking: + disableDefaultCNI: true + podSubnet: "192.168.0.0/16" nodes: - role: control-plane # extraMounts: @@ -112,8 +115,14 @@ jobs: with: cluster_name: test-cluster config: /tmp/kind-config.yaml + # Nodes stay NotReady until a CNI is installed, so don't wait here. + wait: "0" ignore_failed_clean: true + - name: Install Calico CNI (NetworkPolicy enforcement) + if: ${{ steps.operator-image-existence-checker.outputs.FROM_OPERATOR_IMAGE_EXISTS == 'true' && steps.operator-image-existence-checker.outputs.TO_OPERATOR_IMAGE_EXISTS == 'true' }} + run: ./hack/install-calico.sh + - name: Install Ingress Controller if: ${{ steps.operator-image-existence-checker.outputs.FROM_OPERATOR_IMAGE_EXISTS == 'true' && steps.operator-image-existence-checker.outputs.TO_OPERATOR_IMAGE_EXISTS == 'true' }} run: | diff --git a/.github/workflows/nightly.yaml b/.github/workflows/nightly.yaml index faab6cbb1..5186cddee 100644 --- a/.github/workflows/nightly.yaml +++ b/.github/workflows/nightly.yaml @@ -85,8 +85,15 @@ jobs: uses: helm/kind-action@a1b0e391336a6ee6713a0583f8c6240d70863de3 # v1.12.0 with: cluster_name: integration-test-cluster + config: hack/kind-config.yaml + # Nodes stay NotReady until a CNI is installed, so don't wait here. + wait: "0" ignore_failed_clean: true + - name: Install Calico CNI (integration tests) + if: ${{ steps.operator-image-existence-checker.outputs.OPERATOR_IMAGE_EXISTS == 'true' }} + run: ./hack/install-calico.sh + - name: Run Controller if: ${{ steps.operator-image-existence-checker.outputs.OPERATOR_IMAGE_EXISTS == 'true' }} # run this stage only if there are changes that match the includes and not the excludes @@ -120,6 +127,9 @@ jobs: cat < /tmp/kind-config.yaml apiVersion: kind.x-k8s.io/v1alpha4 kind: Cluster + networking: + disableDefaultCNI: true + podSubnet: "192.168.0.0/16" nodes: - role: control-plane extraPortMappings: @@ -137,8 +147,14 @@ jobs: with: cluster_name: e2e-test-cluster config: /tmp/kind-config.yaml + # Nodes stay NotReady until a CNI is installed, so don't wait here. + wait: "0" ignore_failed_clean: true + - name: Install Calico CNI (E2E NetworkPolicy enforcement) + if: ${{ steps.operator-image-existence-checker.outputs.OPERATOR_IMAGE_EXISTS == 'true' }} + run: ./hack/install-calico.sh + - name: Install Ingress Controller if: ${{ steps.operator-image-existence-checker.outputs.OPERATOR_IMAGE_EXISTS == 'true' }} run: | diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml index 5b8a5efbc..ef0a4e5e8 100644 --- a/.github/workflows/pr.yaml +++ b/.github/workflows/pr.yaml @@ -76,8 +76,15 @@ jobs: uses: helm/kind-action@a1b0e391336a6ee6713a0583f8c6240d70863de3 # v1.12.0 with: cluster_name: test-cluster + config: hack/kind-config.yaml + # Nodes stay NotReady until a CNI is installed, so don't wait here. + wait: "0" ignore_failed_clean: true + - name: Install Calico CNI (NetworkPolicy enforcement) + if: steps.changed-files.outputs.any_changed == 'true' + run: ./hack/install-calico.sh + - name: Run Controller if: steps.changed-files.outputs.any_changed == 'true' run: | diff --git a/hack/install-calico.sh b/hack/install-calico.sh new file mode 100755 index 000000000..49bc76f13 --- /dev/null +++ b/hack/install-calico.sh @@ -0,0 +1,60 @@ +#!/usr/bin/env bash +# +# Install Calico on a KinD (or any Kubernetes) cluster so that NetworkPolicies are +# actually enforced. +# +# KinD's default CNI (kindnet) does not implement NetworkPolicy enforcement, which +# means the NetworkPolicies shipped by the RHDH Operator are silently ignored and +# tests can pass even when the policies are wrong or incomplete. +# +# The KinD cluster must be created with: +# +# networking: +# disableDefaultCNI: true +# podSubnet: "192.168.0.0/16" # matches Calico's default IPv4 pool +# +# See hack/kind-config.yaml for a ready-to-use configuration. +# +# Usage: +# ./hack/install-calico.sh +# CALICO_VERSION=v3.31.7 ./hack/install-calico.sh +# +set -euo pipefail + +# The workflows in this repo create KinD clusters with kind v0.26 (Kubernetes 1.32), +# so pin Calico to a release tested against that Kubernetes version. +CALICO_VERSION="${CALICO_VERSION:-v3.31.7}" +WAIT_TIMEOUT="${WAIT_TIMEOUT:-300s}" +MANIFEST_URL="https://raw.githubusercontent.com/projectcalico/calico/${CALICO_VERSION}/manifests/calico.yaml" + +log() { + echo "[install-calico] $*" +} + +if kubectl get daemonset -n kube-system kindnet >/dev/null 2>&1; then + echo "[install-calico] ERROR: kindnet is still installed in this cluster." >&2 + echo "[install-calico] Recreate the cluster with networking.disableDefaultCNI=true (see hack/kind-config.yaml)." >&2 + exit 1 +fi + +log "Installing Calico ${CALICO_VERSION} (NetworkPolicy enforcement)..." + +manifest="$(mktemp)" +trap 'rm -f "${manifest}"' EXIT + +curl -fsSL --retry 5 --retry-all-errors --retry-delay 2 "${MANIFEST_URL}" -o "${manifest}" + +# Calico's manifest is large; server-side apply avoids the client-side +# "metadata.annotations: Too long" limitation. +kubectl apply --server-side --force-conflicts -f "${manifest}" + +log "Waiting for calico-node DaemonSet to roll out..." +kubectl -n kube-system rollout status daemonset/calico-node --timeout="${WAIT_TIMEOUT}" + +log "Waiting for calico-kube-controllers Deployment to roll out..." +kubectl -n kube-system rollout status deployment/calico-kube-controllers --timeout="${WAIT_TIMEOUT}" + +log "Waiting for all nodes to become Ready..." +kubectl wait --for=condition=Ready nodes --all --timeout="${WAIT_TIMEOUT}" + +log "Calico is ready; NetworkPolicies are now enforced." diff --git a/hack/kind-config.yaml b/hack/kind-config.yaml new file mode 100644 index 000000000..40c61ff37 --- /dev/null +++ b/hack/kind-config.yaml @@ -0,0 +1,13 @@ +# KinD cluster configuration with NetworkPolicy enforcement. +# +# kindnet (KinD's default CNI) does not enforce NetworkPolicies, so we disable it +# and install Calico after the cluster is created (see hack/install-calico.sh). +# +# The podSubnet must match Calico's default IPv4 pool (192.168.0.0/16). +apiVersion: kind.x-k8s.io/v1alpha4 +kind: Cluster +networking: + disableDefaultCNI: true + podSubnet: "192.168.0.0/16" +nodes: + - role: control-plane diff --git a/tests/e2e/README.md b/tests/e2e/README.md index b9afc182c..6c3257a33 100644 --- a/tests/e2e/README.md +++ b/tests/e2e/README.md @@ -75,8 +75,14 @@ To do so, you can: ##### `kind` +The CI Kind clusters are created with NetworkPolicy enforcement enabled (KinD's +default CNI, kindnet, ignores NetworkPolicies). To reproduce this locally, create +the cluster with [`hack/kind-config.yaml`](../../hack/kind-config.yaml) and install +Calico before running the tests: + ```shell -$ kind create cluster +$ kind create cluster --config hack/kind-config.yaml --wait 0 +$ ./hack/install-calico.sh $ make test-e2e \ BACKSTAGE_OPERATOR_TESTS_BUILD_IMAGES=true \ BACKSTAGE_OPERATOR_TESTS_PLATFORM=kind From 1baced617d2192e7a7cafd437c3c537803ab3f79 Mon Sep 17 00:00:00 2001 From: Armel Soro Date: Thu, 26 Nov 2026 18:24:30 +0100 Subject: [PATCH 2/2] fix(hack): restrict calico manifest download to HTTPS Pin the protocol on the curl call that fetches the Calico manifest so redirects cannot downgrade to an insecure scheme (SonarCloud shell:S6506). Assisted-by: OpenCode Signed-off-by: Armel Soro --- hack/install-calico.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hack/install-calico.sh b/hack/install-calico.sh index 49bc76f13..226bb2f39 100755 --- a/hack/install-calico.sh +++ b/hack/install-calico.sh @@ -42,7 +42,8 @@ log "Installing Calico ${CALICO_VERSION} (NetworkPolicy enforcement)..." manifest="$(mktemp)" trap 'rm -f "${manifest}"' EXIT -curl -fsSL --retry 5 --retry-all-errors --retry-delay 2 "${MANIFEST_URL}" -o "${manifest}" +curl --proto '=https' --proto-redir '=https' \ + -fsSL --retry 5 --retry-all-errors --retry-delay 2 "${MANIFEST_URL}" -o "${manifest}" # Calico's manifest is large; server-side apply avoids the client-side # "metadata.annotations: Too long" limitation.