netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: Thomas Haller <thaller@redhat.com>
Cc: NetFilter <netfilter-devel@vger.kernel.org>
Subject: Re: [PATCH nft] tests/shell: allow running tests as non-root users
Date: Thu, 31 Aug 2023 18:08:38 +0200	[thread overview]
Message-ID: <20230831160838.GG15759@breakpoint.cc> (raw)
In-Reply-To: <20230830113153.877968-1-thaller@redhat.com>

Thomas Haller <thaller@redhat.com> wrote:
> Allow to opt-out from the have-real-root check via
> 
>   NFT_TEST_ROOTLESS=1 ./run-tests.sh

I don't like this.  But its a step in the right direction.

To me run-tests.sh has following issues/pain points:
 - test duration is huge (>10m with debug kernels)
 - all tests run in same netns
 - tries to unloads kernel modules after each test

The need for uid 0 wasn't big on my problem list so far because
I mostly run the tests in a VM.  But I agree its an issue for
auto-build systems / CI and the like.

> For that to be useful, we must also unshare the PID and user namespace
> and map the root user inside that namespace.

Are you sure PIDNS unshare is needed for this?

> Test that don't work without real root should check for
> [ "$NFT_TEST_HAVE_REALROOT" != 1 ] and skip gracefully.

Thats fine, see my recent RFC to add such environment
variables to check if a particular feature is supported or not.

What I don't like here is the NFT_TEST_ROOTLESS environment
variable to alter behaviour of run-tests.sh behavior, but see below.

> -if [ "$(id -u)" != "0" ] ; then
> +if [ "$NFT_TEST_HAVE_REALROOT" = "" ] ; then
> +	# The caller can set NFT_TEST_HAVE_REALROOT to indicate us whether we
> +	# have real root. They usually don't need, and we detect it now based
> +	# on `id -u`. Note that we may unshare below, so the check inside the
> +	# new namespace won't be conclusive. We thus only detect once and export
> +	# the result.
> +	export NFT_TEST_HAVE_REALROOT="$(test "$(id -u)" = "0" && echo 1 || echo 0)"
> +fi
> +

Why not get rid of the check?  Just auto-switch to unpriv userns and
error out if that fails.  You could just print a warning/notice here and
then try userns mode.  And/or print a notice at the together with the
test summary.

> +if [ "$NFT_TEST_NO_UNSHARE" = 1 ]; then
> +	# The user opts-out from unshare. Proceed without.

Whats the use case?  If there is a good one, then i'd prefer a command
line switch rather than environment.

I think long term all of the following would be good to have:

1. run each test in its own netns
2. get rid of the forced 'nft flush ruleset' and the rmmod calls
3. Explore parallelisation of tests to reduce total test time
4. Add a SKIP return value, that tells that the test did not run
  (or some other means that allows run-tests.sh to figure out that
   a particular test did not run because its known to not work on
   current configuration).

This would avoid false-positive 'all tests passed' when in reality
some test had to 'exit 0' because of a missing feature or lack of real
root.

Alternatively we could just make these tests fail and leave it to the
user to figure it out, the normal expectation is for all tests to pass,
its mostly when run-tests.sh is run on older kernel releases when it
starts acting up.

  reply	other threads:[~2023-08-31 16:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-30 11:31 [PATCH nft] tests/shell: allow running tests as non-root users Thomas Haller
2023-08-31 16:08 ` Florian Westphal [this message]
2023-08-31 17:26   ` Thomas Haller
2023-08-31 18:18     ` Florian Westphal
2023-09-01 14:56       ` Thomas Haller

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=20230831160838.GG15759@breakpoint.cc \
    --to=fw@strlen.de \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=thaller@redhat.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).