aa-notify: fix package build install of polkit files

The install of the polkit action files for aa-notify leaks build root
information.

From OBS
  apparmor-utils.noarch: E: file-contains-buildroot (Badness: 10000) /usr/share/polkit-1/actions/com.ubuntu.pkexec.aa-notify.policy

this is present on Ubuntu as well
    <annotate key="org.freedesktop.policykit.exec.path">/build/apparmor-ZUzkoL/apparmor-4.1.0~beta4/debian/tmp/usr/lib/python3/dist-packages/apparmor/update_profile.py</annotate>

this occurs because the {LIB_PATH} template variable is being replaced
with the self.install_lib. Make sure we strip the build prefix if
we are generating the files in a build environment instead of doing
a direct install.

Closes: https://gitlab.com/apparmor/apparmor/-/issues/486
Co-Author: Ryan Lee <ryan.lee@canonical.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
This commit is contained in:
John Johansen 2025-02-13 12:26:29 -08:00
parent 55889ef783
commit b4e6f0449b

View file

@ -27,6 +27,14 @@ import sys
from setuptools import setup from setuptools import setup
from setuptools.command.install import install as _install from setuptools.command.install import install as _install
# removeprefix is only in python 3.9+ support older python versions
def replace_path_prefix(text, prefix):
if text.startswith(prefix):
suffix = text[len(prefix):]
if not suffix.startswith("/"):
suffix = "/" + suffix
return suffix
return text
class Install(_install): class Install(_install):
"""Override setuptools to install the files where we want them.""" """Override setuptools to install the files where we want them."""
@ -65,7 +73,8 @@ class Install(_install):
with open(pkexec_action_name, 'r') as f: with open(pkexec_action_name, 'r') as f:
polkit_template = f.read() polkit_template = f.read()
polkit = polkit_template.format(LIB_PATH=self.install_lib) # don't leak the buildroot into the polkit files
polkit = polkit_template.format(LIB_PATH=replace_path_prefix(self.install_lib, prefix))
if not os.path.exists(prefix + '/usr/share/polkit-1/actions/'): if not os.path.exists(prefix + '/usr/share/polkit-1/actions/'):
self.mkpath(prefix + '/usr/share/polkit-1/actions/') self.mkpath(prefix + '/usr/share/polkit-1/actions/')