-
Notifications
You must be signed in to change notification settings - Fork 50
WIP: Initial implementation for user space uprobe for SSL #819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
msherif1234
wants to merge
3
commits into
main
Choose a base branch
from
dev_ssl
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
2f4fbe7
fix(deps): update module github.com/netobserv/flowlogs-pipeline to v1…
red-hat-konflux[bot] b165fb3
fix(deps): update module github.com/vmware/go-ipfix to v0.13.0 (#592)
red-hat-konflux[bot] 00fd511
Initial PR to implement openSSL userspace tracker
msherif1234 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /* | ||
| * OpenSSL monitoring uprobe/uretprobe eBPF hook. | ||
| */ | ||
|
|
||
| #ifndef __OPENSSL_TRACKER_H__ | ||
| #define __OPENSSL_TRACKER_H__ | ||
|
|
||
| #include "utils.h" | ||
|
|
||
| static inline void generate_SSL_data_event(struct pt_regs *ctx, u64 pid_tgid, u8 ssl_type, | ||
| const char *buf, int len) { | ||
| if (len <= 0) { | ||
| return; | ||
| } | ||
|
|
||
| struct ssl_data_event_t *event; | ||
| event = bpf_ringbuf_reserve(&ssl_data_event_map, sizeof(*event), 0); | ||
| if (!event) { | ||
| return; | ||
| } | ||
| event->timestamp_ns = bpf_ktime_get_ns(); | ||
| event->pid_tgid = pid_tgid; | ||
| event->ssl_type = ssl_type; | ||
| event->data_len = len < MAX_DATA_SIZE_OPENSSL ? len : MAX_DATA_SIZE_OPENSSL; | ||
| bpf_probe_read_user(&event->data, event->data_len, buf); | ||
| bpf_ringbuf_submit(event, 0); | ||
| } | ||
|
|
||
| // int SSL_write(SSL *ssl, const void *buf, int num); | ||
| // https://github.com/openssl/openssl/blob/master/ssl/ssl_lib.c#L2666 | ||
| SEC("uprobe/SSL_write") | ||
| int probe_entry_SSL_write(struct pt_regs *ctx) { | ||
| if (enable_ssl == 0) { | ||
| return 0; | ||
| } | ||
|
|
||
| u64 pid_tgid = bpf_get_current_pid_tgid(); | ||
|
|
||
| BPF_PRINTK("openssl uprobe/SSL_write pid: %d\n", pid_tgid); | ||
| // https://github.com/openssl/openssl/blob/master/ssl/ssl_local.h#L1233 | ||
| void *ssl = (void *)PT_REGS_PARM1(ctx); | ||
|
|
||
| u32 ssl_type; | ||
| int ret; | ||
|
|
||
| ret = bpf_probe_read_user(&ssl_type, sizeof(ssl_type), (u32 *)ssl); | ||
| if (ret) { | ||
| BPF_PRINTK("(OPENSSL) bpf_probe_read ssl_type_ptr failed, ret: %d\n", ret); | ||
| return 0; | ||
| } | ||
| const char *buf = (const char *)PT_REGS_PARM2(ctx); | ||
| int num = (int)PT_REGS_PARM3(ctx); // Third parameter: number of bytes to write | ||
|
|
||
| BPF_PRINTK("openssl uprobe/SSL_write type: %d, buf: %p, num: %d\n", ssl_type, buf, num); | ||
|
|
||
| // Read the data immediately in the uprobe (before SSL_write processes it) | ||
| // This captures the plaintext before encryption | ||
| if (num > 0) { | ||
| generate_SSL_data_event(ctx, pid_tgid, ssl_type, buf, num); | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| #endif /* __OPENSSL_TRACKER_H__ */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,216 @@ | ||
| #!/bin/bash | ||
| # Test SSL tracking with HOST processes (not containers) | ||
| # | ||
| # This script tests SSL/TLS tracking functionality by executing HTTPS requests | ||
| # directly on cluster nodes (host processes) and verifying that the NetObserv | ||
| # agent captures SSL events via eBPF uprobes. | ||
| # | ||
| # Prerequisites: | ||
| # - Kubernetes cluster (kind/minikube/etc) | ||
| # - NetObserv agent deployed with EnableSSL: true | ||
| # - Agent configured with correct OpenSSL library path | ||
| # | ||
| # Note: Some tests (TLS 1.3, HTTP/2) are optional and won't cause failure | ||
| # if not supported on the node. | ||
|
|
||
| # Don't exit on error - we want to run all tests and report results | ||
| # Steps to test on Kind cluster: | ||
| # make create-and-deploy-kind-cluster | ||
| # export KUBECONFIG=$(pwd)/scripts/kubeconfig | ||
| # ./examples/test-ssl-host.sh | ||
|
|
||
| set +e | ||
|
|
||
| # Colors for output | ||
| RED='\033[0;31m' | ||
| GREEN='\033[0;32m' | ||
| YELLOW='\033[1;33m' | ||
| BLUE='\033[0;34m' | ||
| NC='\033[0m' # No Color | ||
|
|
||
| echo -e "${BLUE}=== Testing SSL with Host Process ===${NC}" | ||
| echo "" | ||
| echo "This will run various SSL/TLS tests on each cluster node directly on the host" | ||
| echo "This should trigger the SSL uprobes since the host process uses" | ||
| echo "the same libssl.so that the agent attached to." | ||
| echo "" | ||
|
|
||
| # Get all node names | ||
| NODES=$(kubectl get nodes -o jsonpath='{.items[*].metadata.name}') | ||
|
|
||
| # Counter for tests | ||
| TOTAL_TESTS=0 | ||
| PASSED_TESTS=0 | ||
| FAILED_TESTS=0 | ||
|
|
||
| run_test() { | ||
| local node=$1 | ||
| local test_name=$2 | ||
| local curl_cmd=$3 | ||
|
|
||
| TOTAL_TESTS=$((TOTAL_TESTS + 1)) | ||
| echo -e "${YELLOW}[TEST $TOTAL_TESTS] $test_name${NC}" | ||
|
|
||
| if docker exec $node bash -c "$curl_cmd" > /dev/null 2>&1; then | ||
| echo -e "${GREEN}✓ Request completed successfully${NC}" | ||
| PASSED_TESTS=$((PASSED_TESTS + 1)) | ||
| return 0 | ||
| else | ||
| echo -e "${RED}✗ Request failed${NC}" | ||
| FAILED_TESTS=$((FAILED_TESTS + 1)) | ||
| return 1 | ||
| fi | ||
| } | ||
|
|
||
| check_ssl_events() { | ||
| local agent_pod=$1 | ||
| local test_desc=$2 | ||
|
|
||
| echo -e "${BLUE}Checking logs for SSL events after $test_desc:${NC}" | ||
| local ssl_events=$(kubectl logs -n netobserv-privileged $agent_pod --tail=100 | grep 'SSL EVENT' | tail -5) | ||
|
|
||
| if [ -z "$ssl_events" ]; then | ||
| echo -e "${YELLOW}No SSL events found in logs${NC}" | ||
| else | ||
| echo -e "${GREEN}SSL events found:${NC}" | ||
| echo "$ssl_events" | ||
| fi | ||
| echo "" | ||
| } | ||
|
|
||
| for NODE in $NODES; do | ||
| echo "=========================================" | ||
| echo -e "${BLUE}Testing node: $NODE${NC}" | ||
| echo "=========================================" | ||
|
|
||
| # Get the agent pod running on this node | ||
| AGENT_POD=$(kubectl get pods -n netobserv-privileged -l k8s-app=netobserv-ebpf-agent \ | ||
| --field-selector spec.nodeName=$NODE \ | ||
| -o jsonpath='{range .items[*]}{.metadata.name}{"\n"}{end}' | head -n1) | ||
|
|
||
| if [ -z "$AGENT_POD" ]; then | ||
| echo -e "${RED}Warning: No agent pod found on node $NODE, skipping...${NC}" | ||
| continue | ||
| fi | ||
|
|
||
| echo -e "${GREEN}Agent pod: $AGENT_POD${NC}" | ||
| echo "" | ||
|
|
||
| # Show diagnostic information | ||
| echo -e "${BLUE}Node diagnostics:${NC}" | ||
| echo -n " curl version: " | ||
| docker exec $NODE curl --version 2>/dev/null | head -1 || echo "unknown" | ||
| echo -n " OpenSSL version: " | ||
| docker exec $NODE openssl version 2>/dev/null || echo "unknown" | ||
| echo -n " libssl location: " | ||
| docker exec $NODE bash -c "ls -la /usr/lib*/libssl.so* 2>/dev/null | head -1 || echo 'not found in standard location'" | ||
| echo "" | ||
|
|
||
| # Check if agent has SSL tracking enabled | ||
| echo -e "${BLUE}Agent SSL tracking status:${NC}" | ||
| if kubectl logs -n netobserv-privileged $AGENT_POD --tail=100 | grep -q "SSL tracking enabled"; then | ||
| echo -e " ${GREEN}✓ SSL tracking is enabled${NC}" | ||
| kubectl logs -n netobserv-privileged $AGENT_POD --tail=100 | grep "SSL tracking enabled" | tail -1 | ||
| else | ||
| echo -e " ${YELLOW}⚠ SSL tracking status unclear (check agent configuration)${NC}" | ||
| fi | ||
| echo "" | ||
|
|
||
| # Test 1: Basic HTTPS GET with HTTP/1.1 | ||
| run_test "$NODE" "Basic HTTPS GET with HTTP/1.1" \ | ||
| "curl -s --http1.1 --max-time 10 https://httpbin.org/get" | ||
|
|
||
| # Test 2: HTTPS POST with data | ||
| run_test "$NODE" "HTTPS POST with JSON data" \ | ||
| "curl -s --http1.1 --max-time 10 -X POST https://httpbin.org/post -H 'Content-Type: application/json' -d '{\"test\":\"data\"}'" | ||
|
|
||
| # Test 3: HTTPS with TLS 1.2 | ||
| run_test "$NODE" "HTTPS with TLS 1.2 explicitly" \ | ||
| "curl -s --tlsv1.2 --tls-max 1.2 --max-time 10 https://www.howsmyssl.com/a/check" | ||
|
|
||
| # Test 4: HTTPS with TLS 1.3 (optional - may not be supported) | ||
| echo -e "${YELLOW}[TEST $((TOTAL_TESTS + 1))] HTTPS with TLS 1.3 explicitly (optional)${NC}" | ||
| TOTAL_TESTS=$((TOTAL_TESTS + 1)) | ||
|
|
||
| # First check if TLS 1.3 is supported | ||
| if docker exec $NODE bash -c "curl --help all 2>/dev/null | grep -q tlsv1.3" 2>/dev/null; then | ||
| if docker exec $NODE bash -c "curl -s --tlsv1.3 --max-time 10 https://www.howsmyssl.com/a/check" > /dev/null 2>&1; then | ||
| echo -e "${GREEN}✓ Request completed successfully (TLS 1.3 supported)${NC}" | ||
| PASSED_TESTS=$((PASSED_TESTS + 1)) | ||
| else | ||
| # Try alternative endpoint | ||
| if docker exec $NODE bash -c "curl -s --tlsv1.3 --max-time 10 https://www.cloudflare.com" > /dev/null 2>&1; then | ||
| echo -e "${GREEN}✓ Request completed successfully with alternative endpoint${NC}" | ||
| PASSED_TESTS=$((PASSED_TESTS + 1)) | ||
| else | ||
| echo -e "${YELLOW}⚠ TLS 1.3 option exists but connection failed (this is OK)${NC}" | ||
| PASSED_TESTS=$((PASSED_TESTS + 1)) | ||
| fi | ||
| fi | ||
| else | ||
| echo -e "${YELLOW}⚠ TLS 1.3 not supported by curl on this node (skipped)${NC}" | ||
| PASSED_TESTS=$((PASSED_TESTS + 1)) | ||
| fi | ||
|
|
||
| # Test 5: HTTPS with headers | ||
| run_test "$NODE" "HTTPS with custom headers" \ | ||
| "curl -s --http1.1 --max-time 10 -H 'User-Agent: NetObserv-Test/1.0' -H 'X-Test-Header: SSL-Tracking' https://httpbin.org/headers" | ||
|
|
||
| # Test 6: Different endpoint - github API | ||
| run_test "$NODE" "HTTPS to GitHub API" \ | ||
| "curl -s --http1.1 --max-time 10 https://api.github.com" | ||
|
|
||
| # Test 7: Different endpoint - Google | ||
| run_test "$NODE" "HTTPS to Google" \ | ||
| "curl -s --http1.1 --max-time 10 -L https://www.google.com" | ||
|
|
||
| # Test 8: HTTPS with large response | ||
| run_test "$NODE" "HTTPS with large response (1KB)" \ | ||
| "curl -s --http1.1 --max-time 10 https://httpbin.org/bytes/1024" | ||
|
|
||
| # Test 9: HTTPS with HTTP/2 (optional - may not be supported) | ||
| echo -e "${YELLOW}[TEST $((TOTAL_TESTS + 1))] HTTPS with HTTP/2 (optional)${NC}" | ||
| TOTAL_TESTS=$((TOTAL_TESTS + 1)) | ||
|
|
||
| if docker exec $NODE bash -c "curl --help all 2>/dev/null | grep -q http2" 2>/dev/null; then | ||
| if docker exec $NODE bash -c "curl -s --http2 --max-time 10 https://www.google.com" > /dev/null 2>&1; then | ||
| echo -e "${GREEN}✓ Request completed successfully (HTTP/2 supported)${NC}" | ||
| PASSED_TESTS=$((PASSED_TESTS + 1)) | ||
| else | ||
| echo -e "${YELLOW}⚠ HTTP/2 option exists but connection failed (this is OK)${NC}" | ||
| PASSED_TESTS=$((PASSED_TESTS + 1)) | ||
| fi | ||
| else | ||
| echo -e "${YELLOW}⚠ HTTP/2 not supported by curl on this node (skipped)${NC}" | ||
| PASSED_TESTS=$((PASSED_TESTS + 1)) | ||
| fi | ||
|
|
||
| echo "" | ||
| check_ssl_events "$AGENT_POD" "all tests" | ||
|
|
||
| echo -e "${BLUE}Detailed SSL event analysis:${NC}" | ||
| kubectl logs -n netobserv-privileged $AGENT_POD --tail=200 | grep -A 2 "SSL EVENT" | tail -20 || echo "No detailed SSL events found" | ||
|
|
||
| echo "" | ||
| echo -e "${BLUE}Node $NODE test summary:${NC}" | ||
| echo " Total tests: $TOTAL_TESTS" | ||
| echo -e " ${GREEN}Passed: $PASSED_TESTS${NC}" | ||
| echo -e " ${RED}Failed: $FAILED_TESTS${NC}" | ||
| echo "" | ||
| done | ||
|
|
||
| echo "=========================================" | ||
| echo -e "${BLUE}Test completed for all nodes${NC}" | ||
| echo "=========================================" | ||
| echo "" | ||
| echo -e "${BLUE}Overall Summary:${NC}" | ||
| echo " Total tests executed: $TOTAL_TESTS" | ||
| echo -e " ${GREEN}Passed: $PASSED_TESTS${NC}" | ||
| echo -e " ${RED}Failed: $FAILED_TESTS${NC}" | ||
| echo "" | ||
|
|
||
| # Calculate pass rate | ||
| if [ $TOTAL_TESTS -gt 0 ]; then | ||
| PASS_RATE=$((PASSED_TESTS * 100 / TOTAL_TESTS)) | ||
| echo " Pass rate: ${PASS_RATE}%" | ||
| fi |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe more specific "enable_openssl" to leave space for other implementations and also to remove any ambiguity as I'll also add something like "enable_tls_tracker" ?