From e11d86cdf31ac5cd987b9129fe141ddb2d341754 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Fri, 18 Mar 2022 14:23:41 +0100 Subject: [PATCH] util/selinux: define XATTR_NAME_SELINUX Define the extended attribute name for SELinux at the module level and use that in the `getfilecon` function. --- osbuild/util/selinux.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/osbuild/util/selinux.py b/osbuild/util/selinux.py index 26ad5995..c66f3a10 100644 --- a/osbuild/util/selinux.py +++ b/osbuild/util/selinux.py @@ -5,6 +5,9 @@ import subprocess from typing import Dict, TextIO +# Extended attribute name for SELinux labels +XATTR_NAME_SELINUX = b"security.selinux" + def parse_config(config_file: TextIO): """Parse an SELinux configuration file""" @@ -51,6 +54,6 @@ def setfiles(spec_file: str, root: str, *paths): def getfilecon(path: str) -> str: """Get the security context associated with `path`""" - label = os.getxattr(path, b"security.selinux", + label = os.getxattr(path, XATTR_NAME_SELINUX, follow_symlinks=False) return label.decode().strip('\n\0')