@@ -586,6 +586,33 @@ int xccdf_set_profile_or_report_bad_id(struct xccdf_session *session, const char
586586 return return_code ;
587587}
588588
589+
590+ static bool _system_is_in_bootc_mode (void )
591+ {
592+ #ifdef OS_WINDOWS
593+ return false;
594+ #else
595+ #define BOOTC_PATH "/usr/bin/bootc"
596+ struct stat statbuf ;
597+ if (stat (BOOTC_PATH , & statbuf ) == -1 ) {
598+ return false;
599+ }
600+ FILE * output = popen (BOOTC_PATH " status --format json 2>/dev/null" , "r" );
601+ if (output == NULL ) {
602+ return false;
603+ }
604+ char buf [1024 ] = {0 };
605+ int c ;
606+ size_t i = 0 ;
607+ while (i < sizeof (buf ) && (c = fgetc (output )) != EOF ) {
608+ buf [i ] = c ;
609+ i ++ ;
610+ }
611+ pclose (output );
612+ return * buf != '\0' && strstr (buf , "\"booted\":null" ) == NULL ;
613+ #endif
614+ }
615+
589616/**
590617 * XCCDF Processing fucntion
591618 * @param action OSCAP Action structure
@@ -596,6 +623,16 @@ int app_evaluate_xccdf(const struct oscap_action *action)
596623 struct xccdf_session * session = NULL ;
597624
598625 int result = OSCAP_ERROR ;
626+
627+ if (action -> remediate && _system_is_in_bootc_mode ()) {
628+ fprintf (stderr ,
629+ "Detected running Image Mode operating system. OpenSCAP can't "
630+ "perform remediation of this system because majority of the "
631+ "system is read-only. Please apply remediation during bootable "
632+ "container image build using 'oscap-im' instead." );
633+ return result ;
634+ }
635+
599636#if defined(HAVE_SYSLOG_H )
600637 int priority = LOG_NOTICE ;
601638
@@ -797,6 +834,14 @@ int app_xccdf_remediate(const struct oscap_action *action)
797834{
798835 struct xccdf_session * session = NULL ;
799836 int result = OSCAP_ERROR ;
837+ if (_system_is_in_bootc_mode ()) {
838+ fprintf (stderr ,
839+ "Detected running Image Mode operating system. OpenSCAP can't "
840+ "perform remediation of this system because majority of the "
841+ "system is read-only. Please apply remediation during bootable "
842+ "container image build using 'oscap-im' instead." );
843+ return result ;
844+ }
800845 session = xccdf_session_new (action -> f_xccdf );
801846 if (session == NULL )
802847 goto cleanup ;
0 commit comments