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

Incorrect hypervisors and virtual Facts with Unsupported Container Runtime Warning in Docker #2781

Open
molhamalnasr opened this issue Nov 27, 2024 · 3 comments
Labels
bug Something isn't working triaged Jira issue has been created for this

Comments

@molhamalnasr
Copy link

molhamalnasr commented Nov 27, 2024

Describe the Bug

When running Puppet Facter inside a Docker container, the hypervisors and virtual facts are incorrectly set. Additionally, a warning is displayed:
Warning: Facter: Container runtime, 'docker', is unsupported, setting to, 'container_other'.

Example Output:

# facter -p hypervisors
[2024-11-27 13:49:35.972235 ] WARN Facter::Resolvers::Containers - Container runtime, 'docker', is unsupported, setting to, 'container_other'

# facter -p virtual
[2024-11-27 13:49:42.488042 ] WARN Facter::Resolvers::Containers - Container runtime, 'docker', is unsupported, setting to, 'container_other'
container_other

Expected Behavior

In previous versions (e.g., Tag 4.7.0), the hypervisors and virtual facts returned the correct values:

# facter -p hypervisors
{
  docker => {
    id => "<STRING_ID>"
  }
}

# facter -p virtual
docker

Steps to Reproduce

  1. Run Puppet Agent/Facter inside a Docker container.
  2. Execute the command facter -p hypervisors or facter -p virtual.

Environment

  • Version: Puppet Agent 7.32.1
  • Platform: Ubuntu 24.04
  • Facter Version: 4.8.0

Additional Context

After debugging the repository, I identified the root cause in the following line within lib/facter/resolvers/containers.rb:

read_environ(fact_name) || read_cgroup(fact_name)

The call to read_environ(fact_name) always returns a value, which prevents read_cgroup(fact_name) from being executed. This causes the resolver to misidentify the container runtime and set incorrect values for the hypervisors and virtual facts.

@molhamalnasr molhamalnasr added the bug Something isn't working label Nov 27, 2024
@mhashizume mhashizume added the triaged Jira issue has been created for this label Dec 17, 2024
@mhashizume
Copy link
Contributor

Thank you for reporting this @molhamalnasr , we have added this issue to our backlog.

Copy link

Migrated issue to FACT-3488

@joshcooper
Copy link
Contributor

joshcooper commented Jan 7, 2025

@molhamalnasr I can't reproduce this ever working. In particular, read_environ returns nil, because there isn't a container environment variable defined for pid 1:

❯ docker run -it ubuntu:noble cat /proc/1/environ 
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binHOSTNAME=00ddb9b41876TERM=xtermHOME=/root

Also it doesn't appear any version of facter correctly detects those facts:

❯ docker --version
Docker version 27.3.1, build ce12230

❯ docker run -it ubuntu:noble /bin/bash -c 'apt-get update > /dev/null && apt-get install -y ruby > /dev/null && gem install --no-document --version 4.7.0 facter && facter hypervisor virtual'
debconf: delaying package configuration, since apt-utils is not installed
Fetching thor-1.2.2.gem
Fetching hocon-1.4.0.gem
Fetching facter-4.7.0.gem
Successfully installed thor-1.2.2
Successfully installed hocon-1.4.0
Successfully installed facter-4.7.0
3 gems installed
hypervisor => 
virtual => physical

❯ docker run -it ubuntu:noble /bin/bash -c 'apt-get update > /dev/null && apt-get install -y ruby > /dev/null && gem install --no-document --version 4.8.0 facter && facter hypervisor virtual'
debconf: delaying package configuration, since apt-utils is not installed
Fetching facter-4.8.0.gem
Fetching thor-1.2.2.gem
Fetching hocon-1.4.0.gem
Successfully installed thor-1.2.2
Successfully installed hocon-1.4.0
Successfully installed facter-4.8.0
3 gems installed
hypervisor => 
virtual => physical

❯ docker run -it ubuntu:noble /bin/bash -c 'apt-get update > /dev/null && apt-get install -y ruby > /dev/null && gem install --no-document --version 4.9.0 facter && facter hypervisor virtual'
debconf: delaying package configuration, since apt-utils is not installed
Fetching facter-4.9.0.gem
Fetching thor-1.2.2.gem
Fetching hocon-1.4.0.gem
Successfully installed thor-1.2.2
Successfully installed hocon-1.4.0
Successfully installed facter-4.9.0
3 gems installed
hypervisor => 
virtual => physical

❯ docker run -it ubuntu:noble /bin/bash -c 'apt-get update > /dev/null && apt-get install -y ruby > /dev/null && gem install --no-document --version 4.10.0 facter && facter hypervisor virtual'
debconf: delaying package configuration, since apt-utils is not installed
Fetching hocon-1.4.0.gem
Fetching facter-4.10.0.gem
Fetching thor-1.2.2.gem
Successfully installed thor-1.2.2
Successfully installed hocon-1.4.0
Successfully installed facter-4.10.0
3 gems installed
hypervisor => 
virtual => physical

EDIT: The /proc/1/environ method looks specific to starting a container via systemd https://github.com/systemd/systemd/blob/16ac586e5a77942bf1147bc9eae684d544ded88f/docs/CONTAINER_INTERFACE.md?plain=1#L415-L417

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triaged Jira issue has been created for this
Projects
None yet
Development

No branches or pull requests

3 participants