Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ might have to add `~/.local/bin` to your user's `PATH`.

```shell
git clone https://github.com/systemd/mkosi
ln -s $PWD/mkosi/bin/mkosi ~/.local/bin/mkosi
ln -s $PWD/bin/mkosi ~/.local/bin/mkosi
mkosi --version
```

Expand Down
1 change: 1 addition & 0 deletions mkosi/resources/mkosi-tools/mkosi.conf.d/fedora/mkosi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ Packages=
erofs-utils
pkcs11-provider
python3-pefile
systemd-boot-unsigned
13 changes: 13 additions & 0 deletions mkosi/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ def tree_has_selinux_xattr(path: Path) -> bool:
)


def tree_has_ima_xattr(path: Path) -> bool:
return any(
"security.ima" in os.listxattr(p, follow_symlinks=False) for p in (path, *path.rglob("*"))
)
Comment on lines +102 to +104
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ruff complains

Suggested change
return any(
"security.ima" in os.listxattr(p, follow_symlinks=False) for p in (path, *path.rglob("*"))
)
return any("security.ima" in os.listxattr(p, follow_symlinks=False) for p in (path, *path.rglob("*")))

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c&p from tree_has_selinux_xattr. We may want to generalize the function instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ruff complains here because security.ima is shorter than security.selinux and therefore this fits on a single line. Either way, this needs to be addressed.



def copy_tree(
src: Path,
dst: Path,
Expand All @@ -118,9 +124,16 @@ def copy_tree(
attrs = "mode,links"
if preserve:
attrs += ",timestamps,ownership"
with_xattrs = True

# Trying to copy selinux xattrs to overlayfs fails with "Operation not supported" in containers.
if statfs(os.fspath(dst.parent)) != OVERLAYFS_SUPER_MAGIC or not tree_has_selinux_xattr(src):
with_xattrs = False

if tree_has_ima_xattr(src):
with_xattrs = False
Comment on lines +133 to +134
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems problematic, since even if we decided to e.g. copy xattr to keep selinux attributes around, we'd drop them if a file also has these xattrs.

Despite being a bit annoying is there any issue with the warning from cp?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cp fails with exit 1

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but since this is the same as security.selinux then, shouldn't it be be

statfs(os.fspath(dst.parent)) != OVERLAYFS_SUPER_MAGIC 
or (not tree_has_selinux_xattr(src) and not tree_has_ima_xattr(src))

then?


if with_xattrs:
attrs += ",xattr"

def copy() -> None:
Expand Down