Skip to content

gh-132710: only use stable _uuid.generate_time_safe() to deduce MAC address #132901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 26, 2025

Conversation

picnixz
Copy link
Member

@picnixz picnixz commented Apr 25, 2025

@picnixz
Copy link
Member Author

picnixz commented Apr 25, 2025

cc @zanieb

@picnixz picnixz force-pushed the fix/uuid/mac-address-libuuid-132710 branch 2 times, most recently from 2d398c9 to 99bdd52 Compare April 25, 2025 08:02
@picnixz picnixz force-pushed the fix/uuid/mac-address-libuuid-132710 branch from 99bdd52 to ee71d62 Compare April 25, 2025 08:03
@picnixz
Copy link
Member Author

picnixz commented Apr 25, 2025

@zanieb Does it actually solve your issue? because my system also appears to be unable to get the MAC address... but I was offline (I work offline during the week in general) and I didn't check when I'm online.

@zanieb
Copy link
Contributor

zanieb commented Apr 25, 2025

It's kind of hard to test because I haven't added support for the latest 3.14 in python-build-standalone and the patch doesn't apply cleanly to 3.13.

@zanieb
Copy link
Contributor

zanieb commented Apr 25, 2025

Okay, the patch does apply cleanly to the previous 3.14 alpha so I can test this. On macOS, it does resolve the problem. I did not test Linux.

@zanieb
Copy link
Contributor

zanieb commented Apr 25, 2025

I tested a Linux build at astral-sh/python-build-standalone#595 (comment) and it didn't seem to work.

@picnixz
Copy link
Member Author

picnixz commented Apr 25, 2025

Hum. It's very strange. Did I mess the configure script? what's the value of HAVE_UUID_GENERATE_TIME_SAFE_STABLE_MAC?

@zanieb
Copy link
Contributor

zanieb commented Apr 25, 2025

Looking at the logs... "HAVE_UUID_GENERATE_TIME_SAFE_STABLE_MAC": "0",

@picnixz
Copy link
Member Author

picnixz commented Apr 25, 2025

... so it's not _unix_node() that is being called?

@zanieb
Copy link
Contributor

zanieb commented Apr 25, 2025

The builds are attached there if you want to hop into a debugger.

Briefly... yeah it looks like it's called and we try each getter until we reach the random one:

(Pdb) getter
<function _unix_getnode at 0xffffb77b74d0>
(Pdb) s
--Call--
> /python/install/lib/python3.14/uuid.py(634)_unix_getnode()
-> def _unix_getnode():
(Pdb) n
> /python/install/lib/python3.14/uuid.py(636)_unix_getnode()
-> if _generate_time_safe and _has_stable_extractable_node:
(Pdb) n
--Return--
> /python/install/lib/python3.14/uuid.py(636)_unix_getnode()->None
-> if _generate_time_safe and _has_stable_extractable_node:
(Pdb) n
> /python/install/lib/python3.14/uuid.py(706)getnode()
-> if (_node is not None) and (0 <= _node < (1 << 48)):
(Pdb) l
701  	   for getter in _GETTERS + [_random_getnode]:
702  	       try:
703  	           _node = getter()
704  	       except:
705  	           continue
706  ->	       if (_node is not None) and (0 <= _node < (1 << 48)):
707  	           return _node
708  	   assert False, '_random_getnode() returned invalid value: {}'.format(_node)
709  	
710  	
711  	_last_timestamp = None
(Pdb) n
> /python/install/lib/python3.14/uuid.py(701)getnode()
-> for getter in _GETTERS + [_random_getnode]:
(Pdb) n
> /python/install/lib/python3.14/uuid.py(702)getnode()
-> try:
(Pdb) getter
<function _ip_getnode at 0xffffb77b71d0>
(Pdb) n
> /python/install/lib/python3.14/uuid.py(703)getnode()
-> _node = getter()
(Pdb) n
> /python/install/lib/python3.14/uuid.py(706)getnode()
-> if (_node is not None) and (0 <= _node < (1 << 48)):
(Pdb) _node
(Pdb) n
> /python/install/lib/python3.14/uuid.py(701)getnode()
-> for getter in _GETTERS + [_random_getnode]:
(Pdb) n
> /python/install/lib/python3.14/uuid.py(702)getnode()
-> try:
(Pdb) getter
<function _ifconfig_getnode at 0xffffb77b7110>
(Pdb) n
> /python/install/lib/python3.14/uuid.py(703)getnode()
-> _node = getter()
(Pdb) n
> /python/install/lib/python3.14/uuid.py(706)getnode()
-> if (_node is not None) and (0 <= _node < (1 << 48)):
(Pdb) _node
(Pdb) n
> /python/install/lib/python3.14/uuid.py(701)getnode()
-> for getter in _GETTERS + [_random_getnode]:
(Pdb) n
> /python/install/lib/python3.14/uuid.py(702)getnode()
-> try:
(Pdb) getter
<function _random_getnode at 0xffffb77b7650>
(Pdb) n
> /python/install/lib/python3.14/uuid.py(703)getnode()
-> _node = getter()
(Pdb) n
> /python/install/lib/python3.14/uuid.py(706)getnode()
-> if (_node is not None) and (0 <= _node < (1 << 48)):
(Pdb) _node
23292345252342

