<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Concepts on Kubernetes Network Policies</title><link>https://kube-network-policies.sigs.k8s.io/docs/concepts/</link><description>Recent content in Concepts on Kubernetes Network Policies</description><generator>Hugo</generator><language>en-us</language><atom:link href="https://kube-network-policies.sigs.k8s.io/docs/concepts/index.xml" rel="self" type="application/rss+xml"/><item><title>Architecture Overview</title><link>https://kube-network-policies.sigs.k8s.io/docs/concepts/architecture/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kube-network-policies.sigs.k8s.io/docs/concepts/architecture/</guid><description>&lt;p>The &lt;code>kube-network-policies&lt;/code> project is designed to enforce Kubernetes network policies by intercepting and evaluating network packets in userspace. This is achieved by using &lt;code>NFQUEUE&lt;/code> to redirect packets to the controller, which then decides whether to allow or deny them based on a pipeline of policy evaluators.&lt;/p>
&lt;h2 id="packet-flow">Packet Flow&lt;/h2>
&lt;p>The following diagram illustrates the flow of a network packet from the Linux kernel to the userspace controller and back:&lt;/p>
&lt;pre class="mermaid">graph TD
 Packet[Incoming/Outgoing Packet] --&amp;gt; Kernel[Linux Kernel]
 Kernel --&amp;gt;|nftables rule matches| NFQ[NFQUEUE]
 NFQ --&amp;gt;|Intercepted| Controller[Dataplane Controller]
 Controller --&amp;gt;|Evaluate packet| Engine[Policy Engine]
 Engine --&amp;gt;|Query Pod Info| PIP[Pod Info Provider]
 Engine --&amp;gt;|Process through| Pipeline[Policy Evaluators Pipeline]
 Pipeline --&amp;gt;|Verdict: Accept/Deny| Engine
 Engine --&amp;gt;|Send Verdict| Controller
 Controller --&amp;gt;|Set NFQ verdict| Kernel
 Kernel --&amp;gt;|Allow/Drop packet| Done[Done]&lt;/pre>
&lt;p>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.&lt;/p></description></item><item><title>Policy Evaluators</title><link>https://kube-network-policies.sigs.k8s.io/docs/concepts/policy-evaluators/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kube-network-policies.sigs.k8s.io/docs/concepts/policy-evaluators/</guid><description>&lt;p>The &lt;code>PolicyEvaluator&lt;/code> interface is the core abstraction of the packet filtering pipeline in &lt;code>kube-network-policies&lt;/code>. Each evaluator is responsible for processing a packet and deciding its outcome based on its policy implementation.&lt;/p>
&lt;h2 id="the-policyevaluator-interface">The PolicyEvaluator Interface&lt;/h2>
&lt;p>The interface is defined in &lt;code>pkg/api/interfaces.go&lt;/code> (or &lt;code>pkg/networkpolicy/engine.go&lt;/code>) as follows:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-go" data-lang="go">&lt;span class="line">&lt;span class="cl">&lt;span class="kd">type&lt;/span> &lt;span class="nx">PolicyEvaluator&lt;/span> &lt;span class="kd">interface&lt;/span> &lt;span class="p">{&lt;/span> 
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nf">Name&lt;/span>&lt;span class="p">()&lt;/span> &lt;span class="kt">string&lt;/span> 
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nf">EvaluateIngress&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nx">ctx&lt;/span> &lt;span class="nx">context&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">Context&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nx">p&lt;/span> &lt;span class="o">*&lt;/span>&lt;span class="nx">network&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">Packet&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nx">srcPod&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nx">dstPod&lt;/span> &lt;span class="o">*&lt;/span>&lt;span class="nx">api&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">PodInfo&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="nx">Verdict&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="kt">error&lt;/span>&lt;span class="p">)&lt;/span> 
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nf">EvaluateEgress&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="nx">ctx&lt;/span> &lt;span class="nx">context&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">Context&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nx">p&lt;/span> &lt;span class="o">*&lt;/span>&lt;span class="nx">network&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">Packet&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nx">srcPod&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="nx">dstPod&lt;/span> &lt;span class="o">*&lt;/span>&lt;span class="nx">api&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">PodInfo&lt;/span>&lt;span class="p">)&lt;/span> &lt;span class="p">(&lt;/span>&lt;span class="nx">Verdict&lt;/span>&lt;span class="p">,&lt;/span> &lt;span class="kt">error&lt;/span>&lt;span class="p">)&lt;/span> 
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>The &lt;code>Verdict&lt;/code> returned by each evaluator can be one of the following:&lt;/p>
&lt;ul>
&lt;li>&lt;code>VerdictAccept&lt;/code>: The packet is allowed, and no further evaluators in the pipeline are consulted.&lt;/li>
&lt;li>&lt;code>VerdictDeny&lt;/code>: The packet is denied, and no further evaluators are consulted.&lt;/li>
&lt;li>&lt;code>VerdictNext&lt;/code>: The packet does not match this policy (or is passed through), and the engine continues to the next evaluator in the pipeline.&lt;/li>
&lt;/ul>
&lt;h2 id="the-pipeline-order">The Pipeline Order&lt;/h2>
&lt;p>When a packet is evaluated, it is processed sequentially by a pipeline of policy evaluators. The order is crucial, especially for Admin Network Policies:&lt;/p></description></item></channel></rss>