All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alper Nebi Yasak <alpernebiyasak@gmail.com>
To: u-boot@lists.denx.de
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>,
	Simon Glass <sjg@chromium.org>, Bin Meng <bmeng.cn@gmail.com>,
	AKASHI Takahiro <takahiro.akashi@linaro.org>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Marek Vasut <marek.vasut@gmail.com>,
	Tom Rini <trini@konsulko.com>,
	Alper Nebi Yasak <alpernebiyasak@gmail.com>
Subject: [PATCH v3 3/3] Azure: Add loop devices and CAP_SYS_ADMIN for sandbox test.py tests
Date: Mon, 21 Jun 2021 21:51:56 +0300	[thread overview]
Message-ID: <20210621185156.9108-4-alpernebiyasak@gmail.com> (raw)
In-Reply-To: <20210621185156.9108-1-alpernebiyasak@gmail.com>

The filesystem test setup needs to prepare disk images for its tests,
with either guestmount or loop mounts. The former requires access to the
host fuse device (added in a previous patch), the latter requires access
to host loop devices. Both mounts also need additional privileges since
docker's default configuration prevents the containers from mounting
filesystems (for host security).

Add any available loop devices to the container and try to add as few
privileges as possible to run these tests, which narrow down to adding
SYS_ADMIN capability and disabling apparmor confinement. However, this
much still seems to be insecure enough to let malicious container
processes escape as root on the host system [1].

[1] https://blog.trailofbits.com/2019/07/19/understanding-docker-container-escapes/

Since the mentioned tests are marked to run only on the sandbox board,
add these additional devices and privileges only when testing with that.

An alternative to using mounts is modifying the filesystem tests to use
virt-make-fs (like some EFI tests do), but it fails to generate a
partitionless FAT filesystem image on Debian systems. Other more
feasible alternatives are using guestfish or directly using libguestfs
Python bindings to create and populate the images, but switching the
test setups to these is nontrivial and is left as future work.

Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
---

(no changes since v2)

Changes in v2:
- Always pass in /dev/fuse to Azure's docker run invocation.
- Remove "and some EFI tests" from comment (no longer applies to that
  block of code).

 .azure-pipelines.yml | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/.azure-pipelines.yml b/.azure-pipelines.yml
index 976868dd2eb7..e36a27c97d56 100644
--- a/.azure-pipelines.yml
+++ b/.azure-pipelines.yml
@@ -318,8 +318,22 @@ jobs:
           # as sandbox testing need create files like spi flash images, etc.
           # (TODO: clean up this in the future)
           chmod 777 .
+          # Filesystem tests need extra docker args to run
+          set --
+          if [[ "${TEST_PY_BD}" == "sandbox" ]]; then
+              # mount -o loop needs the loop devices
+              if modprobe loop; then
+                  for d in $(find /dev -maxdepth 1 -name 'loop*'); do
+                      set -- "$@" --device $d:$d
+                  done
+              fi
+              # Needed for mount syscall (for guestmount as well)
+              set -- "$@" --cap-add SYS_ADMIN
+              # Default apparmor profile denies mounts
+              set -- "$@" --security-opt apparmor=unconfined
+          fi
           # Some tests using libguestfs-tools need the fuse device to run
-          docker run --device /dev/fuse:/dev/fuse -v $PWD:$(work_dir) $(ci_runner_image) /bin/bash $(work_dir)/test.sh
+          docker run "$@" --device /dev/fuse:/dev/fuse -v $PWD:$(work_dir) $(ci_runner_image) /bin/bash $(work_dir)/test.sh
 
   - job: build_the_world
     displayName: 'Build the World'
-- 
2.32.0


  parent reply	other threads:[~2021-06-21 18:52 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-21 18:51 [PATCH v3 0/3] Fix CIs skipping filesystem, EFI secure boot and EFI capsule tests Alper Nebi Yasak
2021-06-21 18:51 ` [PATCH v3 1/3] tools: docker: Install a readable kernel for libguestfs-tools Alper Nebi Yasak
2021-07-06  0:58   ` Tom Rini
2021-06-21 18:51 ` [PATCH v3 2/3] Azure: Add fuse device for test.py tests Alper Nebi Yasak
2021-07-06  0:59   ` Tom Rini
2021-06-21 18:51 ` Alper Nebi Yasak [this message]
2021-06-26 18:29   ` [PATCH v3 3/3] Azure: Add loop devices and CAP_SYS_ADMIN for sandbox " Simon Glass
2021-06-26 20:46     ` Tom Rini
2021-06-27 14:43       ` Simon Glass
2021-07-06  0:59   ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210621185156.9108-4-alpernebiyasak@gmail.com \
    --to=alpernebiyasak@gmail.com \
    --cc=bmeng.cn@gmail.com \
    --cc=daniel.schwierzeck@gmail.com \
    --cc=marek.vasut@gmail.com \
    --cc=sjg@chromium.org \
    --cc=takahiro.akashi@linaro.org \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.