Skip to content

feat: Rewrite MAC randomisation toggle in python (Task #1560)#1870

Draft
Meijuta wants to merge 61 commits intosecureblue:livefrom
Meijuta:live
Draft

feat: Rewrite MAC randomisation toggle in python (Task #1560)#1870
Meijuta wants to merge 61 commits intosecureblue:livefrom
Meijuta:live

Conversation

@Meijuta
Copy link
Copy Markdown

@Meijuta Meijuta commented Jan 28, 2026

I've rewritten the MAC randomisation toggle in python with an emphasis on minimising permission usage.

@Meijuta Meijuta changed the title feat: Rewrite MAC randomisation toggle in python #1560 feat: Rewrite MAC randomisation toggle in python (Task #1560) Jan 28, 2026
Copy link
Copy Markdown
Collaborator

@HastD HastD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for writing this up. I do have a number of suggestions to bring this more in line with the other rewritten ujust scripts.

For most of the ujust toggle scripts, we've been switching over to ujust set-* [on|off|status] in place of ujust toggle-*; I think it would be good to follow that pattern here. See ujust set-unconfined-userns for a simple example of this. This also makes it easier to invoke the script from another script or from other Python code.

In this case, I think it would make sense to have "random" or "stable" as arguments that can be passed directly in place of just "on". That way, the script can be run non-interactively, e.g. as ujust set-mac-randomization stable or ujust set-mac-randomization off. A "status" argument is also useful and should print something indicating the current status, while "help" or "--help" should print usage info.

If the script is called without arguments, it should prompt the user which mode ("stable", "random", or "off") to select. The inquirer Python module is installed on secureblue and provides a nice interface for "select from these multiple options" prompts like this.

Additionally, for other similar ujust scripts, we're using the sandbox module (defined in files/system/usr/libexec/secureblue) to separate the unprivileged and privileged parts of ujust scripts, and run the privileged part with minimal permissions using systemd sandboxing. (The privileged script goes in the inner subdirectory.)

In this case, I think only writing or deleting the conf file needs to be handled by the privileged script, and it should just need write access to /etc/NetworkManager/conf.d; toggling the network connection can be done unprivileged, and all interactive prompts should be unprivileged too.

Comment thread files/justfiles/common/toggles.just Outdated
Comment thread files/system/usr/libexec/secureblue/toggle_mac_address_randomization.py Outdated
Comment thread files/system/usr/libexec/secureblue/set_mac_randomization.py Outdated
Comment thread files/system/usr/libexec/secureblue/set_mac_randomization.py Outdated
Comment thread files/system/usr/libexec/secureblue/set_mac_randomization.py Outdated
Comment thread files/system/usr/libexec/secureblue/set_mac_randomization.py Outdated
@HastD HastD linked an issue Jan 28, 2026 that may be closed by this pull request
3 tasks
@spaceoden
Copy link
Copy Markdown
Collaborator

Other related improvements that are in progress:

None of these warrant blocking this PR, as the python rewrite alone is an improvement. Just mentioning for any who aren't aware.

@Meijuta Meijuta marked this pull request as draft January 29, 2026 06:16
@Meijuta Meijuta marked this pull request as ready for review January 29, 2026 08:22
@Meijuta Meijuta marked this pull request as draft January 29, 2026 18:18
Comment thread files/system/usr/libexec/secureblue/set_mac_randomization.py Outdated
@Meijuta Meijuta marked this pull request as ready for review January 30, 2026 00:24
@Meijuta Meijuta requested review from HastD and spaceoden January 30, 2026 00:25
@Meijuta Meijuta marked this pull request as draft January 31, 2026 01:22
@Meijuta Meijuta marked this pull request as ready for review January 31, 2026 02:30
@Meijuta
Copy link
Copy Markdown
Author

Meijuta commented Jan 31, 2026

Everything should be done now!
Options for status, disable, per-network, and per-connection.
Inquirer module if no args passed.
Sandboxing implemented where appropriate.

Comment thread files/system/usr/libexec/secureblue/inner/disable_mac_randomization.py Outdated
@Meijuta Meijuta requested a review from spaceoden February 2, 2026 11:27
Comment thread files/system/usr/libexec/secureblue/set_mac_randomization.py Outdated
Comment thread files/system/usr/libexec/secureblue/set_mac_randomization.py Outdated
Comment thread files/system/usr/libexec/secureblue/set_mac_randomization.py Outdated
Comment thread files/system/usr/libexec/secureblue/utils/__init__.py Outdated
Comment thread files/system/usr/libexec/secureblue/set_mac_randomization.py Outdated
Comment thread files/system/usr/libexec/secureblue/set_mac_randomization.py Outdated
Comment thread files/system/usr/libexec/secureblue/set_mac_randomization.py Outdated
Comment thread files/system/usr/libexec/secureblue/set_mac_randomization.py Outdated
Comment thread files/system/usr/libexec/secureblue/inner/disable_mac_randomization.py Outdated
Comment thread files/system/usr/libexec/secureblue/inner/set_mac_randomization_random.py Outdated
@Meijuta Meijuta marked this pull request as draft February 3, 2026 10:19
@Meijuta Meijuta marked this pull request as ready for review February 4, 2026 02:28
@Meijuta Meijuta requested a review from HastD February 4, 2026 02:31
Comment thread files/system/usr/libexec/secureblue/set_mac_randomization.py Outdated
Comment thread files/system/usr/libexec/secureblue/set_mac_randomization.py Outdated
Comment thread files/system/usr/libexec/secureblue/utils/__init__.py Outdated
Comment thread files/system/usr/libexec/secureblue/utils/__init__.py Outdated
Comment thread files/system/usr/libexec/secureblue/set_mac_randomization.py Outdated
Comment thread files/system/usr/libexec/secureblue/set_mac_randomization.py Outdated
Comment thread files/system/usr/libexec/secureblue/set_mac_randomization.py Outdated
@Meijuta Meijuta requested a review from HastD February 4, 2026 05:54
Comment thread files/system/usr/libexec/secureblue/utils/__init__.py Outdated
Copy link
Copy Markdown
Collaborator

@WavyEbuilder WavyEbuilder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few nits. Looking good!

Comment thread files/system/usr/libexec/secureblue/inner/set_mac_randomization_stable.py Outdated
Comment thread files/system/usr/libexec/secureblue/inner/set_mac_randomization_random.py Outdated
Comment thread files/justfiles/common/wrappers.just
Comment thread files/system/usr/libexec/secureblue/set_mac_randomization.py Outdated
Comment thread files/system/usr/libexec/secureblue/set_mac_randomization.py
HastD
HastD previously approved these changes Feb 23, 2026
WavyEbuilder
WavyEbuilder previously approved these changes Feb 24, 2026
@Meijuta Meijuta dismissed stale reviews from WavyEbuilder and HastD via 262716d February 25, 2026 12:19


@dataclass(frozen=True)
class SystemdService:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this copied from dns.py? if so it should be removed from dns.py and pointed to this shared util

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. i prefer not to mess with code i havent written more than absolutely necessary because i dont know the exact details of its use case, where it is used, or every one of its quirks. which is why i left it

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please do so, we shouldn't be copy pasting code.

Comment thread files/system/usr/libexec/secureblue/set_mac_randomization.py Outdated
Comment thread files/system/usr/libexec/secureblue/set_mac_randomization.py Outdated

def run_disable_randomization() -> int:
"""Runs sandboxed disable_randomization() function."""
if Path(RAND_MAC_FILE).exists(): # may TOCTOU
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the TOCTOU comment unique to this toggle?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think so, this one uniquely deletes the file.
I dont remember what i was thinking when i wrote that, it might be like a 'if something is going wrong in these parts, its probably this' kind of comment.

Comment thread files/system/usr/libexec/secureblue/set_mac_randomization.py Outdated
restart_success = run_restart_networkmanager()
if restart_success != 0: # 0 == success, not 0 == failure
print_wrapped(
"Failed to restart NetworkManager. "
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a lot of copy/pasted boilerplate between these functions that could be refactored

why not have a single set_randomization_state() function that takes an enum with values DISABLED, STABLE, RANDOM?

Copy link
Copy Markdown
Author

@Meijuta Meijuta Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldnt i just reuse the Mode enums rather than seperately defining DISABLED, STABLE, RANDOM?

@Meijuta Meijuta marked this pull request as draft February 26, 2026 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] ujust toggle-mac-randomization should print a warning about VM breakage toggle-mac-randomization

5 participants