tmpfiles: add the a and A entries, POSIX ACLs

The tpm2-tss package sets a default ACL on its keystore:

    d  /var/lib/tpm2-tss/system/keystore 2775 tss tss - -
    a+ /var/lib/tpm2-tss/system/keystore -    -   -   - default:group:tss:rwx

tmpfiles skipped the a+ line as unsupported, so what was created in
the keystore did not get the group access it relies on.

Add a and A, the latter recursive, with and without +.  With + the
entries are added to the ACL of the path, without it they replace it.
The ACL is written to the system.posix_acl_access and _default
extended attributes in the format the kernel uses, which saves a
dependency on libacl.  As with setfacl, the mask is made to cover the
named entries unless the entry sets one.

An ACL can have at most 32 entries.  A path with more is left as it
is, with a warning.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2026-11-20 18:02:33 +01:00
1 parent 3bc7c83731
commit f8571aba1f
4 files changed
+406

No files matched your search

+76
View File
@@ -0,0 +1,76 @@
#!/bin/sh
# Verify the a and A entries of tmpfiles, POSIX ACLs. The sysroot has
# no getfacl, so this looks at what an ACL does to the mode: the group
# bits show the mask, and a default ACL replaces the umask for what is
# created in the directory.
set -eu
TEST_DIR=$(dirname "$0")
DIR=/tmp/acl
CONF=/tmp/acl.conf
tmpfiles()
{
run "cat > $CONF"
run "/libexec/finit/tmpfiles --create $CONF"
}
assert_mode()
{
assert "Mode of $1 is $2" "$(texec stat -c %a "$1")" = "$2"
}
test_teardown()
{
say "Running test teardown."
run "rm -rf $DIR $CONF"
}
# shellcheck source=/dev/null
. "$TEST_DIR/lib/setup.sh"
sep
say 'Default ACL on a directory, as in tpm2-tss-fapi.conf'
tmpfiles <<CONF
#Type Path Mode User Group Age Argument
d $DIR/keystore 2775 daemon daemon - -
a+ $DIR/keystore - - - - default:group:daemon:rwx
d $DIR/plain 2775 daemon daemon - -
CONF
run "umask 077; mkdir $DIR/keystore/sub $DIR/plain/sub; touch $DIR/keystore/file"
assert_mode $DIR/plain/sub 2700
assert_mode $DIR/keystore/sub 2775
assert_mode $DIR/keystore/file 664
sep
say 'a+ adds to the ACL of a file, a replaces it'
run "touch $DIR/file; chmod 600 $DIR/file"
tmpfiles <<CONF
a+ $DIR/file - - - - user:daemon:r--
CONF
assert_mode $DIR/file 640
tmpfiles <<CONF
a+ $DIR/file - - - - g:bin:rw-
CONF
assert_mode $DIR/file 660
tmpfiles <<CONF
a $DIR/file - - - - u:sys:--x
CONF
assert_mode $DIR/file 610
tmpfiles <<CONF
a+ $DIR/file - - - - m::r
CONF
assert_mode $DIR/file 640
sep
say 'A is recursive, and X is x only for a directory or an executable'
run "mkdir -p $DIR/tree/sub; touch $DIR/tree/sub/file $DIR/tree/sub/prog"
run "chmod 700 $DIR/tree $DIR/tree/sub $DIR/tree/sub/prog; chmod 600 $DIR/tree/sub/file"
tmpfiles <<CONF
A $DIR/tree - - - - u:daemon:rwX
CONF
assert_mode $DIR/tree 770
assert_mode $DIR/tree/sub 770
assert_mode $DIR/tree/sub/prog 770
assert_mode $DIR/tree/sub/file 660