Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions .github/workflows/nightly-postgresql-upgrade-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ jobs:
cat <<EOF > "$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:
Expand All @@ -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"

Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/nightly-upgrade-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ jobs:
cat <<EOF > /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:
Expand Down Expand Up @@ -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: |
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -120,6 +127,9 @@ jobs:
cat <<EOF > /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:
Expand All @@ -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: |
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
60 changes: 60 additions & 0 deletions hack/install-calico.sh
Original file line number Diff line number Diff line change
@@ -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}"

Check warning on line 45 in hack/install-calico.sh

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Not enforcing HTTPS here might allow for redirections to insecure websites. Make sure it is safe here.

See more on https://sonarcloud.io/project/issues?id=redhat-developer_rhdh-operator&issues=AaIKQdBWkR43N7b3xbV8&open=AaIKQdBWkR43N7b3xbV8&pullRequest=4172
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed

# 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."
13 changes: 13 additions & 0 deletions hack/kind-config.yaml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 additions & 1 deletion tests/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading