|
| 1 | +// Module included in the following assemblies: |
| 2 | +// |
| 3 | +// * networking/ovn-k-network-policy.adoc |
| 4 | + |
| 5 | +:_mod-docs-content-type: Concept |
| 6 | +[id="BaselineAdminNetworkPolicy"_{context}"] |
| 7 | += BaselineAdminNetworkPolicy |
| 8 | +
|
| 9 | +`BaselineAdminNetworkPolicy` (BANP) is a cluster-scoped custom resource definition (CRD). As a {product-title} administrator, you can use BANP to setup and enforce optional baseline network policy rules that are overridable by users using `NetworkPolicy` objects if need be. Rule actions for BANP are `allow` or `deny`. |
| 10 | +
|
| 11 | +The `BaselineAdminNetworkPolicy` resource is a cluster singleton object that can be used as a guardrail policy incase a passed traffic policy does not match any `NetworkPolicy` objects in the cluster. A BANP can also be used as a default security model that provides guardrails that intra-cluster traffic is blocked by default and a user will need to use `NetworkPolicy` objects to allow known traffic. You must use `default` as the name when creating a BANP resource. |
| 12 | +
|
| 13 | +A BANP allows administrators to specify: |
| 14 | +
|
| 15 | +* A `subject` that consists of a set of namespaces or namespace. |
| 16 | +
|
| 17 | +* A list of ingress rules to be applied for all ingress traffic towards the `subject`. |
| 18 | +
|
| 19 | +* A list of egress rules to be applied for all egress traffic from the `subject`. |
| 20 | +
|
| 21 | +[NOTE] |
| 22 | +==== |
| 23 | +`BaselineAdminNetworkPolicy` is a `TechnologyPreviewNoUpgrade` feature that can be enabled on test clusters that are not in production. |
| 24 | +==== |
| 25 | +
|
| 26 | +[discrete] |
| 27 | +[id="baselineddminnetworkpolicy-example_{context}"] |
| 28 | +== BaselineAdminNetworkPolicy example |
| 29 | + |
| 30 | + |
| 31 | +.Example YAML file for BANP |
| 32 | +[%collapsible] |
| 33 | +==== |
| 34 | +[source,yaml] |
| 35 | +---- |
| 36 | +apiVersion: policy.networking.k8s.io/v1alpha1 |
| 37 | +kind: BaselineAdminNetworkPolicy |
| 38 | +metadata: |
| 39 | + name: default <1> |
| 40 | +spec: |
| 41 | + subject: |
| 42 | + namespaces: |
| 43 | + matchLabels: |
| 44 | + kubernetes.io/metadata.name: example.name <2> |
| 45 | + ingress: <3> |
| 46 | + - name: "deny-all-ingress-from-tenant-1" <4> |
| 47 | + action: "Deny" |
| 48 | + from: |
| 49 | + - pods: |
| 50 | + namespaces: |
| 51 | + namespaceSelector: |
| 52 | + matchLabels: |
| 53 | + custom-banp: tenant-1 <5> |
| 54 | + podSelector: |
| 55 | + matchLabels: |
| 56 | + custom-banp: tenant-1 <6> |
| 57 | + egress: |
| 58 | + - name: "allow-all-egress-to-tenant-1" |
| 59 | + action: "Allow" |
| 60 | + to: |
| 61 | + - pods: |
| 62 | + namespaces: |
| 63 | + namespaceSelector: |
| 64 | + matchLabels: |
| 65 | + custom-banp: tenant-1 |
| 66 | + podSelector: |
| 67 | + matchLabels: |
| 68 | + custom-banp: tenant-1 |
| 69 | +---- |
| 70 | +<1> The policy name must be `default` because BANP is a singleton object. |
| 71 | +<2> Specify the namespace to apply the ANP to. |
| 72 | +<3> BANP have both ingress and egress rules. BANP rules for `spec.ingress` and `spec.egress` fields accepts values of `Deny` and `Allow` for the `action` field. |
| 73 | +<4> Specify a name for the `ingress.name` |
| 74 | +<5> Specify the namespaces to select the pods from to apply the BANP resource. |
| 75 | +<6> Specify `podSelector.matchLabels` name of the pods to apply the BANP resource. |
| 76 | +==== |
| 77 | + |
| 78 | + |
| 79 | +[discrete] |
| 80 | +[id="BaselineAdminNetworkPolicy-default-deny-example"_{context}] |
| 81 | +== BaselineAdminNetworkPolicy Deny example |
| 82 | +The following BANP singleton ensures that the administrator has set up a default deny policy for all ingress monitoring traffic coming into the tenants at `internal` security level. When combined with the "AdminNetworkPolicy Pass example", this deny policy acts as a guardrail policy for all ingress traffic that is passed by the ANP `pass-monitoring` policy. |
| 83 | + |
| 84 | +.Example YAML file for a guardrail `Deny` rule |
| 85 | +[%collapsible] |
| 86 | +==== |
| 87 | +[source,yaml] |
| 88 | +---- |
| 89 | +apiVersion: policy.networking.k8s.io/v1alpha1 |
| 90 | +kind: BaselineAdminNetworkPolicy |
| 91 | +metadata: |
| 92 | + name: default |
| 93 | +spec: |
| 94 | + subject: |
| 95 | + namespaces: |
| 96 | + matchLabels: |
| 97 | + security: internal |
| 98 | + ingress: |
| 99 | + - name: "deny-ingress-from-monitoring" |
| 100 | + action: "Deny" |
| 101 | + from: |
| 102 | + - namespaces: |
| 103 | + namespaceSelector: |
| 104 | + matchLabels: |
| 105 | + kubernetes.io/metadata.name: monitoring |
| 106 | +# ... |
| 107 | +---- |
| 108 | +==== |
| 109 | + |
| 110 | +You can use an `AdminNetworkPolicy` resource with a `Pass` value for the `action` field in conjunction with the `BaselineAdminNetworkPolicy` resource to create a multi-tenant policy. This multi-tenant policy allows one tenant to collect monitoring data on their application while simultaneously not collecting data from a second tenant. |
| 111 | + |
| 112 | +As an administrator, if you apply both the "AdminNetworkPolicy `Pass` action example" and the "BaselineAdminNetwork Policy `Deny` example", tenants are then left with the ability to choose to create a `NetworkPolicy` resource that will be evaluated before the BANP. |
| 113 | + |
| 114 | +For example, Tenant 1 can set up the following `NetworkPolicy` resource to monitor ingress traffic: |
| 115 | + |
| 116 | +.Example `NetworkPolicy` |
| 117 | +[%collapsible] |
| 118 | +==== |
| 119 | +[source,yaml] |
| 120 | +---- |
| 121 | +apiVersion: networking.k8s.io/v1 |
| 122 | +kind: NetworkPolicy |
| 123 | +metadata: |
| 124 | + name: allow-monitoring |
| 125 | + namespace: tenant 1 |
| 126 | +spec: |
| 127 | + podSelector: |
| 128 | + policyTypes: |
| 129 | + - Ingress |
| 130 | + ingress: |
| 131 | + - from: |
| 132 | + - namespaceSelector: |
| 133 | + matchLabels: |
| 134 | + kubernetes.io/metadata.name: monitoring |
| 135 | +# ... |
| 136 | +---- |
| 137 | +==== |
| 138 | + |
| 139 | +In this scenario, Tenant 1's policy would be evaluated after the "AdminNetworkPolicy `Pass` action example" and before the "BaselineAdminNetwork Policy `Deny` example", which denies all ingress monitoring traffic coming into tenants with `security` level `internal`. With Tenant 1's `NetworkPolicy` object in place, they will be able to collect data on their application. Tenant 2, however, who does not have any `NetworkPolicy` objects in place, will not be able to collect data. As an administrator, you have not by default monitored internal tenants, but instead, you created a BANP that allows tenants to use `NetworkPolicy` objects to override the default behavior of your BANP. |
| 140 | + |
0 commit comments