Add Darwin/macOS support for SSS and Tang pins
Summary
This adds macOS/Darwin compatibility to the SSS and Tang pins by replacing Linux-specific APIs with POSIX equivalents and making the LUKS test suite gracefully skip when cryptsetup is unavailable.
Tested on macOS 26 (aarch64-darwin) — Tang and SSS-based encryption and decryption both work correctly.
This may also help with support for #541 and #504
Changes
sss: remove unused sys/epoll.h include from clevis-encrypt-sss.c
This header was included but never used. Removing it fixes a compile error on
Darwin where sys/epoll.h does not exist.
sss: replace Linux epoll with POSIX poll in clevis-decrypt-sss.c
epoll is Linux-specific. The SSS decrypt pin monitors a small number of child
process file descriptors, so poll() is functionally equivalent and is available
on all POSIX platforms.
sss: replace pipe2 with portable pipe + fcntl in sss.c
pipe2(fd, O_CLOEXEC) is Linux-specific. The replacement uses pipe() followed
by fcntl(F_SETFD, FD_CLOEXEC) on both descriptors. This is safe because the
call() function operates in a single-threaded context (the fork follows
immediately), so there is no window for a descriptor leak.
luks: make cryptsetup optional in test suite
The LUKS test meson.build is included unconditionally by the parent build, but
all tests require cryptsetup, which is unavailable on macOS. Changed
find_program('cryptsetup', required: true) to required: false with an early
subdir_done() so the build completes without cryptsetup. No test logic is
altered — when cryptsetup is present, all tests run as before.
Motivation
Clevis is used in NixOS disk encryption workflows (Tang + SSS) to generate and
decrypt JWE-wrapped keys. Being able to run clevis encrypt tang and
clevis encrypt sss on macOS enables Darwin-based workstations to provision
NixOS hosts with encrypted disks without requiring a Linux VM.
Test plan
- [x] Builds on x86_64-linux (NixOS)
- [x] Builds on aarch64-darwin (macOS 26)
- [x]
clevis encrypt tang/clevis decryptround-trip on macOS - [x]
clevis encrypt sss/clevis decryptround-trip on macOS - [x] Existing Linux build and test suite unaffected (no behavior change when cryptsetup is present)
I'll take a look and see if I can reproduce the timeout test failure locally.
EDIT: I reproduced it and think I have the root cause -- working on the fix, moving this to draft until I've resolved it.
The epoll to poll conversion had a subtle bug with fd lifecycle management. When epoll monitors a closed fd, it automatically removes it from the set. Poll doesn't - it keeps returning POLLHUP indefinitely, causing an infinite loop.
Why it wasn't caught initially: I only tested on Darwin (which was the whole point of the port), where the Tang/SSS functionality worked fine for my use case. That was an oversight on my part, I've now verified the whole suite works on all tested platforms. The bug only surfaced when running the full Linux test suite, which exercised edge cases like child process failures and invalid configurations.
The fix:
- Set closed fds to -1 so poll ignores them (matching epoll's auto-removal)
- Handle POLLHUP/POLLERR/POLLNVAL to clean up failed children - but only when there's no POLLIN, since a process can write valid data and immediately exit (setting both POLLHUP and POLLIN). Reading the data first ensures we don't discard valid output.
@sini: Hello, could you please rebase this on top of the current tree? Thanks in advance.
@sergio-correia Sorry, I missed this notification. I'll rebase and update it now!
/packit retest-failed
@sarroutbi what would you like to do here?
/packit test
@sarroutbi what would you like to do here?
Hi @sini,
Great catch on the zombie risk with WNOHANG—clearing the PID before the process fully exits would definitely leak resources. Also, verifying the fcntl return values for the Darwin fallback is a great improvement for stability.
That being said, keeping waitpid(..., 0) as a synchronous blocking call inside the main event loop is dangerous. Even if the pipe is drained, a child could still hang during its internal destruction (e.g., stuck in a signal handler, library destructor, or an internal deadlock). If that happens, the blocking wait will freeze the entire Clevis process, breaking the concurrency of the poll architecture.
If we want to keep the loop 100% non-blocking without micro-managing zombie states, we could leverage the OS kernel before forking by setting SIGCHLD with SA_NOCLDWAIT. This tells the kernel to automatically reap dead children without requiring a synchronous waitpid from the parent.
If that feels out of scope for this Darwin port, a simple deferred cleanup list for active PIDs might be a safer middle ground than a blocking wait.
Let me know what you think!
@sarroutbi You're right that a blocking waitpid has no business in the middle of the poll loop — a child that stalls after closing stdout shouldn't be able to freeze the whole process and starve its siblings. I went with your deferred-cleanup-list suggestion rather than SA_NOCLDWAIT, for two reasons:
SA_NOCLDWAITchanges reaping globally but doesn't actually bound the case you described: a child stuck in a destructor/handler is still alive, so nothing reaps it and nothing is waiting — we'd just lose the ability toSIGTERMit on abort. And its interaction with a laterwait()is left partly unspecified by POSIX (awaitpidwith live children may block until all exit, then failECHILD), which is exactly the kind of cross-platform surprise this port is trying to avoid.- A deferred PID list keeps the reaping explicit and portable, and lets us bound the pathological case with
SIGTERMat teardown.
What changed (clevis-decrypt-sss.c):
- Both in-loop
waitpid(..., 0)sites (thePOLLHUP/error path and the success path) now push the pid onto areap[]list viadefer_reap()instead of blocking. The poll loop is now 100% non-blocking. egressdrains that list withkill(SIGTERM)+waitpid, mirroring the existing aborted-child cleanup. Blocking there is safe — the loop has already finished, so a slow child can't affect its siblings, and theSIGTERMbounds anything that stalls after closing stdout.- No zombies (the
WNOHANGfailure mode), no reliance on signal-disposition inheritance acrossfork, and thenchldrnaccounting / all-negative-fd poll guard are untouched.
Full sss suite passes (success, single-child-fail POLLHUP, all-fail give-up, and the t=2 multi-child variants all exercise the changed paths). Pushed as a separate commit on top.