Skip to content

Commit 3dcbda5

Browse files
authored
Merge pull request #2279 from evgenyz/main-merge-2
Merge 1.3
2 parents c8d2262 + 528a5c5 commit 3dcbda5

File tree

10 files changed

+128
-109
lines changed

10 files changed

+128
-109
lines changed

AUTHORS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Alexander Bergmann <abergmann@suse.com>
22
Alexander Scheel <ascheel@redhat.com>
3+
Arden97 <arden2545@gmail.com>
34
Axel Nennker <axel@nennker.de>
45
Brady Alleman <brady@alleman.me>
56
Brandon Dixon <Brandon.Dixon@g2-inc.com>
@@ -23,6 +24,7 @@ Evgeni Golov <egolov@redhat.com>
2324
Evgeny Kolesnikov <ekolesni@redhat.com>
2425
Felix Wolfsteller <felix.wolfsteller@greenbone.net>
2526
Fen Labalme <fen@civicactions.com>
27+
Flos Lonicerae <lonicerae@gmail.com>
2628
Francisco Slavin <fslavin@tresys.com>
2729
Gabe Alford <redhatrises@gmail.com>
2830
Gabriel Gaspar Becker <ggasparb@redhat.com>

docs/manual/manual.adoc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,9 +1617,12 @@ Also, OpenSCAP uses `libcurl` library which also can be configured using environ
16171617

16181618
== Using external or remote resources
16191619

1620-
Some SCAP content references external resources. For example, some content
1621-
can use external OVAL file to check that the system is up to date and has no known
1622-
security vulnerabilities.
1620+
Some SCAP content references external resources. For example, older versions of SCAP Security Guide (prior to version 0.1.73)
1621+
used external OVAL file to check that the system is up to date and has no known
1622+
security vulnerabilities. However, other content can use external resources for
1623+
other purposes.
1624+
1625+
NOTE: Starting with version 0.1.73, SCAP Security Guide content doesn't use external resources anymore.
16231626

16241627
When you are evaluating SCAP content with external resources the `oscap` tool
16251628
will warn you:
@@ -1669,6 +1672,8 @@ $ wget -O ~/scap-files/security-data-oval-com.redhat.rhsa-RHEL8.xml https://www.
16691672
$ oscap xccdf eval --local-files ~/scap-files --profile ospp ssg-rhel8-ds.xml
16701673
----
16711674

