Skip to content

Commit

Permalink
fix: add default deny acl (#1935)
Browse files Browse the repository at this point in the history
  • Loading branch information
lut777 committed Oct 8, 2022
1 parent de3d65c commit 95939ca
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 3 deletions.
55 changes: 52 additions & 3 deletions .github/workflows/build-x86-image.yaml
Expand Up @@ -394,6 +394,13 @@ jobs:
sudo chmod -R 777 /home/runner/.kube/
make e2e-underlay-single-nic
- name: Run networkpolicy E2E
working-directory: test/networkpolicy-cyclonus/
run: |
sudo cp -r /root/.kube/ /home/runner/.kube/
sudo chmod -R 777 /home/runner/.kube/
bash ./start-test.sh
- name: Cleanup
run: |
sh -c 'while :; do if [ $(kubectl get --no-headers subnet | wc -l) -eq 2 ]; then break; fi; sleep 5; done'
Expand Down Expand Up @@ -556,6 +563,13 @@ jobs:
sudo chmod -R 777 /home/runner/.kube/
make e2e
- name: Run networkpolicy E2E
working-directory: test/networkpolicy-cyclonus/
run: |
sudo cp -r /root/.kube/ /home/runner/.kube/
sudo chmod -R 777 /home/runner/.kube/
bash ./start-test.sh
- name: Cleanup
run: |
sh -c 'while :; do if [ $(kubectl get --no-headers subnet | wc -l) -eq 2 ]; then break; fi; sleep 5; done'
Expand All @@ -565,7 +579,7 @@ jobs:
needs: build-kube-ovn
name: ipv6-e2e
runs-on: ubuntu-20.04
timeout-minutes: 30
timeout-minutes: 45
steps:
- uses: actions/checkout@v3

Expand Down Expand Up @@ -627,6 +641,13 @@ jobs:
sudo chmod -R 777 /home/runner/.kube/
make e2e-ipv6
- name: Run networkpolicy E2E
working-directory: test/networkpolicy-cyclonus/
run: |
sudo cp -r /root/.kube/ /home/runner/.kube/
sudo chmod -R 777 /home/runner/.kube/
bash ./start-test.sh
- name: Cleanup
run: |
sh -c 'while :; do if [ $(kubectl get --no-headers subnet | wc -l) -eq 2 ]; then break; fi; sleep 5; done'
Expand Down Expand Up @@ -769,6 +790,13 @@ jobs:
sudo chmod -R 777 /home/runner/.kube/
make e2e-underlay-single-nic
- name: Run networkpolicy E2E
working-directory: test/networkpolicy-cyclonus/
run: |
sudo cp -r /root/.kube/ /home/runner/.kube/
sudo chmod -R 777 /home/runner/.kube/
bash ./start-test.sh
- name: Cleanup
run: |
sh -c 'while :; do if [ $(kubectl get --no-headers subnet | wc -l) -eq 2 ]; then break; fi; sleep 5; done'
Expand Down Expand Up @@ -856,6 +884,13 @@ jobs:
sudo chmod -R 777 /home/runner/.kube/
make e2e
- name: Run networkpolicy E2E
working-directory: test/networkpolicy-cyclonus/
run: |
sudo cp -r /root/.kube/ /home/runner/.kube/
sudo chmod -R 777 /home/runner/.kube/
bash ./start-test.sh
- name: Cleanup
run: |
sh -c 'while :; do if [ $(kubectl get --no-headers subnet | wc -l) -eq 2 ]; then break; fi; sleep 5; done'
Expand All @@ -865,7 +900,7 @@ jobs:
needs: build-kube-ovn
name: dual-stack-underlay-e2e-single-nic
runs-on: ubuntu-20.04
timeout-minutes: 30
timeout-minutes: 45
steps:
- uses: actions/checkout@v3

Expand Down Expand Up @@ -927,6 +962,13 @@ jobs:
sudo chmod -R 777 /home/runner/.kube/
make e2e-underlay-single-nic
- name: Run networkpolicy E2E
working-directory: test/networkpolicy-cyclonus/
run: |
sudo cp -r /root/.kube/ /home/runner/.kube/
sudo chmod -R 777 /home/runner/.kube/
bash ./start-test.sh
- name: Cleanup
run: |
sh -c 'while :; do if [ $(kubectl get --no-headers subnet | wc -l) -eq 2 ]; then break; fi; sleep 5; done'
Expand All @@ -952,7 +994,7 @@ jobs:
needs: build-kube-ovn
name: dual-stack-underlay-logical-gateway-e2e
runs-on: ubuntu-20.04
timeout-minutes: 30
timeout-minutes: 45
steps:
- uses: actions/checkout@v3

Expand Down Expand Up @@ -1014,6 +1056,13 @@ jobs:
sudo chmod -R 777 /home/runner/.kube/
make e2e
- name: Run networkpolicy E2E
working-directory: test/networkpolicy-cyclonus/
run: |
sudo cp -r /root/.kube/ /home/runner/.kube/
sudo chmod -R 777 /home/runner/.kube/
bash ./start-test.sh
- name: Cleanup
run: |
sh -c 'while :; do if [ $(kubectl get --no-headers subnet | wc -l) -eq 2 ]; then break; fi; sleep 5; done'
Expand Down
5 changes: 5 additions & 0 deletions pkg/controller/network_policy.go
Expand Up @@ -313,6 +313,11 @@ func (c *Controller) handleUpdateNp(key string) error {
klog.Errorf("failed to create ingress acls for np %s, %v", key, err)
return err
}
} else {
if err = c.ovnLegacyClient.CreateIngressACL(pgName, ingressAllowAsName, ingressExceptAsName, svcAsName, protocol, []netv1.NetworkPolicyPort{}, logEnable); err != nil {
klog.Errorf("failed to create default deny all ingress acls for np %s, %v", key, err)
return err
}
}
}
if len(np.Spec.Ingress) == 0 {
Expand Down
25 changes: 25 additions & 0 deletions test/networkpolicy-cyclonus/cyclonus.yaml
@@ -0,0 +1,25 @@
apiVersion: batch/v1
kind: Job
metadata:
name: cyclonus
namespace: kube-system
spec:
template:
spec:
restartPolicy: Never
containers:
- command:
- ./cyclonus
- generate
- --exclude=
- --include=upstream-e2e
- --retries=3
- --noisy=true
- --ignore-loopback=true
- --cleanup-namespaces=true
- --server-port=80
- --server-protocol=tcp
name: cyclonus
imagePullPolicy: IfNotPresent
image: mfenwick100/cyclonus:v0.5.0
serviceAccount: cyclonus
24 changes: 24 additions & 0 deletions test/networkpolicy-cyclonus/start-test.sh
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

set -eo pipefail
set -xv

# set up cyclonus
kubectl create clusterrolebinding cyclonus --clusterrole=cluster-admin --serviceaccount=kube-system:cyclonus
kubectl create sa cyclonus -n kube-system
kubectl create -f ./cyclonus.yaml

# don't fail on errors, so we can dump the logs.
set +e

time kubectl wait --for=condition=complete --timeout=60m -n kube-system job.batch/cyclonus
rc=$?

# grab the job logs
LOG_FILE=$(mktemp)
kubectl logs -n kube-system job.batch/cyclonus > "$LOG_FILE"
cat "$LOG_FILE"

# if 'failure' is in the logs, fail; otherwise succeed
cat "$LOG_FILE" | grep "failure" > /dev/null 2>&1 && rc=1
exit $rc

0 comments on commit 95939ca

Please sign in to comment.