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

OPENSCAP-5235: Block remediation on deployed bootc system #2203

Merged
merged 6 commits into from
Mar 13, 2025
Merged
Changes from 1 commit
Commits
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
29 changes: 29 additions & 0 deletions src/XCCDF/xccdf_session.c
Original file line number Diff line number Diff line change
Expand Up @@ -1906,6 +1906,27 @@ struct xccdf_rule_result_iterator *xccdf_session_get_rule_results(const struct x
return xccdf_result_get_rule_results(session->xccdf.result);
}

static int system_is_in_bootc_mode(void)
{
#ifdef OS_WINDOWS
return 0;
#else
FILE *output = popen("bootc status --format json 2>/dev/null | jq \".status.booted\" 2>/dev/null", "r");
if (output == NULL) {
return 0;
}
char buf[1024] = {0};
int c;
size_t i = 0;
while (i < sizeof(buf) && (c = fgetc(output)) != EOF) {
buf[i] = c;
i++;
}
pclose(output);
return *buf != '\0' && strcmp(buf, "null\n") != 0;
#endif
}

int xccdf_session_remediate(struct xccdf_session *session)
{
int res = 0;
Expand All @@ -1917,6 +1938,14 @@ int xccdf_session_remediate(struct xccdf_session *session)
oscap_seterr(OSCAP_EFAMILY_OSCAP, "Can't perform remediation in offline mode: not implemented");
return 1;
}
if (system_is_in_bootc_mode()) {
oscap_seterr(OSCAP_EFAMILY_OSCAP,
"Detected running Image Mode operating system. OpenSCAP can't "
"perform remediation of this system because majority of the "
"system is read-only. Please apply remediation during bootable "
"container image build using 'oscap-im' instead.");
return 1;
}
xccdf_policy_model_unregister_engines(session->xccdf.policy_model, oval_sysname);
if ((res = xccdf_session_load_oval(session)) != 0)
return res;
Expand Down
Loading