Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge maint-1.3 to main #2176

Merged
merged 29 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
34a53de
Version bump after release.
evgenyz Mar 18, 2024
6e69487
Enable Packit builds on commit
evgenyz Apr 15, 2024
29a97f0
Disable Perl bindings on Windows
jan-cerny Apr 30, 2024
1950757
Merge pull request #2105 from jan-cerny/disable_perl_win32
evgenyz Apr 30, 2024
6b0615f
Ensure xlink namespace exists
jan-cerny Apr 29, 2024
da1d1bd
Merge pull request #2104 from jan-cerny/RHEL-34104
evgenyz Apr 30, 2024
b6123ec
Cleanup CI for maint-1.3 branch
evgenyz Sep 2, 2024
b903676
Merge pull request #2157 from evgenyz/cleanup-maint-1.3-ci
Mab879 Sep 6, 2024
5400167
Improve rpm database path in RPM probes
jan-cerny Aug 22, 2024
8c7ef5d
Merge pull request #2156 from jan-cerny/rpmdb
matusmarhefka Sep 13, 2024
f827978
Allow preferring SCE
jan-cerny Oct 10, 2024
d977ad5
Add a test case for the invalid value
jan-cerny Oct 15, 2024
97d8831
Merge pull request #2165 from jan-cerny/prefer_sce2
matusmarhefka Oct 17, 2024
7ba95a9
Introduce generating bootc remediation
jan-cerny Oct 11, 2024
c2c3a9f
Add a simple test
jan-cerny Oct 11, 2024
4b6d0f2
Rename "package" keyword to "dnf"
jan-cerny Oct 17, 2024
93e6ee3
Merge pull request #2166 from jan-cerny/bootc_sce
matusmarhefka Oct 22, 2024
afe3b67
Introduce oscap-bootc
jan-cerny Oct 21, 2024
967892c
Change python to python3
jan-cerny Oct 22, 2024
e0634de
Document command line options properly
jan-cerny Oct 23, 2024
008d333
Make openscap-utils require openscap-engine-sce
jan-cerny Oct 23, 2024
4383299
Do not install openscap-engine-sce as a part of the script
jan-cerny Oct 23, 2024
2f5de09
Merge pull request #2169 from jan-cerny/oscap_bootc_tool
matusmarhefka Oct 23, 2024
502d41b
Pass OSCAP_BOOTC_BUILD to remediations
jan-cerny Oct 22, 2024
298d612
Merge pull request #2170 from jan-cerny/pass_down
matusmarhefka Oct 23, 2024
391d736
Extend oscap-bootc to install SCE dependencies
matusmarhefka Nov 1, 2024
a7eb860
Merge pull request #2171 from matusmarhefka/bootc_sebool_sce
jan-cerny Nov 4, 2024
4c6994c
Merge remote-tracking branch 'upstream/maint-1.3'
jan-cerny Nov 11, 2024
8d6ea6c
Revert changes to GH workflows
jan-cerny Nov 13, 2024
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
13 changes: 6 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ name: Gating
# events but only for the main branch
on:
push:
branches: [ '*' ]
branches: [ maint-1.3 ]
pull_request:
branches: [ main, maint-1.3 ]
branches: [ maint-1.3 ]
matusmarhefka marked this conversation as resolved.
Show resolved Hide resolved


# A workflow run is made up of one or more jobs that can run sequentially or in parallel
Expand All @@ -21,7 +21,7 @@ jobs:

strategy:
matrix:
os: [ubuntu-20.04, ubuntu-latest]
os: [ubuntu-22.04]

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
Expand Down Expand Up @@ -148,7 +148,7 @@ jobs:
path: ${{ github.workspace }}/vcpkg
repository: microsoft/vcpkg
fetch-depth: 1

- name: Bootstrap vcpkg
shell: pwsh
run: "${{ github.workspace }}\\vcpkg\\scripts\\bootstrap.ps1 -disableMetrics"
Expand All @@ -159,9 +159,8 @@ jobs:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');

- name: Install Deps
run: "${{ github.workspace }}\\vcpkg\\vcpkg.exe install curl libxml2 libxslt bzip2 pcre2 pthreads zlib getopt-win32 xmlsec --triplet x64-windows"
run: "${{ github.workspace }}\\vcpkg\\vcpkg.exe install curl libxml2 libxslt bzip2 pcre pthreads zlib getopt-win32 xmlsec --triplet x64-windows"

- name: Configure
working-directory: ./build
Expand All @@ -170,7 +169,7 @@ jobs:
- name: Build
run: cmake --build . --config Release
working-directory: ./build

