Skip to content

Commit 376ce92

Browse files
committed
OPENSCAP-5235: Block remediation on deployed bootc system
OpenSCAP remediation is supposed to be used only at bootc container image build. Deployed bootc system is immutable, it can't be remediated with OpenSCAP and trying to do so would result in errors and bad user experience. We will update OpenSCAP to print error message for users in case they try to run remediation on an already deployed bootc system, informing them that it is not possible and that the openscap remediation must be performed during container build.
1 parent 4fda084 commit 376ce92

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/XCCDF/xccdf_session.c

+29
Original file line numberDiff line numberDiff line change
@@ -1906,6 +1906,27 @@ struct xccdf_rule_result_iterator *xccdf_session_get_rule_results(const struct x
19061906
return xccdf_result_get_rule_results(session->xccdf.result);
19071907
}
19081908

1909+
static int system_is_in_bootc_mode(void)
1910+
{
1911+
#ifdef OS_WINDOWS
1912+
return 0;
1913+
#else
1914+
FILE *output = popen("bootc status --format json 2>/dev/null | jq \".status.booted\"", "r");
1915+
if (output == NULL) {
1916+
return 0;
1917+
}
1918+
char buf[1024] = {0};
1919+
int c;
1920+
size_t i = 0;
1921+
while (i < sizeof(buf) && (c = fgetc(output)) != EOF) {
1922+
buf[i] = c;
1923+
i++;
1924+
}
1925+
pclose(output);
1926+
return strcmp(buf, "null\n") != 0;
1927+
#endif
1928+
}
1929+
19091930
int xccdf_session_remediate(struct xccdf_session *session)
19101931
{
19111932
int res = 0;
@@ -1917,6 +1938,14 @@ int xccdf_session_remediate(struct xccdf_session *session)
19171938
oscap_seterr(OSCAP_EFAMILY_OSCAP, "Can't perform remediation in offline mode: not implemented");
19181939
return 1;
19191940
}
1941+
if (system_is_in_bootc_mode()) {
1942+
oscap_seterr(OSCAP_EFAMILY_OSCAP,
1943+
"Detected running Image Mode operating system. OpenSCAP can't "
1944+
"perform remediation of this system because majority of the "
1945+
"system is read-only. Please apply remediation during bootable "
1946+
"container image build using 'oscap-im' instead.");
1947+
return 1;
1948+
}
19201949
xccdf_policy_model_unregister_engines(session->xccdf.policy_model, oval_sysname);
19211950
if ((res = xccdf_session_load_oval(session)) != 0)
19221951
return res;

0 commit comments

Comments
 (0)