SV-257514r1208195_rule
V-257514
SRG-APP-000038-CTR-000105
CNTR-OS-000100
CAT II
10
Add a network policy to an existing project namespace by performing the following steps:
1. Create <YOURFILE>.yaml and insert the desired resource network policy content. The following is an example resource quota definition:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-from-same-namespace
namespace: <NAMESPACE>
spec:
podSelector: {}
ingress:
- from:
- podSelector: {}
2. Apply the network policy definition to the project namespace by executing the following:
oc apply -f <YOURFILE>.yaml -n <NAMESPACE>
Details regarding the configuration of resource network policy can be reviewed at https://docs.openshift.com/container-platform/4.12/networking/network_policy/about-network-policy.html.
Where OpenShift Virtualization is enabled:
Enable MAC-spoof filtering per the deployed networking provider instructions.
Instructions for Bridge CNI and SR-IOV CNI:
https://docs.redhat.com/en/documentation/openshift_container_platform/4.18/html/virtualization/networking#virt-creating-linux-bridge-nad-cli_virt-connecting-vm-to-linux-bridge
https://docs.redhat.com/en/documentation/openshift_container_platform/4.18/html/virtualization/networking#nw-sriov-network-attachment_virt-connecting-vm-to-sriov
Verify each user namespace has a network policy by executing the following:
for ns in $(oc get namespaces -ojson | jq -r '.items[] | select((.metadata.name | startswith('openshift') | not) and (.metadata.name | startswith('kube-') | not) and .metadata.name != 'default') | .metadata.name '); do oc get networkpolicy -n$ns; done
If the above returns any lines saying "No resources found in <PROJECT> namespace.", this is a finding. Empty output is not a finding.
Where OpenShift Virtualization is enabled:
For SR-IOV, use the following command:
$ oc get sriovnetwork -o json | jq ".items[].spec.spoofChk"
If these results show the setting is off for any network, this is a finding.
For Bridge CNI, use the following command:
$ oc get networkattachmentdefinition -o json | jq
".items[].spec.config.macspoofchk"
If these results show the setting is false for any network, this is a finding.
V-257514
False
CNTR-OS-000100
Verify each user namespace has a network policy by executing the following:
for ns in $(oc get namespaces -ojson | jq -r '.items[] | select((.metadata.name | startswith('openshift') | not) and (.metadata.name | startswith('kube-') | not) and .metadata.name != 'default') | .metadata.name '); do oc get networkpolicy -n$ns; done
If the above returns any lines saying "No resources found in <PROJECT> namespace.", this is a finding. Empty output is not a finding.
Where OpenShift Virtualization is enabled:
For SR-IOV, use the following command:
$ oc get sriovnetwork -o json | jq ".items[].spec.spoofChk"
If these results show the setting is off for any network, this is a finding.
For Bridge CNI, use the following command:
$ oc get networkattachmentdefinition -o json | jq
".items[].spec.config.macspoofchk"
If these results show the setting is false for any network, this is a finding.
M
5547