-
Notifications
You must be signed in to change notification settings - Fork 39
CNP: update docs to use CNP instead of ANP and BANP #333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,15 @@ | ||
| # Api Object Overview | ||
| # API Object Overview | ||
|
|
||
| Prior to the Network Policy API the original NetworkPolicy V1 Resource was the only | ||
| way for k8s users to apply security rules to their kubernetes workloads. One of the | ||
| main drawbacks to this API was that it was designed exclusively for use by the | ||
| Application Developer, although in reality it is used by many different cluster | ||
| personas, sometimes creating a complex web of objects to be maintained. In | ||
| Contrast, each resource in the Network Policy API is designed to be used by a | ||
| contrast, each resource in the Network Policy API is designed to be used by a | ||
| specific persona. | ||
|
|
||
| With the advent of the AdminNetworkPolicy and BaselineAdminNetworkPolicy | ||
| resources Cluster Admins will now have the ability to apply policy globally with | ||
| only a few simple policy objects. | ||
| With the advent of the ClusterNetworkPolicy resource Cluster Admins will now have | ||
| the ability to apply policy globally with only a few simple policy objects. | ||
|
|
||
| ## Roles and personas | ||
|
|
||
|
|
@@ -27,116 +26,108 @@ In this documentation we refer to three primary personas: | |
| Custom Resource Definitions (CRDs). Unqualified resource names below will | ||
| implicitly be in this API group. | ||
|
|
||
| Currently, there are two main objects in the Network Policy API resource model: | ||
| Currently, there is one main object in the Network Policy API resource model: | ||
|
|
||
| - **AdminNetworkPolicy (ANP)** | ||
|
|
||
| - **BaselineAdminNetworkPolicy (BANP)** | ||
| - **ClusterNetworkPolicy (CNP)** | ||
|
|
||
| The diagram below demonstrates how these new API objects interact with | ||
| each-other and existing NetworkPolicy Objects: | ||
|
|
||
|  | ||
| <img src="/images/CNP.drawio.svg" width="541" alt="Cluster Network Policy API model"> | ||
|
|
||
| ## General Notes | ||
|
|
||
| - Any well defined AdminNetworkPolicy rules should | ||
| - Any well-defined ClusterNetworkPolicy rules should | ||
| be read as-is, i.e. there will not be any implicit isolation effects for the Pods | ||
| selected by the AdminNetworkPolicy, as opposed to what NetworkPolicy rules imply. | ||
| selected by the ClusterNetworkPolicy, as opposed to what NetworkPolicy rules imply. | ||
|
|
||
| - We now have multiple API versions, see the [ClusterNetworkPolicy blog post](blog/posts/ClusterNetworkPolicy.md) for more details | ||
|
|
||
| ## The ClusterNetworkPolicy Resource | ||
|
|
||
| - As of `v1alpha1` of this API we focus primarily on E/W cluster traffic and | ||
| do not address N/S (Ingress/Egress) use cases. However this is an issue the community | ||
| would like to keep thinking about during further iterations, and a tracking issue | ||
| can be found/ commented on here ---> [issue #28](https://github.com/kubernetes-sigs/network-policy-api/issues/28) | ||
| The ClusterNetworkPolicy (CNP) resource will help administrators set cluster-wide security | ||
| rules for the cluster, which are evaluated before or after the NetworkPolicies defined by the | ||
| namespace owners. | ||
|
|
||
| ## The AdminNetworkPolicy Resource | ||
| ### Tiers | ||
|
|
||
| The AdminNetworkPolicy (ANP) resource will help administrators set strict security | ||
| rules for the cluster, i.e. a developer CANNOT override these rules by creating | ||
| NetworkPolicies that apply to the same workloads as the AdminNetworkPolicy. | ||
| Tier is used as the top-level grouping for network policy prioritization. | ||
|
|
||
| ### AdminNetworkPolicy Actions | ||
| Policy tiers are evaluated in the following order: | ||
| * `Admin` tier | ||
| * NetworkPolicy tier | ||
| * `Baseline` tier | ||
|
|
||
| ClusterNetworkPolicy can use 2 of these tiers: `Admin` and `Baseline`. | ||
|
|
||
| The `Admin` tier will help administrators set strict security rules for the cluster, | ||
| i.e. a developer CANNOT override these rules by creating NetworkPolicies that apply | ||
| to the same workloads as the ClusterNetworkPolicy. | ||
|
|
||
| The `Baseline` tier will allow administrators to set baseline security rules that | ||
| describe default connectivity for cluster workloads, which CAN be overridden by | ||
| developer NetworkPolicies if needed. | ||
| The major use case for `Baseline` tier is the ability to flip the [default security stance of the | ||
| cluster](user-stories.md#story-5-cluster-wide-default-guardrails). | ||
|
|
||
| ### Actions | ||
|
|
||
| Unlike the NetworkPolicy resource in which each rule represents an allowed | ||
| traffic, AdminNetworkPolicies will enable administrators to set `Pass`, | ||
| `Deny` or `Allow` as the action of each rule. AdminNetworkPolicy rules should | ||
| traffic, ClusterNetworkPolicy will enable administrators to set `Pass`, | ||
| `Deny` or `Accept` as the action of each rule. ClusterNetworkPolicy rules should | ||
| be read as-is, i.e. there will not be any implicit isolation effects for the Pods | ||
| selected by the AdminNetworkPolicy, as opposed to implicit deny NetworkPolicy rules imply. | ||
|
|
||
| - **Pass**: Traffic that matches a `Pass` rule will skip all further rules from all | ||
| numbered ANPs and instead be enforced by the K8s NetworkPolicies. | ||
| If there is no K8s NetworkPolicy of BaselineAdminNetworkPolicy rule match | ||
| traffic will be governed by the implementation. For most implementations, | ||
| this means "allow", but there may be implementations which have their own policies | ||
| outside of the standard Kubernetes APIs. | ||
| - **Deny**: Traffic that matches a `Deny` rule will be dropped. | ||
| - **Allow**: Traffic that matches an `Allow` rule will be allowed. | ||
|
|
||
| AdminNetworkPolicy `Deny` rules are useful for administrators to explicitly | ||
| selected by the ClusterNetworkPolicy, as opposed to implicit deny NetworkPolicy rules imply. | ||
|
|
||
| - **Accept**: Accepts the selected traffic, allowing it into | ||
| the destination. No further ClusterNetworkPolicy or | ||
| NetworkPolicy rules will be processed. | ||
|
|
||
| - **Deny**: Drops the selected traffic. No further | ||
| ClusterNetworkPolicy or NetworkPolicy rules will be | ||
| processed. | ||
|
|
||
| - **Pass**: Skips all further ClusterNetworkPolicy rules in the | ||
| current tier for the selected traffic, and passes | ||
| evaluation to the next tier. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Technically 'NetworkPolicy' is not the "next tier", not sure if we want to call it out here. I know that we have the diagram above which illustrates the policy evaluation model, but I don't want people to think that once we're done with "Admin" tier rules we move on to the "Baseline" tier.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it could be explained either way (it's based on the definition of terms etc), but we should be consistent across all the docs to avoid confusion. Either the notion of tiers is just a convenient way to refer 1) to Admin -> NP -> Baseline or 2) we are more strict and say only Admin and Baseline are tiers. I think in the code comments, it is closer to 1)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point, I think this part is confusing because I didn't update the tiers section properly, let me update it with the API doc |
||
|
|
||
| ClusterNetworkPolicy `Deny` rules are useful for administrators to explicitly | ||
| block traffic with malicious in-cluster clients, or workloads that pose security risks. | ||
| Those traffic restrictions can only be lifted once the `Deny` rules are deleted, | ||
| modified by the admin, or overridden by a higher priority rule. | ||
|
|
||
| On the other hand, the `Allow` rules can be used to call out traffic in the cluster | ||
| On the other hand, the `Accept` rules can be used to call out traffic in the cluster | ||
| that needs to be allowed for certain components to work as expected (egress to | ||
| CoreDNS for example). This traffic should not be blocked when developers apply | ||
| NetworkPolicy to their Namespaces which isolates the workloads. | ||
|
|
||
| AdminNetworkPolicy `Pass` rules allow an admin to delegate security posture for | ||
| ClusterNetworkPolicy `Pass` rules in the `Admin` tier allow an admin to delegate security posture for | ||
| certain traffic to the Namespace owners by overriding any lower precedence Allow | ||
| or Deny rules. For example, intra-tenant traffic management can be delegated to tenant | ||
| admins explicitly with the use of `Pass` rules. More specifically traffic selected | ||
| by a `Pass` rule will skip any further ANP rule selection, be evaluated against | ||
| any well defined NetworkPolicies, and if not terminated ultimately be evaluated against any | ||
| BaselineAdminNetworkPolicies. | ||
| or Deny rules. For example, intra-namespace traffic management can be delegated to namespace | ||
| admins explicitly with the use of `Pass` rules. More specifically traffic selected by a `Pass` rule | ||
| will skip any lower precedence `Admin` tier rules and proceed to be evaluated by `NetworkPolicy` and | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this feels like a bit of a run-on sentence for me
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like chopping it at the |
||
| `Baseline` tier policies. When the `Pass` action is matched at the `Admin` tier, `NetworkPolicy` will | ||
| apply next or if there is no `NetworkPolicy` match, `Baseline` policies will be evaluated. | ||
|
|
||
| ### AdminNetworkPolicy Priorities | ||
| ### Priorities | ||
|
|
||
| Integer priority values were added to the AdminNetworkPolicy API to allow Cluster | ||
| Admins to express direct and intentional ordering between various ANP Objects. | ||
| The `Priority` field in the ANP spec is defined as an integer value | ||
| within the range 0 to 1000 where rules with lower priority values have higher | ||
| precedence. Regardless of priority value all ANPs have higher precedence than | ||
| any defined NetworkPolicy or BaselineAdminNetworkPolicy objects. | ||
| Integer priority values were added to the ClusterNetworkPolicy API to allow Cluster | ||
| Admins to express direct and intentional ordering between various CNP Objects. | ||
| The `Priority` field in the CNP spec is defined as a non-negative integer value | ||
| where rules with lower priority values have higher precedence, and are checked | ||
| before policies with higher priority values in the same tier. | ||
|
|
||
| ### AdminNetworkPolicy Rules | ||
| ### Rules | ||
|
|
||
| Each ANP should define at least one `Ingress` or `Egress` relevant in-cluster traffic flow | ||
| Each CNP should define at least one `Ingress` or `Egress` relevant in-cluster traffic flow | ||
| along with the associated Action that should occur. In each `gress` rule the user | ||
| should AT THE MINIMUM define an `Action`, and at least one `AdminNetworkPolicyPeer`. | ||
| should AT THE MINIMUM define an `Action`, and at least one `ClusterNetworkPolicyPeer`. | ||
| Optionally the user may also define select `Ports` to filter traffic on and also | ||
| a name for each rule to make management and reporting easier for Admins. | ||
|
|
||
| ### AdminNetworkPolicy Status | ||
| ### Status | ||
|
|
||
| For `v1alpha1` of this API the ANP status field is simply defined as a list of | ||
| For `v1alpha2` of this API the ANP status field is simply defined as a list of | ||
| [`metav1.condition`](https://github.com/kubernetes/apimachinery/blob/v0.25.0/pkg/apis/meta/v1/types.go#L1464)s. Currently there are no rules as to what these conditions should display, | ||
| and it is up to each implementation to report what they see fit. For further | ||
| API iterations the community may consider standardizing these conditions based on | ||
| the usefulness they provide for various implementors. | ||
|
|
||
| ## The BaselineAdminNetworkPolicy Resource | ||
|
|
||
| The BaselineAdminNetworkPolicy (BANP) resource will allow administrators to | ||
| set baseline security rules that describes default connectivity for cluster workloads, | ||
| which CAN be overridden by developer NetworkPolicies if needed. The major use case | ||
| BANPs solve is the ability to flip the [default security stance of the | ||
| cluster](user-stories.md#story-5-cluster-wide-default-guardrails). | ||
|
|
||
| ### BaselineAdminNetworkPolicy Rule Actions | ||
|
|
||
| BaselineAdminNetworkPolicies allow administrators to define two distinct actions | ||
| for each well defined rule, `Allow` and `Deny`. | ||
|
|
||
| - **Deny**: Traffic that matches a `Deny` rule will be dropped. | ||
| - **Allow**: Traffic that matches an `Allow` rule will be allowed. | ||
|
|
||
| ### BaselineAdminNetworkPolicy Rules | ||
|
|
||
| BANP Rules are defined and behave the same (Except for the `Pass` action) as [ANP | ||
| rules](#adminnetworkpolicy-rules). | ||
|
|
||
| ### BaselineAdminNetworkPolicy Status | ||
|
|
||
| The BANP `status` field follows the same constructs as used by the | ||
| [AdminNetworkPolicy.Status](#adminnetworkpolicy-status) field. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| --- | ||
| date: 2025-10-09 | ||
| authors: | ||
| - npinaeva | ||
| --- | ||
|
|
||
| # API update for v1alpha2: `ClusterNetworkPolicy` replaces `AdminNetworkPolicy` and `BaselineAdminNetworkPolicy` | ||
|
|
||
| We have merged `v1alpha1.AdminNetworkPolicy` and `v1alpha1.BaselineAdminNetworkPolicy` into a single API in `v1alpha2.ClusterNetworkPolicy`. | ||
|
|
||
| AdminNetworkPolicy (ANP) and BaselineAdminNetworkPolicy (BANP) were the first APIs created by the Network Policy API working group. | ||
| They are `v1alpha1` resources, which means that they are not stable and are mostly used to get early feedback on the API design from | ||
| the community. | ||
|
|
||
| If you have seen these APIs, you probably have noticed that they are quite similar. If you have written controllers to reconcile these resources, | ||
| you probably also found some code duplication. The original reason for having two separate resources was just a lack of | ||
| use cases for multiple instances of BANP, which made it a singleton. However, with more feedback from the community, we have realized that | ||
| those use cases do exist and that having two separate resources adds more burden than value. | ||
|
|
||
| <!-- more --> | ||
|
|
||
| ### What has changed | ||
|
|
||
| As a reminder, here is how the original Admin Network Policy API Model looked like: | ||
|
|
||
|  | ||
|
|
||
| The model stays the same with the new API, the only difference is that evaluation order is now defined by the `tier` field | ||
| and not by the resource type. `AdminNetworkPolicy` becomes a `ClusterNetworkPolicy` with `tier=Admin` and | ||
| `BaselineAdminNetworkPolicy` becomes a `ClusterNetworkPolicy` with `tier=Baseline`. | ||
|
|
||
| <img src="/images/CNP.drawio.svg" width="541" alt="Cluster Network Policy API model"> | ||
|
|
||
| Other changes bring the functionality of `BaselineAdminNetworkPolicy` to parity with `AdminNetworkPolicy`. This includes: | ||
|
|
||
| - Allowing multiple `ClusterNetworkPolicy` resources with `tier=Baseline` by using the same `priority` field as for `tier=Admin`. | ||
| - Supporting `Pass` action in `ClusterNetworkPolicy` with `tier=Baseline` to allow skipping all further rules in the `Baseline` tier. | ||
| - Supporting `domainNames` matching for `egress` rules in `ClusterNetworkPolicy` with `tier=Baseline`. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is experimental channel
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you mean I should add a note saying that domainNames is an experimental feature? |
||
|
|
||
| The [enhancement proposal](https://github.com/kubernetes-sigs/network-policy-api/pull/289) has some more details for those interested. | ||
|
|
||
| ### Examples | ||
|
|
||
| Let's take a look at some examples based on the original [user stories](../../user-stories.md). | ||
|
|
||
| #### Story 1:Deny traffic at a cluster level | ||
|
|
||
| To deny all traffic at the cluster level, the following `AdminNetworkPolicy` was used: | ||
|
|
||
| ```yaml | ||
| apiVersion: policy.networking.k8s.io/v1alpha1 | ||
| kind: AdminNetworkPolicy | ||
| metadata: | ||
| name: cluster-wide-deny-example | ||
| spec: | ||
| priority: 10 | ||
| subject: | ||
| namespaces: | ||
| matchLabels: | ||
| kubernetes.io/metadata.name: sensitive-ns | ||
| ingress: | ||
| - action: Deny | ||
| from: | ||
| - namespaces: | ||
| namespaceSelector: {} | ||
| name: select-all-deny-all | ||
| ``` | ||
|
|
||
| which looks like this with the new `ClusterNetworkPolicy` API: | ||
|
|
||
| ```yaml | ||
| --8<-- "user-story-examples/user-story-1.yaml" | ||
| ``` | ||
|
|
||
| #### Story 5: Cluster Wide Default Guardrails | ||
|
|
||
| To deny all traffic in a cluster by default (in an overridable manner), the following `BaselineAdminNetworkPolicy` was used: | ||
|
|
||
| ```yaml | ||
| apiVersion: policy.networking.k8s.io/v1alpha1 | ||
| kind: BaselineAdminNetworkPolicy | ||
| metadata: | ||
| name: default | ||
| spec: | ||
| subject: | ||
| namespaces: {} | ||
| ingress: | ||
| - action: Deny # zero-trust cluster default security posture | ||
| from: | ||
| - namespaces: | ||
| namespaceSelector: {} | ||
| ``` | ||
|
|
||
| which looks like this with the new `ClusterNetworkPolicy` API: | ||
|
|
||
| ```yaml | ||
| --8<-- "user-story-examples/user-story-5.yaml" | ||
| ``` | ||
|
|
||
| ### Migration | ||
|
|
||
| We appreciate all early adopters of the `AdminNetworkPolicy` and `BaselineAdminNetworkPolicy` APIs. | ||
| You can continue using them at their latest released version [v0.1.7](https://github.com/kubernetes-sigs/network-policy-api/releases/tag/v0.1.7) | ||
| At the same time, we encourage you to plan your migration to the new `ClusterNetworkPolicy` API, which can be done once its first version is available. | ||
| We plan to base our `beta` release on the `ClusterNetworkPolicy` API. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you should have two priority arrows and number 1 - 1000 on each. This diagram makes it seem like the priority # extends across all of the tiers, which it does not. Also, the NetworkPolicy tier does not have priority numbers
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point, I am thinking if just leaving Evaluated first and Evaluated last is good enough? Or maybe replace Priority with "evaluation order"?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SG |
Uh oh!
There was an error while loading. Please reload this page.