Skip to content
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

Docker machine-id fails #21

Open
0xprofessooor opened this issue Jul 3, 2023 · 1 comment
Open

Docker machine-id fails #21

0xprofessooor opened this issue Jul 3, 2023 · 1 comment

Comments

@0xprofessooor
Copy link

Hi, I am running machineid in a code sandbox that uses a docker container. The package fails with error:

Traceback (most recent call last):
  File "/workspace/run.py", line 8, in <module>
  File "/usr/local/lib/python3.10/site-packages/machineid/__init__.py", line 103, in hashed_id
    return hmac.new(bytes(app_id.encode()), id().encode(), hashlib.sha256).hexdigest()
  File "/usr/local/lib/python3.10/site-packages/machineid/__init__.py", line 94, in id
    raise Exception('failed to obtain id on platform {}'.format(platform))
Exception: failed to obtain id on platform linux

Checking the package, I have the following id() method:

def id() -> str:
  """
  id returns the platform specific device GUID of the current host OS.
  """
  if platform == 'darwin':
    id = __exec__("ioreg -d2 -c IOPlatformExpertDevice | awk -F\\\" '/IOPlatformUUID/{print $(NF-1)}'")

  if platform == 'win32' or platform == 'cygwin' or platform == 'msys':
    id = __reg__('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography', 'MachineGuid')
    if not id:
      id = __exec__('wmic csproduct get uuid').split('\n')[2] \
                                              .strip()

  if platform.startswith('linux'):
    id = __read__('/var/lib/dbus/machine-id')
    if not id:
      id = __read__('/etc/machine-id')
    if not id:
      cgroup = __read__('/proc/self/cgroup')
      if cgroup:
        if 'docker' in cgroup:
          id = __exec__('head -1 /proc/self/cgroup | cut -d/ -f3')
    if not id:
      mountinfo = __read__('/proc/self/mountinfo')
      if mountinfo:
        if 'docker' in mountinfo:
          id = __exec__("grep 'systemd' /proc/self/mountinfo | cut -d/ -f3")

  if platform.startswith('openbsd') or platform.startswith('freebsd'):
    id = __read__('/etc/hostid')
    if not id:      id = __exec__('kenv -q smbios.system.uuid')

  if not id:
    raise Exception('failed to obtain id on platform {}'.format(platform))

  return id

In particular, I am running docker in linux, so I'm interested in the commands. As expected by the error, none of the linux specific paths has a valid machine id associated with it. We're wondering if this should be trying to read /etc/hostname if the other two checks fail?

@pirate
Copy link

pirate commented Oct 4, 2024

I'm also running into this, it seems machineid doesn't work during docker builds.

For now I just added this line so that machineid has something to work with to avoid the error:

RUN openssl rand -hex 16 > /etc/machine-id

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

No branches or pull requests

2 participants