|
| 1 | +(bpf-tokens)= |
| 2 | +# BPF token delegation |
| 3 | + |
| 4 | +Incus supports delegating BPF capabilities via [BPF tokens](https://docs.ebpf.io/linux/concepts/token/). |
| 5 | +If any of the instance options {config:option}`instance-security:security.bpffs.delegate_cmds`, |
| 6 | +{config:option}`instance-security:security.bpffs.delegate_maps`, |
| 7 | +{config:option}`instance-security:security.bpffs.delegate_progs` or |
| 8 | +{config:option}`instance-security:security.bpffs.delegate_attachs` is set, Incus mounts a BPF filesystem into the |
| 9 | +container at the path specified by the {config:option}`instance-security:security.bpffs.path` option and delegates the |
| 10 | +configured capabilities to it. |
| 11 | + |
| 12 | +The permissible values for these options depend on the kernel version and can be found in enums in the BPF header file |
| 13 | +(`include/uapi/linux/bpf.h` in the kernel tree, `/usr/include/linux/bpf.h` on most distributions if you have the kernel |
| 14 | +sources installed): |
| 15 | + |
| 16 | + Key | Kernel enum | Remove prefix |
| 17 | + :-- |:-- | :-- |
| 18 | + `security.bpffs.delegate_cmds` | `bpf_cmd` | `BPF_` |
| 19 | + `security.bpffs.delegate_maps` | `bpf_map_type` | `BPF_MAP_TYPE_` |
| 20 | + `security.bpffs.delegate_progs` | `bpf_prog_type` | `BPF_PROG_TYPE_` |
| 21 | + `security.bpffs.delegate_attachs` | `bpf_attach_type` | `BPF_` |
| 22 | + |
| 23 | +Each of these options takes a comma-separated list of values, additionally the value `any` is supported to delegate all |
| 24 | +possible values of the type. |
| 25 | + |
| 26 | +## Example |
| 27 | + |
| 28 | + Key | Value |
| 29 | + :-- | :-- |
| 30 | + `security.bpffs.delegate_cmds` | `map_create,obj_get,link_create` |
| 31 | + `security.bpffs.delegate_maps` | `hash,array,devmap,queue,stack` |
| 32 | + `security.bpffs.delegate_progs` | `socket_filter,kprobe,cgroup_sysctl` |
| 33 | + `security.bpffs.delegate_attachs` | `any` |
| 34 | + |
| 35 | +```bash |
| 36 | +$ mount -t bpf |
| 37 | +none on /sys/fs/bpf type bpf (rw,relatime,delegate_cmds=map_create:obj_get:link_create,delegate_maps=hash:array:devmap:queue:stack,delegate_progs=socket_filter:kprobe:cgroup_sysctl,delegate_attachs=any) |
| 38 | +``` |
0 commit comments