Skip to content
This repository was archived by the owner on May 27, 2025. It is now read-only.

Commit 18ee161

Browse files
reidprkchilleri
authored andcommitted
PR #1892: several fixes related to -W testing
1 parent 1d034c3 commit 18ee161

File tree

6 files changed

+72
-18
lines changed

6 files changed

+72
-18
lines changed

.github/workflows/main.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ jobs:
4747
steps:
4848
- uses: actions/checkout@v3
4949

50+
# This allows SSH access to the GitHub Actions VM to debug things that
51+
# only happen on CI. Comment out unless needed. WARNING: tmate.io has
52+
# access to unencrypted SSH traffic.
53+
# See: https://github.com/marketplace/actions/debugging-with-tmate
54+
#- name: set up tmate session
55+
# uses: mxschmitt/action-tmate@v3
56+
# with:
57+
# detached: true
58+
5059
- name: early setup & validation
5160
run: |
5261
[[ -n $CH_TEST_BUILDER ]]

bin/ch-run.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,12 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
451451
exit(0);
452452
#else
453453
exit(1);
454+
#endif
455+
} else if (!strcmp(arg, "overlayfs")) {
456+
#ifdef HAVE_OVERLAYFS
457+
exit(0);
458+
#else
459+
exit(1);
454460
#endif
455461
} else if (!strcmp(arg, "seccomp")) {
456462
#ifdef HAVE_SECCOMP
@@ -463,6 +469,12 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state)
463469
exit(0);
464470
#else
465471
exit(1);
472+
#endif
473+
} else if (!strcmp(arg, "tmpfs-xattrs")) {
474+
#ifdef HAVE_TMPFS_XATTRS
475+
exit(0);
476+
#else
477+
exit(1);
466478
#endif
467479
}
468480
else

bin/ch_core.c

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,27 @@
4141
/* Timeout in seconds for waiting for join semaphore. */
4242
#define JOIN_TIMEOUT 30
4343

44-
/* Maximum length of paths we're willing to deal with. (Note that
44+
/* Maximum length of paths were willing to deal with. (Note that
4545
system-defined PATH_MAX isn't reliable.) */
4646
#define PATH_CHARS 4096
4747

48+
/* Mount point for the tmpfs used by -W. We want this to be (a) always
49+
available [1], (b) short, (c) not used by anything else we care about
50+
during container setup, and (d) not wildly confusing if users see it in an
51+
error message. Must be a string literal because we use C’s literal
52+
concatenation feature. Options considered (all of these required by FHS):
53+
54+
/boot Not present if host is booted in some strange way?
55+
/etc Likely very reliable but seems risky
56+
/mnt Used for images on GitHub Actions and causes CI failures
57+
/opt Seems very omittable
58+
/srv I’ve never actually seen it used; reliable?
59+
/var Too aggressive?
60+
/var/spool Long; omittable for lightweight hosts?
61+
62+
[1]: https://www.pathname.com/fhs/pub/fhs-2.3.pdf */
63+
#define WF_MNT "/srv"
64+
4865

4966
/** Constants **/
5067