- name: Package
run: cpack
working-directory: build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ jobs:
make all

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ cmake_dependent_option(ENABLE_OSCAP_UTIL_AS_RPM "enable the scap-as-rpm utility,
cmake_dependent_option(ENABLE_OSCAP_UTIL_SSH "enables the oscap-ssh utility, this lets you scan remote machines over ssh" ON "NOT WIN32" OFF)
cmake_dependent_option(ENABLE_OSCAP_UTIL_VM "enables the oscap-vm utility, this lets you scan VMs and VM storage images" ON "NOT WIN32" OFF)
cmake_dependent_option(ENABLE_OSCAP_UTIL_PODMAN "enables the oscap-podman utility, this lets you scan Podman containers and container images" ON "NOT WIN32" OFF)
cmake_dependent_option(ENABLE_OSCAP_UTIL_BOOTC "enables the oscap-bootc utility, this lets you build hardened bootable container images" ON "NOT WIN32" OFF)
cmake_dependent_option(ENABLE_OSCAP_UTIL_CHROOT "enables the oscap-chroot utility, this lets you scan entire chroots using offline scanning" ON "NOT WIN32" OFF)
option(ENABLE_OSCAP_UTIL_AUTOTAILOR "enables the autotailor utility that is able to perform command-line tailoring" TRUE)
option(ENABLE_OSCAP_REMEDIATE_SERVICE "enables the oscap-remediate service" FALSE)
Expand Down Expand Up @@ -467,6 +468,7 @@ message(STATUS "scap-as-rpm: ${ENABLE_OSCAP_UTIL_AS_RPM}")
message(STATUS "oscap-ssh: ${ENABLE_OSCAP_UTIL_SSH}")
message(STATUS "oscap-vm: ${ENABLE_OSCAP_UTIL_VM}")
message(STATUS "oscap-podman: ${ENABLE_OSCAP_UTIL_PODMAN}")
message(STATUS "oscap-bootc: ${ENABLE_OSCAP_UTIL_BOOTC}")
message(STATUS "oscap-chroot: ${ENABLE_OSCAP_UTIL_CHROOT}")
message(STATUS "autotailor: ${ENABLE_OSCAP_UTIL_AUTOTAILOR}")
message(STATUS " ")
Expand Down
38 changes: 38 additions & 0 deletions docs/manual/manual.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,7 @@ If OpenSCAP is executed with verbosity level INFO or DEVEL their runtime values
* `OSCAP_PROBE_MEMORY_USAGE_RATIO` - maximum memory usage ratio (used/total) for OpenSCAP probes, default: 0.1
* `OSCAP_PROBE_MAX_COLLECTED_ITEMS` - maximal count of collected items by OpenSCAP probe for a single OVAL object evaluation
* `OSCAP_PROBE_IGNORE_PATHS` - Skip given paths during evaluation. If multiple paths should be skipped they need to be separated by a colon. The paths should be absolute canonical paths.
* `OSCAP_PREFERRED_ENGINE` - Set a preffered check engine for XCCDF rules. If a rule has multiple checks, the checks for the preffered check engine will be used. Allowed values: `SCE`, `OVAL`. If this variable is set to `SCE` and a rule has both SCE and OVAL checks the SCE check will be used. If this variable is set to `OVAL` and a rule has both SCE and OVAL checks the OVAL check will be used. If this environment variable isn't set, the standard XCCDF mechanism will be used for check selection.

Also, OpenSCAP uses `libcurl` library which also can be configured using environment variables. See https://curl.se/libcurl/c/libcurl-env.html[the list of libcurl environment variables].

Expand Down Expand Up @@ -1839,6 +1840,43 @@ registry.access.redhat.com/ubi8 latest 3269c37eae33 2 months ago 208 MB

Note that the `oscap-podman` command requires root privileges.

=== Building hardened bootable container images using oscap-bootc

The `oscap-bootc` tool is a convenience script that makes building hardened bootable container images easier.
This tool is designed to be used during the build of the bootable container image.

Include `oscap-bootc` in your `Containerfile` that will be used to build your bootable container image.
The `Containerfile` first needs to install the `openscap-utils` package which ships the `oscap-bootc` tool.

Also, SCAP content needs to be installed to the image before `oscap-bootc` will be run.
Although any SCAP content can be consumed by the tool, the SCAP source data streams shipped in `scap-security-guide` are specially cared to be compatible with bootable containers.

Example `Containerfile`:

----
FROM quay.io/centos-bootc/centos-bootc:stream9

RUN dnf install -y openscap-utils scap-security-guide

RUN oscap-bootc --profile stig /usr/share/xml/scap/ssg/content/ssg-cs9-ds.xml
----

Once you have your `Containerfile`, execute the image build:

----
podman build -t hardened_image .
----

The `oscap-bootc` tool installs and removes all packages required by the selected profile to or from the image.
Then, it runs a scan and remediation with the selected profile.
It doesn't use offline scanning.
The configuration files and other content in the image are modified by this process, depending on the used SCAP content.

The built bootable container image can be then deployed and booted.
After booting the image, the state of the resulting system will be in line with the selected security profile.

The `oscap-bootc` tool can't be used anywhere else than in a `Containerfile`.

=== Scanning of Docker containers and images using oscap-docker

The `oscap-docker` is used to scan Docker containers and images. It can
Expand Down
1 change: 1 addition & 0 deletions openscap.spec
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ 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
29 changes: 29 additions & 0 deletions src/OVAL/probes/unix/linux/rpm-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,32 @@ void rpmLibsPreload()
const char* rcfiles = "";
rpmReadConfigFiles(rcfiles, NULL);
}

