Skip to content

KCSA · Domain 3: Kubernetes Security Fundamentals · 22% of the exam

Task 3.8: Network Policy

NetworkPolicy selectors, ingress and egress rules, default-deny policies and the plugin support they need.

Study it

Sample questions

Try each one before opening the answer. Every option is explained, with the CNCF documentation page that proves it.

Question 1 · choose 1

Pods in namespace shop are under a default-deny egress policy. To let them reach the orders database, the team adds an egress rule with ipBlock 10.96.40.12/32, the ClusterIP of the orders Service, on port 5432. The client connects to that address directly, and the connections still fail. What does the NetworkPolicy documentation point to?

  1. AWiden the ipBlock to the cluster's whole Service CIDR
  2. BUse a podSelector for the database Pods instead of the Service address
  3. CAdd endPort: 5432 to the rule so that the allowed port range is explicit
  4. DAdd an ingress rule in shop that allows the database's reply packets
Show the answer and why
  • AWiden the ipBlock to the cluster's whole Service CIDR

    Incorrect

    The problem is not the range: traffic to any Service IP may be rewritten before it is matched, so an ipBlock of Service addresses is unreliable at any size.

  • BUse a podSelector for the database Pods instead of the Service address

    Correct

    Connections to Service IPs can be rewritten to backend addresses, and it is not defined whether that happens before or after policy processing; selecting the backend Pods by label avoids the problem.

  • CAdd endPort: 5432 to the rule so that the allowed port range is explicit

    Incorrect

    endPort only extends a single port into a range; it does not affect how the destination address is matched.

  • DAdd an ingress rule in shop that allows the database's reply packets

    Incorrect

    Reply traffic for an allowed connection is implicitly allowed; no extra rule is needed for responses.

Rewriting of Service or load balancer addresses may happen before or after NetworkPolicy processing, so a rule that names a Service's ClusterIP may never match the connection. To allow traffic to in-cluster backends, select the backend Pods by label.

Question 2 · choose 1

After a default-deny ingress policy is applied in a namespace, the HTTP liveness probes of its Pods keep succeeding. The security team asks why the policy does not block them. What is the reason?

  1. ATraffic from the Pod's own node is always allowed, whatever the policies say
  2. BProbes run inside the container, so they never cross the Pod network
  3. CPolicies affect only new connections, and probes reuse one opened before the policy
  4. DProbes use the Pod's loopback address, which policies never filter
Show the answer and why
  • ATraffic from the Pod's own node is always allowed, whatever the policies say

    Correct

    The NetworkPolicy documentation states that traffic to and from the node where a Pod is running is always allowed, and Pods cannot block access from their resident node.

  • BProbes run inside the container, so they never cross the Pod network

    Incorrect

    HTTP probes are sent by the kubelet on the node to the Pod; they reach it as traffic from the node, which policy cannot block.

  • CPolicies affect only new connections, and probes reuse one opened before the policy

    Incorrect

    Each probe is a new request; the documentation notes only that the effect on existing connections is implementation-defined.

  • DProbes use the Pod's loopback address, which policies never filter

    Incorrect

    Pods cannot block localhost traffic, but kubelet probes are not loopback traffic: they come from the node to the Pod's address.

NetworkPolicy cannot block traffic between a Pod and its own node: the documentation lists this both as an exception for IP blocks and as something policies cannot do. Kubelet probes come from the node, so they keep working under a default-deny ingress policy.

Question 3 · choose 1

A namespace has no NetworkPolicies at all, and the cluster's network plugin supports them. Which traffic is allowed to and from the Pods in that namespace?

  1. AOnly traffic from Pods in the same namespace
  2. BAll ingress and egress traffic
  3. CNo traffic, until a policy allows it
  4. DOnly egress traffic
Show the answer and why
  • AOnly traffic from Pods in the same namespace

    Incorrect

    Without a selecting policy the Pod is not isolated at all; same-namespace limits need a policy.

  • BAll ingress and egress traffic

    Correct

    The NetworkPolicy documentation says that if no policies exist in a namespace, all ingress and egress traffic is allowed to and from its Pods.

  • CNo traffic, until a policy allows it

    Incorrect

    Pods are non-isolated by default; isolation starts when a policy selects them.

  • DOnly egress traffic

    Incorrect

    Both directions are open while no policy selects the Pod.

Pods are non-isolated by default. Only when a NetworkPolicy selects a Pod does it become isolated for the policy types listed, and then only allowed connections pass.

Question 4 · choose 1

A NetworkPolicy must allow traffic from the namespace named monitoring, which has no custom labels. Which label can its namespaceSelector match?

  1. Akubernetes.io/metadata.name: monitoring
  2. Bname: monitoring
  3. Cmetadata.namespace: monitoring
  4. Dapp.kubernetes.io/name: monitoring
Show the answer and why
  • Akubernetes.io/metadata.name: monitoring

    Correct

    The control plane sets the immutable label kubernetes.io/metadata.name on every namespace, with the namespace's name as its value.

  • Bname: monitoring

    Incorrect

    No name label is added automatically; it would have to be created.

  • Cmetadata.namespace: monitoring

    Incorrect

    That is a field path, not a label on the namespace.

  • Dapp.kubernetes.io/name: monitoring

    Incorrect

    This is a recommended label for applications; it is not set on namespaces automatically.

NetworkPolicy selects namespaces by label. Because Kubernetes adds kubernetes.io/metadata.name to every namespace, a policy can target a namespace by name without adding labels first.

Practice domain 3 →Practice all domains →