ctc-oss / fapolicy-analyzer

Tools to assist with the configuration and management of fapolicyd.
https://ctc-oss.github.io/fapolicy-analyzer
GNU General Public License v3.0
12 stars 5 forks source link

On FC41/Rawhide, navigating to the `Trust` tool within the `fapolicy-analyzer` results in a TypeError exception #1019

Closed tparchambault closed 1 month ago

tparchambault commented 1 month ago

Executing in double verbose mode (-vv aka DEBUG), the following log messaging and the final exception were captured after attempting to see the Trust page:

toma@fc-rawhide-ref:~$ fapolicy-analyzer -vv
Verbosity enabled
INFO:root:SessionManager::set_autosave_filename: /var/lib/fapolicy-analyzer/fapolicy-analyzer.tmp
fapolicy-analyzer v1.4.0rc1
DEBUG:fapolicy_analyzer.redux._internal.feature:system
DEBUG:root:_PostInitCaller.__call__((), {})
DEBUG:root:system_feature::finish::system = <class 'app.System'>
DEBUG:root:distroying widget from class SplashScreen
DEBUG:root:disposing of subscription for class SplashScreen
DEBUG:root:_PostInitCaller.__call__((), {})
INFO:root:FapdManager constructed, control:True
DEBUG:root:_PostInitCaller.__call__((), {'timer_duration': 5})
DEBUG:root:dispatch( REQUEST_APP_CONFIG )
DEBUG:root:dispatch( REQUEST_SYSTEM_TRUST )
DEBUG:fapolicy_pyo3.check:BatchConf: recs: 46890, tc:5, tl:20, bc:100, bl:469
DEBUG:root:dispatch( REQUEST_ANCILLARY_TRUST )
INFO:root:MainWindow::on_start()
INFO:root:SessionManager searching for previous session
DEBUG:root:Search Pattern: /var/lib/fapolicy-analyzer/fapolicy-analyzer.tmp_*.json
DEBUG:root:Glob search results: []
DEBUG:root:on_update_daemon_status(ServiceStatus.TRUE)
DEBUG:root:Starting the fapd monitoring thread
INFO:root:start_daemon_monitor(): ServiceStatus.TRUE
INFO:root:Spawning monitor thread...
DEBUG:root:_monitor_daemon() executing
DEBUG:root:Thread=<Thread(Thread-1 (_monitor_daemon), started daemon 140621352273600)>, Running=True
DEBUG:root:_PostInitCaller.__call__((), {})
DEBUG:root:dispatch( REQUEST_RULES )
DEBUG:fapolicy_pyo3.system:rules
DEBUG:root:dispatch( REQUEST_RULES_TEXT )
DEBUG:fapolicy_pyo3.system:rules_text
DEBUG:root:dispatch( MODIFY_RULES_TEXT )
DEBUG:root:_update_fapd_status(ServiceStatus.TRUE)
DEBUG:root:_PostInitCaller.__call__((), {})
DEBUG:root:dispatch( REQUEST_ANCILLARY_TRUST )
DEBUG:root:_PostInitCaller.__call__((), {})
DEBUG:root:dispatch( REQUEST_SYSTEM_TRUST )
DEBUG:fapolicy_pyo3.check:BatchConf: recs: 46890, tc:5, tl:20, bc:100, bl:469
DEBUG:root:distroying widget from class RulesAdminPage
DEBUG:root:disposing of subscription for class RulesAdminPage
DEBUG:root:disposing of subscription for class RulesAdminPage
DEBUG:root:disposing of subscription for class RulesAdminPage
Traceback (most recent call last):
  File "/usr/lib64/python3.13/site-packages/fapolicy_analyzer/ui/trust_file_list.py", line 169, in process_rows
    self._update_loading_status(f(_("Loading trust {pct}% complete...")))
                                ~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.13/site-packages/fapolicy_analyzer/util/format.py", line 23, in f
    eval(f'f"""{formatString}"""', frame.f_locals, frame.f_globals)
    ~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: globals must be a real dict; try eval(expr, {}, mapping)

Note: FC41/Rawhide is shipping Python 3.13.

tparchambault commented 1 month ago

FC40 w/Python 3.12.2 does not exhibit the TypeError exception.

tparchambault commented 1 month ago

Changed line /usr/lib64/python3.13/site-packages/fapolicy_analyzer/ui/trust_file_list.py:169 to self._update_loading_status(f"Loading trust {pct}% complete...") which addressed the issue. I don't know why this is OK in FC40/Py 3.12.2. Will do more extensive testing Monday.

tparchambault commented 1 month ago

There's a wrapper function, f() to perform formatting in format.py which works in Py 3.12.x but not in Py 3.13. We could use str.format() with locale.gettext() but will try and fix the existing code first. Py 3.13 added new typing features, and the version currently shipped in Rawhide is still in beta.

tparchambault commented 1 month ago

The eval() built-n function's API and documentation for 3.13 is in a state of flux currently wrt to argument count and position:

I'd like to go w/keyword parameter passing, but have concerns about 3.9 support. Also note that if we are passing positionally (which is how we currently call eval() in master to eval() we have our globals/locals arguments reversed. Obviously Py <= 3.12 does not care; It was probably the addition of a new positional arg in 3.13 that broke things.

Both reversing the order of the globals/locals namespace arguments and also using globals and locals keyword parameter passing addressed the TypeError exception observed on FC41/Rawhide. Tested on FC40 and no issues observed.

jw3 commented 1 month ago

Checking the python version and calling eval with appropriate args may allow you to support both.

I only tested this from the repl:

if (3, 13) > sys.version_info:
  use old eval
else:
  use new eval