Skip to content

Commit

Permalink
test(capabilities): add e2e tests and example pipeline
Browse files Browse the repository at this point in the history
Signed-off-by: Massimiliano Giovagnoli <[email protected]>
  • Loading branch information
maxgio92 committed Dec 20, 2024
1 parent cbf421c commit ee5eec5
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
31 changes: 31 additions & 0 deletions e2e-tests/capabilities-add-drop-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package:
name: busybox
description: Capabilities add-drop feature test
version: 0.1.0
epoch: 0

capabilities:
add:
- CAP_NET_ADMIN
drop:
- CAP_SYS_ADMIN
- CAP_SYS_CHROOT

environment:
contents:
packages:
- busybox
- cmd:capsh

pipeline:
- name: Test default effective capability
runs: |
capsh --decode=$(grep CapEff /proc/self/status | cut -d ':' -f2 | xargs) | grep -i cap_dac_override
- name: Test added non-default effective capability
runs: |
capsh --decode=$(grep CapEff /proc/self/status | cut -d ':' -f2 | xargs) | grep -i cap_net_admin
- name: Test dropped default effective capability
runs: |
capsh --decode=$(grep CapEff /proc/self/status | cut -d ':' -f2 | xargs) | grep -vi cap_sys_chroot
33 changes: 33 additions & 0 deletions e2e-tests/capabilities-add-drop-nopkg-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package:
name: busybox
description: Capabilities add-drop feature test
version: 0.1.0
epoch: 0

capabilities:
add:
- CAP_NET_ADMIN
drop:
- CAP_SYS_ADMIN
- CAP_SYS_CHROOT

pipeline:

test:
environment:
contents:
packages:
- busybox
- cmd:capsh
pipeline:
- name: Test default effective capability
runs: |
capsh --decode=$(grep CapEff /proc/self/status | cut -d ':' -f2 | xargs) | grep -i cap_dac_override
- name: Test added non-default effective capability
runs: |
capsh --decode=$(grep CapEff /proc/self/status | cut -d ':' -f2 | xargs) | grep -i cap_net_admin
- name: Test dropped default effective capability
runs: |
capsh --decode=$(grep CapEff /proc/self/status | cut -d ':' -f2 | xargs) | grep -vi cap_sys_chroot
27 changes: 27 additions & 0 deletions examples/capabilities-add-drop.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package:
name: busybox
version: 0.1.0
epoch: 0

capabilities:
add:
- CAP_NET_ADMIN
drop:
- CAP_SYS_ADMIN

pipeline:
# Here your build pipeline.
# Capabilities are added/dropped to both build and test pipelines.

test:
environment:
contents:
packages:
- busybox
- iproute2
pipeline:
# Note: you can't do it with bubblewrap runner,
# as it shares the host network namespace.
- name: Simulate a test attempting to create network interfaces
runs: |
ip link add dev myinterface type dummy

0 comments on commit ee5eec5

Please sign in to comment.