Check
Check for Network Policy. Verify a default project template is defined by executing the following:
oc get project.config.openshift.io/cluster -o jsonpath="{.spec.projectRequestTemplate.name}"
If no project request template is in use by the project config, this is a finding.
Verify the project request template creates a Network Policy:
oc get templates/
-n openshift-config -o jsonpath="{.objects[?(.kind=='NetworkPolicy')]}{'\n'}"
Replace with the name of the project request template returned from the earlier query. If the project template is not defined, or there are no Network Policy definitions in it, this is a finding.
Fix
Configure a default network policy as necessary to protect the flow of information by performing the following steps:
1. Create a bootstrap project template (if not already created) by executing the following:
oc adm create-bootstrap-project-template -o yaml > template.yaml
2. Edit the template and add Network Policy object definitions before the parameters section. For example, the following section defines two policies: one to allow requests from the same namespace and one to allow from the OpenShift ingress routing service.
- apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-from-same-namespace
spec:
podSelector:
ingress:
- from:
- podSelector: {}
- apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-from-openshift-ingress
spec:
ingress:
- from:
- namespaceSelector:
matchLabels:
network.openshift.io/policy-group: ingress
podSelector: {}
policyTypes:
- Ingress
parameters:
3. Apply the project template to the cluster by executing the following:
oc create -f template.yaml -n openshift-config
4. Set the default cluster project request template by executing the following:
oc patch project.config.openshift.io/cluster --type=merge -p '{"spec":{"projectRequestTemplate":{"name": "
"}}}'
For additional information regarding network policies, refer to https://docs.openshift.com/container-platform/4.8/networking/network_policy/about-network-policy.html.