void set_rpm_db_path()
{
/*
* Fedora >=36 changed the default dbpath in librpm from /var/lib/rpm to /usr/lib/sysimage/rpm.
* See: https://fedoraproject.org/wiki/Changes/RelocateRPMToUsr
*
* Therefore, when running openscap on a Fedora >=36 system scanning another systems (such as RHEL, SLES, Fedora<36)
* openscap's librpm will try to read the rpm db from /usr/lib/sysimage/rpm which doesn't exist and therefore won't work.
* On many systems, /var/lib/rpm is still a symlink to /usr/lib/sysimage/rpm, so using /var/lib/rpm can work there.
* However, on some systems, eg. bootc images, /var/lib/rpm isn't a symlink and doesn't contain the RPM database.
*
* We will first try if the "new" location /usr/lib/sysimage/rpm exists, and use it only if it exists.
* If it doesn't exist, we will fall back to the "old" location /var/lib/rpm.
*/

struct stat sb;
const char *dbpath;
const char *prefix = getenv("OSCAP_PROBE_ROOT");
char *path_with_prefix = oscap_path_join(prefix, "/usr/lib/sysimage/rpm");
if (stat(path_with_prefix, &sb) == 0) {
dbpath = "/usr/lib/sysimage/rpm";
} else {
dbpath = "/var/lib/rpm";
}
free(path_with_prefix);
dI("Using %s as rpm database.", dbpath);
rpmPushMacro(NULL, "_dbpath", NULL, dbpath, RMIL_CMDLINE);
}
3 changes: 3 additions & 0 deletions src/OVAL/probes/unix/linux/rpm-helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,7 @@ int rpmVerifyFile(const rpmts ts, const rpmfi fi,
*/
void rpmLibsPreload(void);

void set_rpm_db_path(void);


#endif
12 changes: 1 addition & 11 deletions src/OVAL/probes/unix/linux/rpminfo_probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,17 +294,7 @@ void *rpminfo_probe_init(void)
return ((void *)g_rpm);
}

/*
* Fedora >=36 changed the default dbpath in librpm from /var/lib/rpm to /usr/lib/sysimage/rpm
* See: https://fedoraproject.org/wiki/Changes/RelocateRPMToUsr
* Therefore, when running openscap on a Fedora >=36 system scanning another systems (such as RHEL, SLES, Fedora<36)
* openscap's librpm will try to read the rpm db from /usr/lib/sysimage/rpm which doesn't exist and therefore won't work.
* In implementing this change, /var/lib/rpm is still a symlink to /usr/lib/sysimage/rpm
* so /var/lib/rpm still works. So /var/lib/rpm is a dbpath that will work on all systems.
* Therefore, set the dbpath to be /var/lib/rpm, allow openscap running on any system to scan any system.
*/
rpmPushMacro(NULL, "_dbpath", NULL, "/var/lib/rpm", RMIL_CMDLINE);

set_rpm_db_path();
g_rpm->rpmts = rpmtsCreate();
pthread_mutex_init (&(g_rpm->mutex), NULL);

Expand Down
11 changes: 1 addition & 10 deletions src/OVAL/probes/unix/linux/rpmverify_probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,7 @@ void *rpmverify_probe_init(void)
return (NULL);
}

/*
* Fedora >=36 changed the default dbpath in librpm from /var/lib/rpm to /usr/lib/sysimage/rpm
* See: https://fedoraproject.org/wiki/Changes/RelocateRPMToUsr
* Therefore, when running openscap on a Fedora >=36 system scanning another systems (such as RHEL, SLES, Fedora<36)
* openscap's librpm will try to read the rpm db from /usr/lib/sysimage/rpm which doesn't exist and therefore won't work.
* In implementing this change, /var/lib/rpm is still a symlink to /usr/lib/sysimage/rpm
* so /var/lib/rpm still works. So /var/lib/rpm is a dbpath that will work on all systems.
* Therefore, set the dbpath to be /var/lib/rpm, allow openscap running on any system to scan any system.
*/
rpmPushMacro(NULL, "_dbpath", NULL, "/var/lib/rpm", RMIL_CMDLINE);
set_rpm_db_path();

