Skip to content

Commit 66dd77e

Browse files
committed
WIP: IPsec blog
Signed-off-by: Mohamed S. Mahmoud <mmahmoud2201@gmail.com>
1 parent c7ad0b0 commit 66dd77e

3 files changed

Lines changed: 97 additions & 0 deletions

File tree

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
layout: :theme/post
3+
title: "Monitoring IPSec encryption and decryption using Network Observability"
4+
description: IPSec provides enriched information to indicate if IPsec encryption or decryption using libreswan was successful or not
5+
tags: Monitoring,Networking,IPSEC
6+
authors: [msherif1234]
7+
---
8+
9+
# Monitoring IPsec Encryption and Decryption with eBPF
10+
11+
**IPsec (Internet Protocol Security)** is a widely used protocol suite that secures communication at the IP layer through authentication and encryption. While powerful, IPsec can be opaque—making it difficult to inspect or debug encrypted traffic, especially at the kernel level.
12+
13+
With **eBPF (Extended Berkeley Packet Filter)** and its dynamic tracing capabilities via **kprobes** and **kretprobes**, we can instrument IPsec-related kernel functions without modifying kernel source code or rebooting the system.
14+
15+
In this blog post, we'll show how to leverage eBPF to observe IPsec encryption and decryption processes in the Linux kernel.
16+
17+
---
18+
19+
## Understanding IPsec Traffic
20+
21+
OpenShift uses [**Libreswan**](https://libreswan.org/) to handle IPsec encryption and decryption. The diagram below illustrates how an IPsec packet appears before and after encryption:
22+
23+
![IPsec Packet Flow](ipsec-packet.png)
24+
25+
---
26+
27+
## 1. Tracing IPsec Encryption
28+
29+
**IPsec encryption** transforms plaintext data into ciphertext to protect it from unauthorized access.
30+
31+
To monitor this process with eBPF:
32+
33+
- Set a **`kprobe`** on the `xfrm_output` function to trace when encryption is initiated.
34+
- Set a **`kretprobe`** on the same function to capture its return value and extract flow metadata, allowing us to determine whether encryption was successful.
35+
36+
---
37+
38+
## 2. Tracing IPsec Decryption
39+
40+
**IPsec decryption** converts ciphertext back into plaintext.
41+
42+
To monitor decryption:
43+
44+
- Set a **`kprobe`** on the `xfrm_input` function to trace when decryption is triggered.
45+
- Use a **`kretprobe`** on `xfrm_input` to capture the return code and associated flow information, helping determine success or failure.
46+
47+
---
48+
49+
## Network Observability Enrichment
50+
51+
With eBPF instrumentation, NetObserv enriches flow records with two fields related to IPsec operations:
52+
53+
- **`ipsec_encrypted_ret`**: Contains the kernel return code from the encryption/decryption function.
54+
- **`ipsec_encrypted`**: A boolean indicator (`1` = success, `0` = failure) representing whether encryption or decryption was completed successfully.
55+
56+
---
57+
58+
## IPsec Insights in the UI
59+
60+
The NetObserv user interface provides visibility into IPsec operations as part of flow records:
61+
62+
![IPsec Flows in UI](ipsec-flows.png)
63+
64+
---
65+
66+
## Enabling IPsec Monitoring
67+
68+
To activate IPsec tracing, update the `FlowCollector` configuration as follows:
69+
70+
```yaml
71+
apiVersion: flows.netobserv.io/v1beta2
72+
kind: FlowCollector
73+
metadata:
74+
name: cluster
75+
spec:
76+
agent:
77+
type: EBPF
78+
ebpf:
79+
features:
80+
- IPSec
81+
```
82+
83+
84+
## Availability
85+
86+
The IPsec feature is available OCP 4.19 and NetObserv release 1.9.
87+
88+
89+
## Conclusion
90+
Network Observability with eBPF provides a powerful way to monitor IPsec encryption and decryption operations in the Linux kernel. By using kprobe and kretprobe, we can dynamically insert probes into IPsec-related kernel functions without modifying kernel source code or requiring system reboots.
91+
92+
93+
## Feedback
94+
95+
We hope you liked this article !
96+
NetObserv is an open source project [available on github](https://github.com/netobserv).
97+
Feel free to share your [ideas](https://github.com/orgs/netobserv/discussions/categories/ideas), [use cases](https://github.com/orgs/netobserv/discussions/categories/show-and-tell) or [ask the community for help](https://github.com/orgs/netobserv/discussions/categories/q-a).
327 KB
Loading
189 KB
Loading

0 commit comments

Comments
 (0)