Skip to content

Commit

Permalink
Merge pull request #2180 from matusmarhefka/oscap-bootc_dependencies
Browse files Browse the repository at this point in the history
Update oscap-bootc to verify it runs in bootable container env
  • Loading branch information
jan-cerny authored Nov 27, 2024
2 parents c2ba1cb + c8a2517 commit e4ddfc8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
1 change: 0 additions & 1 deletion openscap.spec
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ Summary: OpenSCAP Utilities
Requires: %{name}%{?_isa} = %{epoch}:%{version}-%{release}
Requires: rpmdevtools rpm-build
Requires: %{name}-scanner%{?_isa} = %{epoch}:%{version}-%{release}
Requires: %{name}-engine-sce%{?_isa} = %{epoch}:%{version}-%{release}

%description utils
The %{name}-utils package contains command-line tools build on top
Expand Down
20 changes: 13 additions & 7 deletions utils/oscap-bootc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import subprocess
import sys
import tempfile

from pathlib import Path


def parse_args():
parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -52,17 +54,21 @@ def parse_args():
return parser.parse_args()


def ensure_sce_installed():
query_cmd = ["rpm", "-q", "openscap-engine-sce"]
query_process = subprocess.run(query_cmd, capture_output=True)
if query_process.returncode != 0:
def verify_bootc_build_env():
rv = subprocess.run(
["rpm", "-q", "bootc"],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
bootc_env = (rv.returncode == 0)
container_env = Path("/run/.containerenv").exists()
if not bootc_env or not container_env:
raise RuntimeError(
"The script requires to have the openscap-engine-sce package "
"installed.")
"This script is supposed to be used only in the bootable "
"container build environment.")


def install_sce_dependencies():
required_packages = [
"openscap-engine-sce",
"setools-console" # seinfo is used by the sebool template
]
install_cmd = ["dnf", "-y", "install"] + required_packages
Expand Down Expand Up @@ -124,7 +130,7 @@ def scan_and_remediate(args):

def main():
args = parse_args()
ensure_sce_installed()
verify_bootc_build_env()
install_sce_dependencies()
pre_scan_fix(args)
scan_and_remediate(args)
Expand Down

0 comments on commit e4ddfc8

Please sign in to comment.