@zanieb
Copy link
Contributor

zanieb commented Apr 25, 2025

So, the patch worked but it turns out generate_time_safe is necessary for MAC address retrieval on (at least) ubuntu:latest?

@picnixz
Copy link
Member Author

picnixz commented Apr 25, 2025

Maybe we should add all possible getnode fallbacks based on ifconfig, ip, arp, netstat, lanscan?

@zanieb
Copy link
Contributor

zanieb commented Apr 25, 2025

We did try _ip_getnode and _ifconfig_getnode as expected there. I didn't look into why those might fail. It does feel like a bit of a separate concern than this patch.

@picnixz
Copy link
Member Author

picnixz commented Apr 25, 2025

I suggest adding a print in the except: continue as well just in case and also print the output of the invoked command to see whether we need to upgrade how the output is being parsed.

@zanieb
Copy link
Contributor

zanieb commented Apr 26, 2025

Those commands are just not installed by default in the ubuntu image. If you apt-get install net-tools, the getnode result is static.

@picnixz
Copy link
Member Author

picnixz commented Apr 26, 2025

Ha! so that's why. Let's also fix this by adding them as a dependency then

@picnixz picnixz added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Apr 26, 2025
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @picnixz for commit 16200ae 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F132901%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@picnixz
Copy link
Member Author

picnixz commented May 25, 2025

@hugovk friendly ping

This is a bug fix, so it should technically be backported up to 3.13. But I'm not confident in this bugfix because there is still a change of behavior, and maybe it could have more impact than what I think.

The bug is however really hard to spot as it's only between different interpreters that it would appear. Within the same process, it wouldn't appear. Do you think it's better to merge this one for 3.14 and 3.15 but hold a few beta releases until merging it into 3.13?

@hugovk
Copy link
Member

hugovk commented May 25, 2025

Do you think it's better to merge this one for 3.14 and 3.15 but hold a few beta releases until merging it into 3.13?

Can do. The next 3.13 is scheduled for 2025-06-03. After that is 2025-08-05, by which time we'll have had all three remaining 3.14 betas and one RC.

@picnixz picnixz self-assigned this May 25, 2025
@picnixz picnixz removed the needs backport to 3.13 bugs and security fixes label May 25, 2025
@picnixz picnixz added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label May 25, 2025
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @picnixz for commit fd84b3c 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F132901%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label May 25, 2025
@picnixz
Copy link
Member Author

picnixz commented May 26, 2025

Note: the buildbot failures are unrelated so I'll ignore them.

@picnixz picnixz merged commit 3bffada into python:main May 26, 2025
113 of 119 checks passed
@picnixz picnixz deleted the fix/uuid/mac-address-libuuid-132710 branch May 26, 2025 08:56
@picnixz
Copy link
Member Author

picnixz commented May 26, 2025

Hum, is our backport bot sick? it didn't make an automatic backport, so I'll do it for 3.14

picnixz added a commit to picnixz/cpython that referenced this pull request May 26, 2025
…to deduce MAC address (pythonGH-132901)

(cherry picked from commit 3bffada)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@picnixz picnixz added needs backport to 3.13 bugs and security fixes and removed needs backport to 3.14 bugs and security fixes labels May 26, 2025
@miss-islington-app
Copy link

Thanks @picnixz for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry, @picnixz, I could not cleanly backport this to 3.13 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 3bffada46728e51f84c41ecbb0d3722595693e63 3.13

@picnixz
Copy link
Member Author

picnixz commented May 26, 2025

huh... ok I'll make the manual bp, add a DO-NOT-MERGE and so that we don't forget it

@bedevere-app
Copy link

bedevere-app bot commented May 26, 2025

GH-134704 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label May 26, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 26, 2025
…-134705)

(cherry picked from commit 9eb84d8)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
picnixz added a commit that referenced this pull request May 26, 2025
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 26, 2025
…-134705)

(cherry picked from commit 9eb84d8)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants