Ensuring Deployment Safety with eBPF: A Step-by-Step Guide

By

Introduction

Did you know that GitHub hosts all of its own source code on github.com? This practice allows the company to act as its own biggest customer, testing internal changes before rolling them out to users. However, it introduces a critical risk: if github.com goes down, GitHub loses access to its own source code—a classic circular dependency. To mitigate this, GitHub maintains a mirrored copy and built assets for rollback. Yet, more subtle circular dependencies lurk within deployment scripts, such as those that rely on internal services or downloading binaries from GitHub. To tackle this, GitHub turned to eBPF (extended Berkeley Packet Filter), a powerful Linux kernel technology that allows safe and efficient monitoring and blocking of system calls. This guide will walk you through how GitHub uses eBPF to enhance deployment safety, step by step.

Ensuring Deployment Safety with eBPF: A Step-by-Step Guide
Source: github.blog

What You Need

Step-by-Step Guide

Step 1: Identify Circular Dependencies in Your Deployment Process

Before writing eBPF programs, analyze your deployment scripts to spot circular dependencies. In the GitHub scenario, three types exist:

Document each dependency: what system calls or network requests it makes, and whether it could create a loop. For example, a script run during a MySQL outage might try to wget a release from GitHub.

Step 2: Design an eBPF Program to Monitor Relevant Syscalls

eBPF can attach to syscalls like connect, open, or execve. For deployment safety, focus on network-related syscalls (e.g., connect to detect outgoing connections to GitHub). Create a map to store allowed IP addresses or domains. In GitHub’s case, they’d block connections to github.com except from whitelisted processes. Use kprobe or tracepoint to intercept these syscalls and log details (PID, destination IP, etc.).

Step 3: Write the eBPF C Code

Using C with libbpf, write an eBPF program that:

Sample snippet:

#include 
#include 

struct {
    __uint(type, BPF_MAP_TYPE_HASH);
    __uint(max_entries, 1024);
    __type(key, __u32); // PID
    __type(value, __u32); // allowed flag
} allowed_processes SEC(".maps");

SEC("kprobe/sys_connect")
int kprobe__sys_connect(struct pt_regs *ctx)
{
    // ... implementation
    return 0;
}

Note: Full implementation requires handling socket structures and byte ordering.

Step 4: Compile and Load the eBPF Program

Compile the eBPF C code into a BPF object using clang with -target bpf. Then, use a loader (e.g., bpftool or a small Python/C loader) to load the program into the kernel. For example:

Ensuring Deployment Safety with eBPF: A Step-by-Step Guide
Source: github.blog
clang -O2 -target bpf -c deploy_safety.c -o deploy_safety.o
bpftool prog load deploy_safety.o /sys/fs/bpf/deploy_safety

Verify it's loaded with bpftool prog list. Attach the program to the appropriate hook (e.g., using bpftool perf attach or via tracepoint).

Step 5: Test with Simulated Deployment Scenarios

Simulate the circular dependency scenarios from Step 1. Run a script that tries to connect to GitHub’s IP while the eBPF program is active. Check logs (e.g., via trace_pipe or bpftool map dump) to confirm the program blocks or logs the attempt. Test both allowed processes (e.g., a trusted updater) and blocked ones. Adjust the map entries to fine-tune behavior.

Step 6: Integrate into Your Deployment Pipeline

Once tested, incorporate the eBPF program into the deployment system. For GitHub, this means:

Consider running the eBPF program in a monitoring-only mode initially to audit dependencies before enforcing blocks.

Tips for Success

By following these steps, you can leverage eBPF to break circular dependencies in your own deployment pipelines, just like GitHub does. The key is to identify risky dependencies, design a targeted eBPF program, and test thoroughly before enforcing blocks.

Tags:

Related Articles

Recommended

Discover More

Dell and Lenovo Invest $200K Annually to Propel Linux Firmware ServiceRiding the Waves of Web Development: From Hacks to StandardsFedora Asahi Remix 44 Brings Fedora Linux to Apple Silicon Macs with Enhanced FeaturesAlert: QLNX Linux Malware Harvests Developer Credentials for Software Supply Chain AttacksYour Step-by-Step Guide to Harnessing the HP Z6 G5 A as a Linux-Ready Powerhouse