You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+31-31Lines changed: 31 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,9 +19,9 @@ The following diagram illustrates the flow of a network packet from the kernel t
19
19
20
20
The key components of the architecture are:
21
21
22
-
***Dataplane Controller**: The dataplane/controller.go file contains the main controller that sets up NFQUEUE, intercepts packets, and orchestrates the policy evaluation process. It is responsible for creating the necessary nftables rules to redirect traffic. To avoid the performance penalty of sending all packets to userspace, the controller includes logic to only capture packets for pods that are targeted by at least one network policy.
23
-
***Policy Engine**: The networkpolicy/engine.go file defines the PolicyEngine, which manages a pipeline of PolicyEvaluator plugins. The engine is responsible for running each packet through the pipeline and making a final decision based on the verdicts returned by the evaluators.
24
-
***Pod Info Provider**: The podinfo/podinfo.go file provides an interface for retrieving pod information. It resolves a packet's IP address to a PodInfo protobuf type (pkg/api/kubenetworkpolicies.proto). This PodInfo object contains all the necessary information for evaluators to match policies, including the pod's name, labels, namespace, and associated node information.
22
+
***Dataplane Controller**: The `dataplane/controller.go` file contains the main controller that sets up NFQUEUE, intercepts packets, and orchestrates the policy evaluation process. It is responsible for creating the necessary nftables rules to redirect traffic. To avoid the performance penalty of sending all packets to userspace, the controller includes logic to only capture packets for pods that are targeted by at least one network policy.
23
+
***Policy Engine**: The `networkpolicy/engine.go` file defines the `PolicyEngine`, which manages a pipeline of `PolicyEvaluator` plugins. The engine is responsible for running each packet through the pipeline and making a final decision based on the verdicts returned by the evaluators.
24
+
***Pod Info Provider**: The `podinfo/podinfo.go` file provides an interface for retrieving pod information. It resolves a packet's IP address to a PodInfo protobuf type (`pkg/api/kubenetworkpolicies.proto`). This `PodInfo` object contains all the necessary information for evaluators to match policies, including the pod's name, labels, namespace, and associated node information.
25
25
***Policy Evaluators**: These are plugins that implement the PolicyEvaluator interface and contain the logic for a specific type of network policy. The project currently includes evaluators for AdminNetworkPolicy, BaselineAdminNetworkPolicy, and the standard Kubernetes NetworkPolicy.
26
26
27
27
Here is a diagram illustrating the interaction between these components:
@@ -32,7 +32,7 @@ Here is a diagram illustrating the interaction between these components:
32
32
33
33
The PolicyEvaluator interface is the core of the policy evaluation pipeline. Each evaluator is responsible for determining whether a packet should be allowed, denied, or passed to the next evaluator in the pipeline.
34
34
35
-
The interface is defined in pkg/networkpolicy/engine.go as follows:
35
+
The interface is defined in `pkg/networkpolicy/engine.go` as follows:
36
36
37
37
```go
38
38
typePolicyEvaluatorinterface {
@@ -44,23 +44,23 @@ type PolicyEvaluator interface {
44
44
45
45
The Verdict returned by each evaluator can be one of the following:
46
46
47
-
* VerdictAccept: The packet is allowed, and no further evaluators are consulted.
48
-
* VerdictDeny: The packet is denied, and no further evaluators are consulted.
49
-
* VerdictNext: The packet is passed to the next evaluator in the pipeline.
47
+
*`VerdictAccept`: The packet is allowed, and no further evaluators are consulted.
48
+
*`VerdictDeny`: The packet is denied, and no further evaluators are consulted.
49
+
*`VerdictNext`: The packet is passed to the next evaluator in the pipeline.
50
50
51
51
### How to Add a New PolicyEvaluator
52
52
53
-
Adding a new PolicyEvaluator is straightforward and involves the following steps:
53
+
Adding a new `PolicyEvaluator` is straightforward and involves the following steps:
54
54
55
-
1.**Create a new file** for your evaluator in the pkg/networkpolicy directory.
56
-
2.**Define a struct** for your evaluator that implements the PolicyEvaluator interface.
57
-
3.**Implement the Name method** to return a unique name for your evaluator.
58
-
4.**Implement the EvaluateIngress and EvaluateEgress methods** to define the logic for your policy.
59
-
5.**Register your new evaluator** in the PolicyEngine in cmd/main.go.
55
+
1.**Create a new file** for your evaluator in the `pkg/networkpolicy` directory.
56
+
2.**Define a struct** for your evaluator that implements the `PolicyEvaluator` interface.
57
+
3.**Implement the Name method** to return a unique name for your evaluator.
58
+
4.**Implement the EvaluateIngress and EvaluateEgress methods** to define the logic for your policy.
59
+
5.**Register your new evaluator** in the PolicyEngine in `cmd/main.go`.
60
60
61
61
#### Example: Creating an AllowListPolicy
62
62
63
-
Let's create a simple AllowListPolicy that only allows traffic from a predefined list of IP addresses.
63
+
Let's create a simple `AllowListPolicy` that only allows traffic from a predefined list of IP addresses.
64
64
65
65
1.**Create the file** pkg/networkpolicy/allowlistpolicy.go:
66
66
@@ -76,36 +76,36 @@ Let's create a simple AllowListPolicy that only allows traffic from a predefined
76
76
77
77
// AllowListPolicy is a simple policy that allows traffic only from a predefined list of IP addresses.
78
78
typeAllowListPolicystruct {
79
-
allowedIPs \[\]net.IP
79
+
allowedIPs []net.IP
80
80
}
81
81
82
82
// NewAllowListPolicy creates a new AllowListPolicy.
Admin Network Policies and Baseline Admin Network Policies features are controlled by `Values.adminNetworkPolicy` and
181
181
they are enabled by default. Disable them if needed in values.yaml or use `--set adminNetworkPolicy=false` when running
182
-
`helm install` command.
182
+
`helm install` command.
183
183
184
184
NOTE: the corresponding CRDs must be installed first.
185
185
@@ -229,7 +229,7 @@ Current implemented metrics are:
229
229
230
230
## Testing
231
231
232
-
See [TESTING](docs/testing/README.md)
232
+
See [TESTING](docs/testing/README.md)
233
233
234
234
There are two github workflows that runs e2e tests aginst the Kubernetes/Kubernetes Network Policy tests and the Network Policy API Working Group conformance tests.
0 commit comments