@@ -306,26 +323,30 @@ void enter_udss(struct container *c)
306323
// https://www.kernel.org/doc/html/v5.11/filesystems/tmpfs.html
307324
// https://www.kernel.org/doc/html/v5.11/filesystems/overlayfs.html
308325
if (c->overlay_size != NULL) {
309-
VERBOSE("overlaying tmpfs for --write-fake (%s)", c->overlay_size);
310326
char *options;
327+
struct stat st;
328+
VERBOSE("overlaying tmpfs for --write-fake (%s)", c->overlay_size);
311329
T_ (1 <= asprintf(&options, "size=%s", c->overlay_size));
312-
Zf (mount(NULL, "/mnt", "tmpfs", 0, options), // host should have /mnt
330+
Zf (mount(NULL, WF_MNT, "tmpfs", 0, options),
313331
"cannot mount tmpfs for overlay");
314332
free(options);
315-
Z_ (mkdir("/mnt/upper", 0700));
316-
Z_ (mkdir("/mnt/work", 0700));
317-
Z_ (mkdir("/mnt/merged", 0700));
318-
mkdir_scratch = "/mnt/mkdir_overmount";
333+
Z_ (mkdir(WF_MNT "/upper", 0700));
334+
Z_ (mkdir(WF_MNT "/work", 0700));
335+
Z_ (mkdir(WF_MNT "/merged", 0700));
336+
mkdir_scratch = WF_MNT "/mkdir_overmount";
319337
Z_ (mkdir(mkdir_scratch, 0700));
320-
T_ (1 <= asprintf(&options, "lowerdir=%s,upperdir=%s,workdir=%s,"
321-
"index=on,userxattr,volatile",
322-
c->newroot, "/mnt/upper", "/mnt/work"));
338+
T_ (1 <= asprintf(&options, ("lowerdir=%s,upperdir=%s,workdir=%s,"
339+
"index=on,userxattr,volatile"),
340+
c->newroot, WF_MNT "/upper", WF_MNT "/work"));
323341
// update newroot
324-
c->newroot = "/mnt/merged";
342+
Zf (stat(c->newroot, &st),
343+
"can't stat new root; overmounted by tmpfs for -W?: %s", c->newroot);
344+
c->newroot = WF_MNT "/merged";
325345
free(nr_parent);
326346
free(nr_base);
327347
path_split(c->newroot, &nr_parent, &nr_base);
328-
Zf (mount(NULL, c->newroot, "overlay", 0, options), "can't overlay");
348+
Zf (mount(NULL, c->newroot, "overlay", 0, options),
349+
"can't overlay: %s, %s", c->newroot, options);
329350
VERBOSE("newroot updated: %s", c->newroot);
330351
free(options);
331352
}

configure.ac

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -787,6 +787,10 @@ AC_SUBST([CH_RUN_LIBS])
787787
AC_SUBST([PYTHON_SHEBANG])
788788
AC_SUBST([SPHINX])
789789

790+
AS_IF([test $have_overlayfs = yes],
791+
[AC_DEFINE([HAVE_OVERLAYFS], [1], [unprivileged overlayfs])])
792+
AS_IF([test $have_tmpfs_xattrs = yes],
793+
[AC_DEFINE([HAVE_TMPFS_XATTRS], [1], [tmpfs user xattrs])])
790794
AS_IF([test $have_fnm_extmatch = yes],
791795
[AC_DEFINE([HAVE_FNM_EXTMATCH], [1], [extended globs supported])])
792796
AS_IF([test $have_seccomp = yes],

doc/ch-run.rst

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,16 @@ mounting SquashFS images with FUSE.
6060
Don’t expand variables when using :code:`--set-env`.
6161

6262
:code:`--feature=FEAT`
63-
If feature :code:`FEAT` is enabled, exit with success. Valid values of
64-
:code:`FEAT` are :code:`extglob` for extended globs, :code:`seccomp` for
65-
:code:`seccomp(2)`, and :code:`squash` for squashfs archives.
63+
If feature :code:`FEAT` is enabled, exit successfully (zero); otherwise,
64+
exit unsuccessfully (non-zero). Note this just communicates the results of
65+
:code:`configure` rather than testing the feature. Valid values of
66+
:code:`FEAT` are:
67+
68+
* :code:`extglob`: extended globs in :code:`--unset-env`
69+
* :code:`seccomp`: :code:`--seccomp` available
70+
* :code:`squash`: internal SquashFUSE image mounts
71+
* :code:`overlayfs`: unprivileged overlayfs support
72+
* :code:`tmpfs-xattrs`: :code:`user` xattrs on tmpfs
6673

6774
:code:`-g`, :code:`--gid=GID`
6875
Run as group :code:`GID` within container.

test/run/ch-run_misc.bats

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ setup () {
1212

1313

1414
demand-overlayfs () {
15-
ch-run -W "$ch_timg" -- true || skip 'no unpriv overlayfs'
15+
ch-run --feature=overlayfs || skip 'no unpriv overlayfs'
1616
}
1717

1818

@@ -291,10 +291,11 @@ EOF
291291
[[ $status -eq 0 ]]
292292

293293
# --home
294-
run ch-run --home "$img" -- ls -lah /home
294+
run ch-run --home "$img" -- ls -lAh /home
295295
echo "$output"
296296
[[ $status -eq 0 ]]
297-
[[ $(echo "$output" | wc -l) -eq 3 ]]
297+
[[ $(echo "$output" | wc -l) -eq 5 ]] # 4 files plus “total” line
298+
[[ $output = *.orig* ]]
298299
[[ $output = *directory-in-home* ]]
299300
[[ $output = *file-in-home* ]]
300301
[[ $output = *"$USER"* ]]

0 commit comments

Comments
 (0)