Closed digitalsleuth closed 1 year ago
I'm going to have to take a deeper look into the dbus stuff, probably can merge this soonish into the existing branch.
Not super thrilled with having to work around dbus, perhaps there's a better approach with Jammy. I'll do some research.
Typically, I would use the following:
- onlyif:
- fun: cmd.run
cmd: export DBUS_SESSION_BUS_ADDRESS=$(dbus-launch | grep DBUS_SESSION_BUS_ADDRESS | cut -d= -f2-)
shell: /bin/bash
python_shell: True
runas: {{ user }}
Then add the requirement for dbus-x11 to the state, but for some reason this is always returning as False because Python cannot seem to find the command export
in this context.
The error can be observed by changing python_shell to False.
I'm still looking into that error, but these states are the best workaround I can find for now. I'll let you know when I figure out the cause.
I've come up with a more graceful solution, but my VMs have crashed and it's late. I need to run a full test to make sure it works, but I can pinpoint the proper DBUS address without additional commands.
I'll share the rest in the morning.
Tested multiple times on both instances, no failures or issues with the desktop theme being applied across the board. The fix will essentially identify the user info based on the chosen / defaulted user (using the pillar data provided), then grab the UID for that user, and use it as part of the in-line DBUS session. Thus the new environment variable will be set by:
{% set userid = (salt['user.info'](user))['uid'] %}
...
- env:
- DBUS_SESSION_BUS_ADDRESS: 'unix:path=/run/user/{{ userid }}/bus'
This works on both Focal and Jammy.
The issue with the onlyif
function not working is that the export
command is not a separate binary, but an alias built into the bash shell. Since the export
command cannot be called using the given environment (nor can declare
), the function fails because it cannot find the binary / command within the given shell.
Nice @digitalsleuth I'll review this tonight and get it merged in, I'll be fixing the bulk extractor package soon.
One of the main reasons for moving the DBUS_SESSION_BUS_ADDRESS variable, and suggesting an "if" clause, is that the Jinja gets rendered prior to any requirements of the states, and gets evaluated in the current environment before state execution. At runtime, Jammy does not come with dbus-x11, and by extension, dbus-launch. This renders the
set dbus_address
jinja todbus-launch: command not found
, even though it is to be installed.To fix this, a few changes were made which still set the value on both versions, but it is only used on Focal. If the states are run on Jammy, then a temporary script is created to execute the commands which require an appropriate DBUS environment variable. The states create an autostart shortcut, executes it on reboot, then moves the autostart shortcut out of the autostart folder. This will enable the user to make modifications as they wish, without the original customization being forced every time.