struct rpm_probe_global *g_rpm = malloc(sizeof(struct rpm_probe_global));
g_rpm->rpmts = rpmtsCreate();
Expand Down
11 changes: 1 addition & 10 deletions src/OVAL/probes/unix/linux/rpmverifyfile_probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,16 +358,7 @@ void *rpmverifyfile_probe_init(void)

struct rpm_probe_global *g_rpm = malloc(sizeof(struct rpm_probe_global));

/*
* Fedora >=36 changed the default dbpath in librpm from /var/lib/rpm to /usr/lib/sysimage/rpm
* See: https://fedoraproject.org/wiki/Changes/RelocateRPMToUsr
* Therefore, when running openscap on a Fedora >=36 system scanning another systems (such as RHEL, SLES, Fedora<36)
* openscap's librpm will try to read the rpm db from /usr/lib/sysimage/rpm which doesn't exist and therefore won't work.
* In implementing this change, /var/lib/rpm is still a symlink to /usr/lib/sysimage/rpm
* so /var/lib/rpm still works. So /var/lib/rpm is a dbpath that will work on all systems.
* Therefore, set the dbpath to be /var/lib/rpm, allow openscap running on any system to scan any system.
*/
rpmPushMacro(NULL, "_dbpath", NULL, "/var/lib/rpm", RMIL_CMDLINE);
set_rpm_db_path();

g_rpm->rpmts = rpmtsCreate();

Expand Down
11 changes: 1 addition & 10 deletions src/OVAL/probes/unix/linux/rpmverifypackage_probe.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,16 +354,6 @@ void *rpmverifypackage_probe_init(void)
return ((void *)g_rpm);
}

/*
* Fedora >=36 changed the default dbpath in librpm from /var/lib/rpm to /usr/lib/sysimage/rpm
* See: https://fedoraproject.org/wiki/Changes/RelocateRPMToUsr
* Therefore, when running openscap on a Fedora >=36 system scanning another systems (such as RHEL, SLES, Fedora<36)
* openscap's librpm will try to read the rpm db from /usr/lib/sysimage/rpm which doesn't exist and therefore won't work.
* In implementing this change, /var/lib/rpm is still a symlink to /usr/lib/sysimage/rpm
* so /var/lib/rpm still works. So /var/lib/rpm is a dbpath that will work on all systems.
* Therefore, set the dbpath to be /var/lib/rpm, allow openscap running on any system to scan any system.
*/
rpmPushMacro(NULL, "_dbpath", NULL, "/var/lib/rpm", RMIL_CMDLINE);

g_rpm->rpm.rpmts = rpmtsCreate();

Expand All @@ -377,6 +367,7 @@ void *rpmverifypackage_probe_init(void)
rpmtsSetRootDir(g_rpm->rpm.rpmts, CHROOT_PATH());
}

set_rpm_db_path();
pthread_mutex_init(&(g_rpm->rpm.mutex), NULL);
return ((void *)g_rpm);
}
Expand Down
1 change: 1 addition & 0 deletions src/SCE/sce_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ xccdf_test_result_type_t sce_engine_eval_rule(struct xccdf_policy *policy, const
struct xccdf_check_import_iterator *check_import_it,
void *usr)
{
dI("Executing SCE check '%s'", href);
struct sce_parameters* parameters = (struct sce_parameters*)usr;
const char* xccdf_directory = parameters->xccdf_directory;
bool use_sce_wrapper = false; // use osca-run-sce-script ?
Expand Down
10 changes: 10 additions & 0 deletions src/XCCDF_POLICY/xccdf_policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,16 @@ _xccdf_policy_rule_get_applicable_check(struct xccdf_policy *policy, struct xccd
struct xccdf_check *check = xccdf_check_iterator_next(candidate_it);
if (_xccdf_policy_is_engine_registered(policy, (char *) xccdf_check_get_system(check))) {
result = check;
char *preferred_engine = getenv("OSCAP_PREFERRED_ENGINE");
if (preferred_engine) {
if (strcmp("SCE", preferred_engine) && strcmp("OVAL", preferred_engine)) {
dW("Unknown value of OSCAP_PREFFERED_ENGINE: '%s'. It will be ignored.", preferred_engine);
}
if ((!strcmp("SCE", preferred_engine) && !strcmp("http://open-scap.org/page/SCE", check->system)) ||
(!strcmp("OVAL", preferred_engine) && !strcmp("http://oval.mitre.org/XMLSchema/oval-definitions-5", check->system))) {
break;
}
}
} else if (strcmp("http://oval.mitre.org/XMLSchema/oval-definitions-5", check->system) == 0) {
print_oval_warning = true;
} else if (strcmp("http://scap.nist.gov/schema/ocil/2", check->system) == 0) {
Expand Down
Loading