1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
summary: Ensure that /dev/input/event* is denied by default.
details: |
The default policy disallows access to /dev/input/event*.
The joystick interface disallows access to /dev/input/event* for
non-joysticks.
The device-buttons interface disallows access to /dev/input/event* for
non-device-keys.
The test checks the snap is not able to access /dev/input/event* with or
without the joystick or device-buttons interface(s) connected. We do this
since the /dev/input/event* devices are sensitive and because these
interfaces add a /dev/input/event* AppArmor glob rule that relies entirely
on the device cgroup for enforcement.
prepare: |
echo "Given the test-snapd-event snap is installed"
"$TESTSTOOLS"/snaps-state install-local test-snapd-event
execute: |
if [ -z "$(find /dev/input/by-path -name '*-event-kbd')" ]; then
if [ "$SPREAD_SYSTEM" = "ubuntu-16.04-64" ]; then
# ensure the test runs at least on this spread system
echo "No /dev/input/by-path but this test cannot be skipped on ubuntu-16.04-64"
exit 1
fi
echo "SKIP: no /dev/input/by-path"
exit 0
fi
# Default state of both interfaces
echo "The joystick plug is not connected by default"
snap interfaces -i joystick | MATCH '\- +test-snapd-event:joystick'
echo "The device-buttons plug is not connected by default"
snap interfaces -i device-buttons | MATCH '\- +test-snapd-event:device-buttons'
if [ "$(snap debug confinement)" != "strict" ]; then
exit 0
fi
# 1. Joystick
echo "Then the snap is not able to access an evdev keyboard"
if test-snapd-event "-event-kbd" 2> call.error; then
echo "Expected permission error calling evtest with disconnected plug"
exit 1
fi
# AppArmor is 'Permission denied' which is expected with default policy
MATCH "Permission denied" < call.error
echo "When the joystick plug is connected"
snap connect test-snapd-event:joystick
# Note, '-event-kbd' devices aren't joysticks (those are -event-joystick
# (evdev event*) and -joystick (js*)) and therefore shouldn't be added to
# the device cgroup when the joystick interface is plugged.
echo "Then the snap is still not able to access an evdev keyboard"
retry -n 5 --wait 1 sh -c '! test-snapd-event "-event-kbd" 2> call.error'
# device cgroup is 'Operation not permitted' which is expected when the
# joystick interface is connected since a keyboard shouldn't be added to
# the device cgroup.
MATCH "Operation not permitted" < call.error
# joystick AppArmor profile allows access to devices which are also included
# in device buttons, make sure we start in clean state and disconnect the
# joystick interface
snap disconnect test-snapd-event:joystick
# 2. Device Buttons
echo "Then the snap is not able to access an evdev keyboard"
retry -n 5 --wait 1 sh -c '! test-snapd-event "-event-kbd" 2> call.error'
# AppArmor is 'Permission denied' which is expected with default policy, and
# the AppArmor LSM being evaluated first
MATCH "Permission denied" < call.error
echo "When the device-buttons plug is connected"
snap connect test-snapd-event:device-buttons
# Note, '-event-kbd' devices aren't device buttons (those are
# -gpio-keys-event (evdev event*) and therefore shouldn't be added to
# the device cgroup when the device-buttons interface is plugged.
echo "Then the snap is still not able to access an evdev keyboard"
retry -n 5 --wait 1 sh -c '! test-snapd-event "-event-kbd" 2> call.error'
# device cgroup is 'Operation not permitted' which is expected when the
# device-buttons interface is connected since a keyboard shouldn't be added
# to the device cgroup. Even though AppArmor path-based permissions allow
# access to given device, it still gets blocked by device cgroup filtering.
MATCH "Operation not permitted" < call.error
|