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

Fix docker detection in ohai virtualization #1476

Merged
merged 1 commit into from
Jun 30, 2020
Merged

Conversation

jaymzh
Copy link
Collaborator

@jaymzh jaymzh commented Jun 30, 2020

We ran into an issue where when running in docker containers on GH
Actions (which is on azure which is on HyperV), we were getting detected
as being run on a hyperv guest... which is indirectly true, but not
really the most correct answer.

It turns out we were being a bit too strict in this regex. I think.

So here's the /proc/self/cgroup:

12:blkio:/actions_job/4ab5ebdc794956d804d03db04557c8b79fa985cbf54bc25f51f2b0848e3f58bd
11:devices:/actions_job/4ab5ebdc794956d804d03db04557c8b79fa985cbf54bc25f51f2b0848e3f58bd
10:memory:/actions_job/4ab5ebdc794956d804d03db04557c8b79fa985cbf54bc25f51f2b0848e3f58bd
9:freezer:/actions_job/4ab5ebdc794956d804d03db04557c8b79fa985cbf54bc25f51f2b0848e3f58bd
8:cpuset:/actions_job/4ab5ebdc794956d804d03db04557c8b79fa985cbf54bc25f51f2b0848e3f58bd
7:pids:/actions_job/4ab5ebdc794956d804d03db04557c8b79fa985cbf54bc25f51f2b0848e3f58bd
6:rdma:/
5:hugetlb:/actions_job/4ab5ebdc794956d804d03db04557c8b79fa985cbf54bc25f51f2b0848e3f58bd
4:perf_event:/actions_job/4ab5ebdc794956d804d03db04557c8b79fa985cbf54bc25f51f2b0848e3f58bd
3:cpu,cpuacct:/actions_job/4ab5ebdc794956d804d03db04557c8b79fa985cbf54bc25f51f2b0848e3f58bd
2:net_cls,net_prio:/actions_job/4ab5ebdc794956d804d03db04557c8b79fa985cbf54bc25f51f2b0848e3f58bd
1:name=systemd:/actions_job/4ab5ebdc794956d804d03db04557c8b79fa985cbf54bc25f51f2b0848e3f58bd
0::/system.slice/docker.service

As you can see the second field (or 1st field if you 0-index) is empty,
and it's still docker.

@jaymzh jaymzh requested review from a team as code owners June 30, 2020 01:12
@davide125
Copy link
Contributor

IMO we should also break out of the elsif the dockerenv test on line 244 -- this is relevant regardless of the state of the cgroup config. We might also want to add a check for podman, which uses yet another flag file (/.container iir, but you'll want to double check).

@davide125
Copy link
Contributor

Also see containers/podman#3586

@tas50
Copy link
Contributor

tas50 commented Jun 30, 2020

@jaymzh Can you toss a https://rubular.com/ permalink with the match into the comments so people can go see what that regex was meant to match. Make sure to include this format as well as the non-empty field format so you can show it matching both.

@jaymzh
Copy link
Collaborator Author

jaymzh commented Jun 30, 2020

@davide125 - I don't want to change the overall design of the plugin - as it stands, last-writer wins.

@tas50 - I can add a permalink, but I don't have an example of a non-empty field. If you have one, I can add it.

We ran into an issue where when running in docker containers on GH
Actions (which is on azure which is on HyperV), we were getting detected
as being run on a hyperv guest... which is indirectly true, but not
really the most correct answer.

It turns out we were being a bit too strict in this regex. I think.

So here's the `/proc/self/cgroup`:

```
12:blkio:/actions_job/4ab5ebdc794956d804d03db04557c8b79fa985cbf54bc25f51f2b0848e3f58bd
11:devices:/actions_job/4ab5ebdc794956d804d03db04557c8b79fa985cbf54bc25f51f2b0848e3f58bd
10:memory:/actions_job/4ab5ebdc794956d804d03db04557c8b79fa985cbf54bc25f51f2b0848e3f58bd
9:freezer:/actions_job/4ab5ebdc794956d804d03db04557c8b79fa985cbf54bc25f51f2b0848e3f58bd
8:cpuset:/actions_job/4ab5ebdc794956d804d03db04557c8b79fa985cbf54bc25f51f2b0848e3f58bd
7:pids:/actions_job/4ab5ebdc794956d804d03db04557c8b79fa985cbf54bc25f51f2b0848e3f58bd
6:rdma:/
5:hugetlb:/actions_job/4ab5ebdc794956d804d03db04557c8b79fa985cbf54bc25f51f2b0848e3f58bd
4:perf_event:/actions_job/4ab5ebdc794956d804d03db04557c8b79fa985cbf54bc25f51f2b0848e3f58bd
3:cpu,cpuacct:/actions_job/4ab5ebdc794956d804d03db04557c8b79fa985cbf54bc25f51f2b0848e3f58bd
2:net_cls,net_prio:/actions_job/4ab5ebdc794956d804d03db04557c8b79fa985cbf54bc25f51f2b0848e3f58bd
1:name=systemd:/actions_job/4ab5ebdc794956d804d03db04557c8b79fa985cbf54bc25f51f2b0848e3f58bd
0::/system.slice/docker.service
```

As you can see the second field (or 1st field if you 0-index) is empty,
and it's still docker.

Signed-off-by: Phil Dibowitz <phil@ipom.com>
@jaymzh
Copy link
Collaborator Author

jaymzh commented Jun 30, 2020

one rubular link added.

@tas50 tas50 merged commit 8fb5fb6 into chef:master Jun 30, 2020
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.

None yet

3 participants