@@ -179,10 +179,8 @@ def create_policy(
179179 # mounts
180180 if inspect_format == "CRI-O" :
181181 write_policy_for_crio_mounts (mounts , policy )
182- elif inspect_format == "containerd" :
182+ elif inspect_format in [ "containerd" , "LXD" ] :
183183 write_policy_for_containerd_mounts (mounts , policy )
184- elif inspect_format == "LXD" :
185- write_policy_for_lxd_mounts (mounts , policy )
186184 else :
187185 write_policy_for_podman_mounts (mounts , policy )
188186
@@ -465,111 +463,6 @@ def write_policy_for_containerd_mounts(mounts, policy):
465463 # "nodev"
466464 # ]
467465 # }
468- for item in sorted (mounts , key = lambda x : str (x ["source" ])):
469- if not item ["source" ].find ("/" ):
470- if item ["source" ] == LOG_CONTAINER and "ro" in item ["options" ]:
471- policy .write (" (blockinherit log_container)\n " )
472- add_template ("log_container" )
473- continue
474-
475- if item ["source" ] == LOG_CONTAINER and "ro" not in item ["options" ]:
476- policy .write (" (blockinherit log_rw_container)\n " )
477- add_template ("log_container" )
478- continue
479-
480- if item ["source" ] == HOME_CONTAINER and "ro" in item ["options" ]:
481- policy .write (" (blockinherit home_container)\n " )
482- add_template ("home_container" )
483- continue
484-
485- if item ["source" ] == HOME_CONTAINER and "ro" not in item ["options" ]:
486- policy .write (" (blockinherit home_rw_container)\n " )
487- add_template ("home_container" )
488- continue
489-
490- if item ["source" ] == TMP_CONTAINER and "ro" in item ["options" ]:
491- policy .write (" (blockinherit tmp_container)\n " )
492- add_template ("tmp_container" )
493- continue
494-
495- if item ["source" ] == TMP_CONTAINER and "ro" not in item ["options" ]:
496- policy .write (" (blockinherit tmp_rw_container)\n " )
497- add_template ("tmp_container" )
498- continue
499-
500- if item ["source" ] == CONFIG_CONTAINER and "ro" in item ["options" ]:
501- policy .write (" (blockinherit config_container)\n " )
502- add_template ("config_container" )
503- continue
504-
505- if item ["source" ] == CONFIG_CONTAINER and "ro" not in item ["options" ]:
506- policy .write (" (blockinherit config_rw_container)\n " )
507- add_template ("config_container" )
508- continue
509-
510- contexts = list_contexts (item ["source" ])
511- for context in contexts :
512- if "ro" not in item ["options" ]:
513- policy .write (
514- " (allow process "
515- + context
516- + " ( dir ( "
517- + perms .perm ["dir_rw" ]
518- + " ))) \n "
519- )
520- policy .write (
521- " (allow process "
522- + context
523- + " ( file ( "
524- + perms .perm ["file_rw" ]
525- + " ))) \n "
526- )
527- policy .write (
528- " (allow process "
529- + context
530- + " ( fifo_file ( "
531- + perms .perm ["fifo_rw" ]
532- + " ))) \n "
533- )
534- policy .write (
535- " (allow process "
536- + context
537- + " ( sock_file ( "
538- + perms .perm ["socket_rw" ]
539- + " ))) \n "
540- )
541- if "ro" in item ["options" ]:
542- policy .write (
543- " (allow process "
544- + context
545- + " ( dir ( "
546- + perms .perm ["dir_ro" ]
547- + " ))) \n "
548- )
549- policy .write (
550- " (allow process "
551- + context
552- + " ( file ( "
553- + perms .perm ["file_ro" ]
554- + " ))) \n "
555- )
556- policy .write (
557- " (allow process "
558- + context
559- + " ( fifo_file ( "
560- + perms .perm ["fifo_ro" ]
561- + " ))) \n "
562- )
563- policy .write (
564- " (allow process "
565- + context
566- + " ( sock_file ( "
567- + perms .perm ["socket_ro" ]
568- + " ))) \n "
569- )
570-
571-
572- def write_policy_for_lxd_mounts (mounts , policy ):
573466 for item in sorted (mounts , key = lambda x : str (x ["source" ])):
574467 if not item ["source" ].find ("/" ):
575468 if item ["source" ] == LOG_CONTAINER and "ro" in item .get ("options" , []):
@@ -607,7 +500,9 @@ def write_policy_for_lxd_mounts(mounts, policy):
607500 add_template ("config_container" )
608501 continue
609502
610- if item ["source" ] == CONFIG_CONTAINER and "ro" not in item .get ("options" , []):
503+ if item ["source" ] == CONFIG_CONTAINER and "ro" not in item .get (
504+ "options" , []
505+ ):
611506 policy .write (" (blockinherit config_rw_container)\n " )
612507 add_template ("config_container" )
613508 continue
0 commit comments