Skip to content
/ contain Public

BPF based per-process per-container egress filter

License

Notifications You must be signed in to change notification settings

gr455/contain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contain

BPF based per-process per-container egress filter.

Filters outgoing traffic from containers based on the container and the process the traffic originated from. Once containd is running, it automatically detects any new containers.

Run

Requires cgroup v2

  1. Update blacklist.json with your own allow list.

  2. To start Contain daemon, run

python3 containd.py

When the daemon is running, it detects any newly started containers and applies policies to them.

Once started, the allow list

[
	{	
		"container_name": "curler", // Only add a single object per container
		"policy": [
			{
				"process": "curl", // Only add a single object per process, add one/multiple objects per container
				"allow": [
					{
						"cidr4": "1.1.1.0/24",
						"ports": [80, 443]
					}
				]
			}
		]
	}
]

Gives

Result

This BPF filter uses BPF_PROG_TYPE_CGROUP_SKB and a kretprobe to kernel function net/socket/sock_alloc_file for per-process, per-container socket filtering.

Tested on Linux 5.19.0 - 6.2.0

About

BPF based per-process per-container egress filter

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published