Skip to content

Commit 3f9bf57

Browse files
syedazeez337qmonnet
authored andcommitted
docs: add egressDeny example to policy language guide
Signed-off-by: Syed Azeez <syedazeez337@gmail.com>
1 parent 2d0825e commit 3f9bf57

2 files changed

Lines changed: 50 additions & 24 deletions

File tree

Documentation/security/policy/language.rst

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,17 @@ Note that while the above examples allow all egress traffic from an endpoint, th
124124
of the egress traffic may have ingress rules that deny the traffic. In other words,
125125
policy must be configured on both sides (sender and receiver).
126126

127+
Simple Egress Deny
128+
~~~~~~~~~~~~~~~~~~
129+
130+
The following example illustrates how to deny communication to endpoints with
131+
the label ``role=backend`` from endpoints with the label ``role=frontend``.
132+
If an ``egressDeny`` rule matches, egress traffic is denied even if the policy
133+
contains ``egress`` rules that would otherwise allow it.
134+
135+
.. literalinclude:: ../../../examples/policies/l3/egress-deny/egress-deny.yaml
136+
:language: yaml
137+
127138
Ingress/Egress Default Deny
128139
~~~~~~~~~~~~~~~~~~~~~~~~~~~
129140

@@ -666,7 +677,7 @@ which is defined as follows:
666677
// +kubebuilder:validation:Optional
667678
// +kubebuilder:validation:Enum=IPv4;IPv6
668679
Family string `json:"family,omitempty"`
669-
680+
670681
// Type is a ICMP-type.
671682
// It should be an 8bit code (0-255), or it's CamelCase name (for example, "EchoReply").
672683
// Allowed ICMP types are:
@@ -811,7 +822,7 @@ latter rule will have no effect.
811822

812823
.. note:: :ref:`EnableDefaultDeny <policy_mode_default>` does not apply to layer-7 rules.
813824
If using a layer 7 rule in concert with ``EnableDefaultDeny``, the rule should
814-
allow all layer-7 traffic. See :gh-issue:`38676`.
825+
allow all layer-7 traffic. See :gh-issue:`38676`.
815826

816827
HTTP
817828
----
@@ -847,7 +858,7 @@ Allow GET /public
847858
~~~~~~~~~~~~~~~~~
848859

849860
The following example allows ``GET`` requests to the URL ``/public`` from the
850-
endpoints with the labels ``env=prod`` to endpoints with the labels
861+
endpoints with the labels ``env=prod`` to endpoints with the labels
851862
``app=service``, but requests to any other URL, or using another method, will
852863
be rejected. Requests on ports other than port 80 will be dropped.
853864

@@ -1018,7 +1029,7 @@ respecting TTL.
10181029

10191030
.. _DNS Proxy:
10201031

1021-
DNS Proxy
1032+
DNS Proxy
10221033
"""""""""
10231034
A DNS Proxy intercepts egress DNS traffic and records IPs seen in the
10241035
responses. This interception is, itself, a separate policy rule governing the
@@ -1133,33 +1144,33 @@ domain name.
11331144
Disk based Cilium Network Policies
11341145
==================================
11351146
This functionality enables users to place network policy YAML files directly into
1136-
the node's filesystem, bypassing the need for definition via k8s CRD.
1137-
By setting the config field ``static-cnp-path``, users specify the directory from
1138-
which policies will be loaded. The Cilium agent then processes all policy YAML files
1139-
present in this directory, transforming them into rules that are incorporated into
1140-
the policy engine. Additionally, the Cilium agent monitors this directory for any
1141-
new policy YAML files as well as any updates or deletions, making corresponding
1142-
updates to the policy engine's rules. It is important to note that this feature
1147+
the node's filesystem, bypassing the need for definition via k8s CRD.
1148+
By setting the config field ``static-cnp-path``, users specify the directory from
1149+
which policies will be loaded. The Cilium agent then processes all policy YAML files
1150+
present in this directory, transforming them into rules that are incorporated into
1151+
the policy engine. Additionally, the Cilium agent monitors this directory for any
1152+
new policy YAML files as well as any updates or deletions, making corresponding
1153+
updates to the policy engine's rules. It is important to note that this feature
11431154
only supports CiliumNetworkPolicy and CiliumClusterwideNetworkPolicy.
11441155

1145-
The directory that the Cilium agent needs to monitor should be mounted from the host
1156+
The directory that the Cilium agent needs to monitor should be mounted from the host
11461157
using volume mounts. For users deploying via Helm, this can be enabled via ``extraArgs``
11471158
and ``extraHostPathMounts`` as follows:
11481159

11491160
.. code-block:: yaml
11501161
1151-
extraArgs:
1152-
- --static-cnp-path=/policies
1153-
extraHostPathMounts:
1154-
- name: static-policies
1155-
mountPath: /policies
1156-
hostPath: /policies
1157-
hostPathType: Directory
1158-
1159-
To determine whether a policy was established via Kubernetes CRD or directly from a directory,
1160-
execute the command ``cilium policy get`` and examine the source attribute within the policy.
1161-
In output, you could notice policies that have been sourced from a directory will have the
1162-
``source`` field set as ``directory``. Additionally, ``cilium endpoint get <endpoint_id>`` also have
1162+
extraArgs:
1163+
- --static-cnp-path=/policies
1164+
extraHostPathMounts:
1165+
- name: static-policies
1166+
mountPath: /policies
1167+
hostPath: /policies
1168+
hostPathType: Directory
1169+
1170+
To determine whether a policy was established via Kubernetes CRD or directly from a directory,
1171+
execute the command ``cilium policy get`` and examine the source attribute within the policy.
1172+
In output, you could notice policies that have been sourced from a directory will have the
1173+
``source`` field set as ``directory``. Additionally, ``cilium endpoint get <endpoint_id>`` also have
11631174
fields to show the source of policy associated with that endpoint.
11641175

11651176
Previous limitations and known issues
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: "cilium.io/v2"
2+
kind: CiliumNetworkPolicy
3+
metadata:
4+
name: "deny-egress-example"
5+
spec:
6+
endpointSelector:
7+
matchLabels:
8+
role: frontend
9+
egress:
10+
- toEntities:
11+
- all
12+
egressDeny:
13+
- toEndpoints:
14+
- matchLabels:
15+
role: backend

0 commit comments

Comments
 (0)