1675+
NOTE: The `--local-files` option works only with SCAP 1.3 source data streams. It can't be used with SCAP 1.2 source data streams.
1676+
16721677
== Practical Examples
16731678
This section demonstrates practical usage of certain security content provided
16741679
for Red Hat products.
@@ -2000,6 +2005,7 @@ You can find the ID of the customized profile with `oscap info <your_tailoring_f
20002005

20012006
Yes, it's possible, you can download the file on other computer that is connected to the internet and then copy the file to the system where you run `oscap`.
20022007
Instead of the `--fetch-remote-resources` option you will use the `--local-files` option.
2008+
This option works only with SCAP 1.3 source data streams. It can't be used with SCAP 1.2 source data streams.
20032009
For more information, please refer to section <<_using_external_or_remote_resources,Using external or remote resources>>.
20042010

20052011
*I have generated a kickstart but the generated file isn't a valid kickstart.*

src/DS/ds_sds_session.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,25 @@ void ds_sds_session_configure_remote_resources(struct ds_sds_session *session, b
342342
session->fetch_remote_resources = allowed;
343343
session->local_files = local_files;
344344
session->progress = (callback != NULL) ? callback : download_progress_empty_calllback;
345+
if (local_files != NULL) {
346+
struct ds_sds_index *idx = ds_sds_session_get_sds_idx(session);
347+
struct ds_stream_index_iterator *streams = ds_sds_index_get_streams(idx);
348+
while (ds_stream_index_iterator_has_more(streams)) {
349+
struct ds_stream_index *stream = ds_stream_index_iterator_next(streams);
350+
const char *version = ds_stream_index_get_version(stream);
351+
if (strcmp(version, "1.3")) {
352+
ds_sds_session_remote_resources_progress(session)(
353+
true,
354+
"WARNING: The '--local-files' option can be used only with "
355+
"SCAP 1.3 source data streams, but the provided data stream "
356+
"is version '%s'. No local files will be used.\n",
357+
version);
358+
break;
359+
}
360+
361+
}
362+
ds_stream_index_iterator_free(streams);
363+
}
345364
}
346365

347366
const char *ds_sds_session_local_files(struct ds_sds_session *session)

tests/API/XCCDF/unittests/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,3 @@ add_oscap_test("test_no_newline_between_select_elements.sh")
114114
add_oscap_test("test_single_line_tailoring.sh")
115115
add_oscap_test("test_reference.sh")
116116
add_oscap_test("test_remediation_bootc.sh")
117-
add_oscap_test("test_oscap_bootc_pass_down.sh")

tests/API/XCCDF/unittests/test_oscap_bootc_pass_down.ds.xml

Lines changed: 0 additions & 66 deletions
This file was deleted.

tests/API/XCCDF/unittests/test_oscap_bootc_pass_down.sh

Lines changed: 0 additions & 31 deletions
This file was deleted.

tests/DS/test_ds_use_local_remote_resources.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
# Jan Černý <jcerny@redhat.com>
55

66
set -e -o pipefail
7-
set -x
87

98
. $builddir/tests/test_common.sh
109

@@ -81,3 +80,13 @@ assert_exists 1 '//rule-result[@idref="xccdf_com.example.www_rule_test-pass2"]/r
8180
popd
8281
rm -f "$result" "$stderr"
8382
rm -rf "$tmpdir1" "$tmpdir2" "$tmpdir3"
83+
84+
85+
# test that a warning is shown when --local-files is provided with SCAP 1.2 DS
86+
result=$(mktemp)
87+
stderr=$(mktemp)
88+
tmpdir=$(mktemp -d)
89+
$OSCAP xccdf eval --local-files "$tmpdir" --profile "$PROFILE" --results "$result" "${srcdir}/ds_continue_without_remote_resources/remote_content_1.2.ds.xml" 2>"$stderr" || ret=$?
90+
[ "$ret" = 2 ]
91+
grep -q "WARNING: The '--local-files' option can be used only with SCAP 1.3 source data streams, but the provided data stream is version '1.2'. No local files will be used." "$stderr"
92+
rm -rf "$result" "$stderr" "$tmpdir"

utils/oscap-im

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,35 +111,50 @@ def add_eval_args(args, cmd):
111111

112112

113113
def pre_scan_fix(args):
114-
with tempfile.NamedTemporaryFile(delete=False) as remediation_script:
114+
with tempfile.NamedTemporaryFile() as remediation_script:
115115
gen_fix_cmd = [
116116
"oscap", "xccdf", "generate", "fix", "--fix-type", "bootc",
117117
"--output", remediation_script.name]
118118
add_common_args(args, gen_fix_cmd)
119119
gen_fix_cmd.append(args.data_stream)
120-
subprocess.run(gen_fix_cmd, check=True)
121-
subprocess.run(["bash", remediation_script.name], check=True)
120+
try:
121+
subprocess.run(gen_fix_cmd, check=True, capture_output=True)
122+
except subprocess.CalledProcessError as e:
123+
raise RuntimeError(
124+
f"OpenSCAP generate fix failed with return code "
125+
f"{e.returncode}.\nOutput: {e.stderr.decode()}")
126+
try:
127+
subprocess.run(["bash", remediation_script.name], check=True)
128+
except subprocess.CalledProcessError as e:
129+
raise RuntimeError(
130+
f"Remediation script failed with return code "
131+
f"{e.returncode}.")
122132

123133

124134
def scan_and_remediate(args):
125135
oscap_cmd = ["oscap", "xccdf", "eval", "--progress", "--remediate"]
126136
add_common_args(args, oscap_cmd)
127137
add_eval_args(args, oscap_cmd)
128138
oscap_cmd.append(args.data_stream)
129-
env = {**os.environ, "OSCAP_PREFERRED_ENGINE": "SCE", "OSCAP_BOOTC_BUILD": "YES"}
139+
env = {**os.environ, "OSCAP_PREFERRED_ENGINE": "SCE"}
130140
try:
131141
subprocess.run(oscap_cmd, env=env, check=True)
132142
except subprocess.CalledProcessError as e:
133143
if e.returncode not in [0, 2]:
134-
print(e, file=sys.stderr)
144+
raise RuntimeError(
145+
f"OpenSCAP scan failed with return code {e.returncode}.\n")
135146

136147

137148
def main():
138149
args = parse_args()
139150
verify_bootc_build_env()
140151
install_sce_dependencies()
141-
pre_scan_fix(args)
142-
scan_and_remediate(args)
152+
try:
153+
pre_scan_fix(args)
154+
scan_and_remediate(args)
155+
except RuntimeError as e:
156+
print(e, file=sys.stderr)
157+
sys.exit(1)
143158

144159

145160
if __name__ == "__main__":

utils/oscap-xccdf.c

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,49 @@ int xccdf_set_profile_or_report_bad_id(struct xccdf_session *session, const char
643643
return return_code;
644644
}
645645

646+
647+
static bool _system_is_in_bootc_mode(void)
648+
{
649+
#ifdef OS_WINDOWS
650+
return false;
651+
#else
652+
#define BOOTC_PATH "/usr/bin/bootc"
653+
#define CHUNK_SIZE 1024
654+
struct stat statbuf;
655+
if (stat(BOOTC_PATH, &statbuf) == -1) {
656+
return false;
657+
}
658+
FILE *output = popen(BOOTC_PATH " status --format json 2>/dev/null", "r");
659+
if (output == NULL) {
660+
return false;
661+
}
662+
size_t buf_size = CHUNK_SIZE;
663+
char *buf = calloc(buf_size, sizeof(char));
664+
if (buf == NULL) {
665+
pclose(output);
666+
return false;
667+
}
668+
int c;
669+
size_t i = 0;
670+
while ((c = fgetc(output)) != EOF) {
671+
if (i >= buf_size) {
672+
buf_size += CHUNK_SIZE;
673+
char *new_buf = realloc(buf, buf_size);
674+
if (new_buf == NULL) {
675+
pclose(output);
676+
return false;
677+
}
678+
buf = new_buf;
679+
}
680+
buf[i++] = c;
681+
}
682+
pclose(output);
683+
bool result = (*buf != '\0' && strstr(buf, "\"booted\":null") == NULL);
684+
free(buf);
685+
return result;
686+
#endif
687+
}
688+
646689
/**
647690
* XCCDF Processing fucntion
648691
* @param action OSCAP Action structure
@@ -653,6 +696,16 @@ int app_evaluate_xccdf(const struct oscap_action *action)
653696
struct xccdf_session *session = NULL;
654697

655698
int result = OSCAP_ERROR;
699+
700+
if (action->remediate && _system_is_in_bootc_mode()) {
701+
fprintf(stderr,
702+
"Detected running Image Mode operating system. OpenSCAP can't "
703+
"perform remediation of this system because majority of the "
704+
"system is read-only. Please apply remediation during bootable "
705+
"container image build using 'oscap-im' instead.\n");
706+
return result;
707+
}
708+
656709
#if defined(HAVE_SYSLOG_H)
657710
int priority = LOG_NOTICE;
658711

@@ -856,6 +909,14 @@ int app_xccdf_remediate(const struct oscap_action *action)
856909
{
857910
struct xccdf_session *session = NULL;
858911
int result = OSCAP_ERROR;
912+
if (_system_is_in_bootc_mode()) {
913+
fprintf(stderr,
914+
"Detected running Image Mode operating system. OpenSCAP can't "
915+
"perform remediation of this system because majority of the "
916+
"system is read-only. Please apply remediation during bootable "
917+
"container image build using 'oscap-im' instead.\n");
918+
return result;
919+
}
859920
session = xccdf_session_new(action->f_xccdf);
860921
if (session == NULL)
861922
goto cleanup;

utils/oscap.8

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ Allow download of remote components referenced from data stream.
6666
\fB\-\-local-files DIRECTORY\fR
6767
.RS
6868
Instead of downloading remote data stream components from the network, use data stream components stored locally as files in the given directory. In place of the remote data stream component OpenSCAP will attempt to use a file whose file name is equal to @name attribute of the uri element within the catalog element within the component-ref element in the data stream if such file exists.
69+
This option works only with SCAP 1.3 source data streams. It can't be used with SCAP 1.2 source data streams.
6970
.RE
7071
.TP
7172
\fB\-\-profile PROFILE\fR
@@ -216,6 +217,7 @@ Allow download of remote OVAL content referenced from XCCDF by check-content-ref
216217
\fB\-\-local-files DIRECTORY\fR
217218
.RS
218219
Instead of downloading remote data stream components from the network, use data stream components stored locally as files in the given directory. In place of the remote data stream component OpenSCAP will attempt to use a file whose file name is equal to @name attribute of the uri element within the catalog element within the component-ref element in the data stream if such file exists.
220+
This option works only with SCAP 1.3 source data streams. It can't be used with SCAP 1.2 source data streams.
219221
.RE
220222
.TP
221223
\fB\-\-remediate\fR
@@ -251,6 +253,7 @@ Allow download of remote OVAL content referenced from XCCDF by check-content-ref
251253
\fB\-\-local-files DIRECTORY\fR
252254
.RS
253255
Instead of downloading remote data stream components from the network, use data stream components stored locally as files in the given directory. In place of the remote data stream component OpenSCAP will attempt to use a file whose file name is equal to @name attribute of the uri element within the catalog element within the component-ref element in the data stream if such file exists.
256+
This option works only with SCAP 1.3 source data streams. It can't be used with SCAP 1.2 source data streams.
254257
.RE
255258
.TP
256259
\fB\-\-cpe CPE_FILE\fR
@@ -338,6 +341,7 @@ Allow download of remote OVAL content referenced from XCCDF by check-content-ref
338341
\fB\-\-local-files DIRECTORY\fR
339342
.RS
340343
Instead of downloading remote data stream components from the network, use data stream components stored locally as files in the given directory. In place of the remote data stream component OpenSCAP will attempt to use a file whose file name is equal to @name attribute of the uri element within the catalog element within the component-ref element in the data stream if such file exists.
344+
This option works only with SCAP 1.3 source data streams. It can't be used with SCAP 1.2 source data streams.
341345
.RE
342346
.TP
343347
\fB\-\-skip-validation\fR
@@ -505,6 +509,7 @@ Allow download of remote components referenced from data stream.
505509
.TP
506510
\fB\-\-local-files DIRECTORY\fR
507511
Instead of downloading remote data stream components from the network, use data stream components stored locally as files in the given directory. In place of the remote data stream component OpenSCAP will attempt to use a file whose file name is equal to @name attribute of the uri element within the catalog element within the component-ref element in the data stream if such file exists.
512+
This option works only with SCAP 1.3 source data streams. It can't be used with SCAP 1.2 source data streams.
508513
.RE
509514

510515
.TP

0 commit comments

Comments
 (0)