Skip to content

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

Merged
picnixz merged 9 commits into
python:mainfrom
picnixz:fix/uuid/mac-address-libuuid-132710
May 26, 2025
Merged

gh-132710: only use stable _uuid.generate_time_safe() to deduce MAC address#132901
picnixz merged 9 commits into
python:mainfrom
picnixz:fix/uuid/mac-address-libuuid-132710

Conversation

@picnixz

@picnixz picnixz commented Apr 25, 2025

Copy link
Copy Markdown
Member

@picnixz

picnixz commented Apr 25, 2025

Copy link
Copy Markdown
Member Author

cc @zanieb

Comment thread Modules/_uuidmodule.c
@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
Comment thread configure.ac
@picnixz

picnixz commented Apr 25, 2025

Copy link
Copy Markdown
Member Author

@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

zanieb commented Apr 25, 2025

Copy link
Copy Markdown
Contributor

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

zanieb commented Apr 25, 2025

Copy link
Copy Markdown
Contributor

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

zanieb commented Apr 25, 2025

Copy link
Copy Markdown
Contributor

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

@picnixz

picnixz commented Apr 25, 2025

Copy link
Copy Markdown
Member Author

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

@zanieb

zanieb commented Apr 25, 2025

Copy link
Copy Markdown
Contributor

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

@picnixz

picnixz commented Apr 25, 2025

Copy link
Copy Markdown
Member Author

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

@zanieb

zanieb commented Apr 25, 2025

Copy link
Copy Markdown
Contributor

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

zanieb commented Apr 25, 2025

Copy link
Copy Markdown
Contributor

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

@picnixz

picnixz commented Apr 25, 2025

Copy link
Copy Markdown
Member Author

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

@zanieb

zanieb commented Apr 25, 2025

Copy link
Copy Markdown
Contributor

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

picnixz commented Apr 25, 2025

Copy link
Copy Markdown
Member Author

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

zanieb commented Apr 26, 2025

Copy link
Copy Markdown
Contributor

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

picnixz commented Apr 26, 2025

Copy link
Copy Markdown
Member Author

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
Copy Markdown

🤖 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 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
Copy Markdown

🤖 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

picnixz commented May 26, 2025

Copy link
Copy Markdown
Member Author

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

picnixz commented May 26, 2025

Copy link
Copy Markdown
Member Author

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
Copy Markdown

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

@miss-islington-app

Copy link
Copy Markdown

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

picnixz commented May 26, 2025

Copy link
Copy Markdown
Member Author

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

@bedevere-app

bedevere-app Bot commented May 26, 2025

Copy link
Copy Markdown

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>
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
Pranjal095 pushed a commit to Pranjal095/cpython that referenced this pull request Jul 12, 2025
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
taegyunkim pushed a commit to taegyunkim/cpython that referenced this pull request Aug 4, 2025
picnixz added a commit that referenced this pull request Aug 5, 2025
…uce MAC address (GH-132901) (#134704)

This commit includes the original commit and the NEWS entry that was added separately.

(cherry picked from commit 3bffada)
(cherry picked from commit 9eb84d8)
gostak-dd pushed a commit to gostak-dd/cpython that referenced this pull request Jun 2, 2026
gostak-dd pushed a commit to gostak-dd/cpython that referenced this pull request Jun 2, 2026
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