<commit_before>// Module included in the following assemblies:
//
// * networking/network_policy/default-network-policy.adoc
// * networking/configuring-networkpolicy.adoc
// * post_installation_configuration/network-configuration.adoc

[id="nw-networkpolicy-project-defaults_{context}"]
= Adding network policies to the new project template

As a cluster administrator, you can add network policies to the default template for new projects.
{product-title} will automatically create all the `NetworkPolicy` objects specified in the template in the project.

.Prerequisites

* Your cluster uses a default CNI network provider that supports `NetworkPolicy` objects, such as the OpenShift SDN network provider with `mode: NetworkPolicy` set. This mode is the default for OpenShift SDN.
* You installed the OpenShift CLI (`oc`).
* You must log in to the cluster with a user with `cluster-admin` privileges.
* You must have created a custom default project template for new projects.

.Procedure

. Edit the default template for a new project by running the following command:
+
[source,terminal]
----
$ oc edit template <project_template> -n openshift-config
----
+
Replace `<project_template>` with the name of the default template that you
configured for your cluster. The default template name is `project-request`.

. In the template, add each `NetworkPolicy` object as an element to the `objects` parameter. The `objects` parameter accepts a collection of one or more objects.
+
In the following example, the `objects` parameter collection includes several `NetworkPolicy` objects.
+
[IMPORTANT]
====
For the OVN-Kubernetes network provider plug-in, when the Ingress Controller is configured to use the `HostNetwork` endpoint publishing strategy, there is no supported way to apply network policy so that ingress traffic is allowed and all other traffic is denied.
====
+
[source,yaml]
----
objects:
- 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:<commit_msg>remove warning about OVN-Kubernetes and HostNetwork<commit_after>// Module included in the following assemblies:
//
// * networking/network_policy/default-network-policy.adoc
// * networking/configuring-networkpolicy.adoc
// * post_installation_configuration/network-configuration.adoc

[id="nw-networkpolicy-project-defaults_{context}"]
= Adding network policies to the new project template

As a cluster administrator, you can add network policies to the default template for new projects.
{product-title} will automatically create all the `NetworkPolicy` objects specified in the template in the project.

.Prerequisites

* Your cluster uses a default CNI network provider that supports `NetworkPolicy` objects, such as the OpenShift SDN network provider with `mode: NetworkPolicy` set. This mode is the default for OpenShift SDN.
* You installed the OpenShift CLI (`oc`).
* You must log in to the cluster with a user with `cluster-admin` privileges.
* You must have created a custom default project template for new projects.

.Procedure

. Edit the default template for a new project by running the following command:
+
[source,terminal]
----
$ oc edit template <project_template> -n openshift-config
----
+
Replace `<project_template>` with the name of the default template that you
configured for your cluster. The default template name is `project-request`.

. In the template, add each `NetworkPolicy` object as an element to the `objects` parameter. The `objects` parameter accepts a collection of one or more objects.
+
In the following example, the `objects` parameter collection includes several `NetworkPolicy` objects.
+
[source,yaml]
----
objects:
- 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:
{'fraction_non_alphanumeric': 0.08067680235409515, 'fraction_numerical': 0.00196174595389897, 'mean_word_length': 4.4532085561497325, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '245288', 'n_tokens_mistral': 1071, 'n_tokens_neox': 1039, 'n_words': 467}