diff --git a/src/ResourceDetectors/Container/.php-cs-fixer.php b/src/ResourceDetectors/Container/.php-cs-fixer.php index 248b4b9a..dd603291 100644 --- a/src/ResourceDetectors/Container/.php-cs-fixer.php +++ b/src/ResourceDetectors/Container/.php-cs-fixer.php @@ -20,7 +20,7 @@ 'blank_line_before_statement' => true, 'cast_spaces' => true, 'declare_strict_types' => true, - 'function_typehint_space' => true, + 'type_declaration_spaces' => true, 'include' => true, 'lowercase_cast' => true, 'new_with_braces' => true, @@ -34,7 +34,7 @@ 'phpdoc_scalar' => true, 'phpdoc_types' => true, 'short_scalar_cast' => true, - 'single_blank_line_before_namespace' => true, + 'blank_lines_before_namespace' => true, 'single_quote' => true, 'trailing_comma_in_multiline' => true, ]) diff --git a/src/ResourceDetectors/Container/README.md b/src/ResourceDetectors/Container/README.md index db903fc1..aeaea579 100644 --- a/src/ResourceDetectors/Container/README.md +++ b/src/ResourceDetectors/Container/README.md @@ -1,6 +1,7 @@ # OpenTelemetry Container Detector This package provides an OpenTelemetry `ResourceDetector` which will detect docker container id at runtime, using either V1 (cgroup) or V2 (mountinfo). +It should work with docker, kubernetes, and podman containers. ## Requirements diff --git a/src/ResourceDetectors/Container/composer.json b/src/ResourceDetectors/Container/composer.json index cc75afe7..213e7ebf 100644 --- a/src/ResourceDetectors/Container/composer.json +++ b/src/ResourceDetectors/Container/composer.json @@ -10,7 +10,7 @@ "prefer-stable": true, "require": { "php": "^7.0|^8.0", - "open-telemetry/sdk": ">= 1.0.0beta10" + "open-telemetry/sdk": ">= 1.0.0RC1 <= 2" }, "autoload": { "psr-4": { diff --git a/src/ResourceDetectors/Container/src/Container.php b/src/ResourceDetectors/Container/src/Container.php index dcd11492..d7b83c05 100644 --- a/src/ResourceDetectors/Container/src/Container.php +++ b/src/ResourceDetectors/Container/src/Container.php @@ -11,11 +11,13 @@ /** * @see https://github.com/open-telemetry/opentelemetry-specification/blob/v1.18.0/specification/resource/semantic_conventions/container.md + * @see https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/v1.29.0/instrumentation/resources/library/src/main/java/io/opentelemetry/instrumentation/resources/ContainerResource.java */ final class Container implements ResourceDetectorInterface { private string $dir; - private const CONTAINER_ID_LENGTH = 64; + private const CONTAINER_ID_REGEX = '/^[0-9a-f]{64}$/'; + private const V1_CONTAINER_ID_REGEX = '/\.?[0-9a-f]{64}\-?/'; private const CGROUP_V1 = 'cgroup'; private const CGROUP_V2 = 'mountinfo'; private const HOSTNAME = 'hostname'; @@ -38,9 +40,14 @@ public function getResource(): ResourceInfo private function getContainerId(): ?string { - return $this->getContainerIdV2() ?? $this->getContainerIdV1(); + return $this->getContainerIdV1() ?? $this->getContainerIdV2(); } + /** + * Each line of cgroup file looks like "14:name=systemd:/docker/.../... A hex string is expected + * inside the last section separated by '/' Each segment of the '/' can contain metadata separated + * by either '.' (at beginning) or '-' (at end) + */ private function getContainerIdV1(): ?string { if (!file_exists(sprintf('%s/%s', $this->dir, self::CGROUP_V1))) { @@ -50,11 +57,20 @@ private function getContainerIdV1(): ?string if (!$data) { return null; } - $lines = explode('\n', $data); + $lines = explode(PHP_EOL, $data); foreach ($lines as $line) { - if (strlen($line) >= self::CONTAINER_ID_LENGTH) { - //if string is longer than CONTAINER_ID_LENGTH, return the last CONTAINER_ID_LENGTH chars - return substr($line, strlen($line) - self::CONTAINER_ID_LENGTH); + if (strpos($line, '/') === false) { + continue; + } + $parts = explode('/', $line); + $section = end($parts); + $colon = strrpos($section, ':'); + if ($colon !== false) { + return substr($section, $colon); + } + $matches = []; + if (preg_match(self::V1_CONTAINER_ID_REGEX, $section, $matches) === 1) { + return $matches[0]; } } @@ -75,7 +91,7 @@ private function getContainerIdV2(): ?string if (strpos($line, self::HOSTNAME) !== false) { $parts = explode('/', $line); foreach ($parts as $part) { - if (strlen($part) === self::CONTAINER_ID_LENGTH) { + if (preg_match(self::CONTAINER_ID_REGEX, $part) === 1) { return $part; } } diff --git a/src/ResourceDetectors/Container/tests/Unit/ContainerTest.php b/src/ResourceDetectors/Container/tests/Unit/ContainerTest.php index 4ddc8774..103872d9 100644 --- a/src/ResourceDetectors/Container/tests/Unit/ContainerTest.php +++ b/src/ResourceDetectors/Container/tests/Unit/ContainerTest.php @@ -25,15 +25,65 @@ public function setUp(): void $this->detector = new Container($root->url()); } - public function test_valid_v1(): void + /** + * cgroup (v1) should take precedence over mountinfo (v2) + * @dataProvider cgroupMountinfoProvider + */ + public function test_with_cgroup_and_mountinfo(string $cgroup, string $mountinfo, string $expected): void { - $valid = 'a8493b8a4f6f23b65c5db50be86619ca4da078da040aa3d5ccff26fe50de205d'; - $this->cgroup->setContent($valid); + $cgroup && $this->cgroup->setContent($cgroup); + $mountinfo && $this->mountinfo->setContent($mountinfo); + $resource = $this->detector->getResource(); + + $this->assertSame($expected, $resource->getAttributes()->get(ResourceAttributes::CONTAINER_ID)); + } + + public static function cgroupMountinfoProvider(): array + { + return [ + 'k8s' => [ + file_get_contents(__DIR__ . '/fixtures/v1.cgroup.k8s.txt'), + file_get_contents(__DIR__ . '/fixtures/v2.mountinfo.k8s.txt'), + '78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075', + ], + 'docker with invalid cgroup' => [ + 'no-container-ids-here', + file_get_contents(__DIR__ . '/fixtures/v2.mountinfo.docker.txt'), + 'a8493b8a4f6f23b65c5db50be86619ca4da078da040aa3d5ccff26fe50de205d', + ], + 'podman' => [ + 'no-container-ids-here', + file_get_contents(__DIR__ . '/fixtures/v2.mountinfo.podman.txt'), + '2a33efc76e519c137fe6093179653788bed6162d4a15e5131c8e835c968afbe6', + ], + ]; + } + + /** + * @dataProvider cgroupProvider + */ + public function test_valid_v1(string $data, string $expected): void + { + $this->cgroup->setContent($data); $resource = $this->detector->getResource(); $this->assertSame(ResourceAttributes::SCHEMA_URL, $resource->getSchemaUrl()); $this->assertIsString($resource->getAttributes()->get(ResourceAttributes::CONTAINER_ID)); - $this->assertSame($valid, $resource->getAttributes()->get(ResourceAttributes::CONTAINER_ID)); + $this->assertSame($expected, $resource->getAttributes()->get(ResourceAttributes::CONTAINER_ID)); + } + + public static function cgroupProvider(): array + { + return [ + 'docker' => [ + file_get_contents(__DIR__ . '/fixtures/v1.cgroup.docker.txt'), + '7be92808767a667f35c8505cbf40d14e931ef6db5b0210329cf193b15ba9d605', + ], + 'k8s' => [ + file_get_contents(__DIR__ . '/fixtures/v1.cgroup.k8s.txt'), + '78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075', + ], + ]; } public function test_invalid_v1(): void @@ -44,16 +94,11 @@ public function test_invalid_v1(): void $this->assertEmpty($resource->getAttributes()); } - public function test_valid_v2(): void + /** + * @dataProvider mountinfoProvider + */ + public function test_valid_v2(string $data, string $expected): void { - $expected = 'a8493b8a4f6f23b65c5db50be86619ca4da078da040aa3d5ccff26fe50de205d'; - $data = <<< EOS -1366 1365 0:30 / /sys/fs/cgroup ro,nosuid,nodev,noexec,relatime - cgroup2 cgroup rw -1408 1362 0:107 / /dev/mqueue rw,nosuid,nodev,noexec,relatime - mqueue mqueue rw -1579 1362 0:112 / /dev/shm rw,nosuid,nodev,noexec,relatime - tmpfs shm rw,size=65536k,inode64 -1581 1359 259:2 /var/lib/docker/containers/a8493b8a4f6f23b65c5db50be86619ca4da078da040aa3d5ccff26fe50de205d/hostname /etc/hostname rw,relatime - ext4 /dev/nvme0n1p2 rw,errors=remount-ro -1583 1359 259:3 /brett/docker/otel/opentelemetry-php /usr/src/myapp rw,relatime - ext4 /dev/nvme0n1p3 rw -EOS; $this->mountinfo->withContent($data); $resource = $this->detector->getResource(); @@ -61,6 +106,20 @@ public function test_valid_v2(): void $this->assertSame($expected, $resource->getAttributes()->get(ResourceAttributes::CONTAINER_ID)); } + public static function mountinfoProvider(): array + { + return [ + 'docker' => [ + file_get_contents(__DIR__ . '/fixtures/v2.mountinfo.docker.txt'), + 'a8493b8a4f6f23b65c5db50be86619ca4da078da040aa3d5ccff26fe50de205d', + ], + 'podman' => [ + file_get_contents(__DIR__ . '/fixtures/v2.mountinfo.podman.txt'), + '2a33efc76e519c137fe6093179653788bed6162d4a15e5131c8e835c968afbe6', + ], + ]; + } + public function test_invalid_v2(): void { $data = <<< EOS diff --git a/src/ResourceDetectors/Container/tests/Unit/fixtures/v1.cgroup.docker.txt b/src/ResourceDetectors/Container/tests/Unit/fixtures/v1.cgroup.docker.txt new file mode 100644 index 00000000..2697cd97 --- /dev/null +++ b/src/ResourceDetectors/Container/tests/Unit/fixtures/v1.cgroup.docker.txt @@ -0,0 +1,14 @@ +14:name=systemd:/docker/7be92808767a667f35c8505cbf40d14e931ef6db5b0210329cf193b15ba9d605 +13:pids:/docker/7be92808767a667f35c8505cbf40d14e931ef6db5b0210329cf193b15ba9d605 +12:hugetlb:/docker/7be92808767a667f35c8505cbf40d14e931ef6db5b0210329cf193b15ba9d605 +11:net_prio:/docker/7be92808767a667f35c8505cbf40d14e931ef6db5b0210329cf193b15ba9d605 +10:perf_event:/docker/7be92808767a667f35c8505cbf40d14e931ef6db5b0210329cf193b15ba9d605 +9:net_cls:/docker/7be92808767a667f35c8505cbf40d14e931ef6db5b0210329cf193b15ba9d605 +8:freezer:/docker/7be92808767a667f35c8505cbf40d14e931ef6db5b0210329cf193b15ba9d605 +7:devices:/docker/7be92808767a667f35c8505cbf40d14e931ef6db5b0210329cf193b15ba9d605 +6:memory:/docker/7be92808767a667f35c8505cbf40d14e931ef6db5b0210329cf193b15ba9d605 +5:blkio:/docker/7be92808767a667f35c8505cbf40d14e931ef6db5b0210329cf193b15ba9d605 +4:cpuacct:/docker/7be92808767a667f35c8505cbf40d14e931ef6db5b0210329cf193b15ba9d605 +3:cpu:/docker/7be92808767a667f35c8505cbf40d14e931ef6db5b0210329cf193b15ba9d605 +2:cpuset:/docker/7be92808767a667f35c8505cbf40d14e931ef6db5b0210329cf193b15ba9d605 +1:name=openrc:/docker \ No newline at end of file diff --git a/src/ResourceDetectors/Container/tests/Unit/fixtures/v1.cgroup.k8s.txt b/src/ResourceDetectors/Container/tests/Unit/fixtures/v1.cgroup.k8s.txt new file mode 100644 index 00000000..6be49e64 --- /dev/null +++ b/src/ResourceDetectors/Container/tests/Unit/fixtures/v1.cgroup.k8s.txt @@ -0,0 +1,13 @@ +13:devices:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope +12:pids:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope +11:perf_event:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope +10:freezer:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope +9:cpuset:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope +8:hugetlb:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope +7:rdma:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope +6:misc:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope +5:memory:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope +4:cpu,cpuacct:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope +3:blkio:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope +2:net_cls,net_prio:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope +1:name=systemd:/kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope diff --git a/src/ResourceDetectors/Container/tests/Unit/fixtures/v2.mountinfo.docker.txt b/src/ResourceDetectors/Container/tests/Unit/fixtures/v2.mountinfo.docker.txt new file mode 100644 index 00000000..6904d284 --- /dev/null +++ b/src/ResourceDetectors/Container/tests/Unit/fixtures/v2.mountinfo.docker.txt @@ -0,0 +1,5 @@ +1366 1365 0:30 / /sys/fs/cgroup ro,nosuid,nodev,noexec,relatime - cgroup2 cgroup rw +1408 1362 0:107 / /dev/mqueue rw,nosuid,nodev,noexec,relatime - mqueue mqueue rw +1579 1362 0:112 / /dev/shm rw,nosuid,nodev,noexec,relatime - tmpfs shm rw,size=65536k,inode64 +1581 1359 259:2 /var/lib/docker/containers/a8493b8a4f6f23b65c5db50be86619ca4da078da040aa3d5ccff26fe50de205d/hostname /etc/hostname rw,relatime - ext4 /dev/nvme0n1p2 rw,errors=remount-ro +1583 1359 259:3 /brett/docker/otel/opentelemetry-php /usr/src/myapp rw,relatime - ext4 /dev/nvme0n1p3 rw \ No newline at end of file diff --git a/src/ResourceDetectors/Container/tests/Unit/fixtures/v2.mountinfo.k8s.txt b/src/ResourceDetectors/Container/tests/Unit/fixtures/v2.mountinfo.k8s.txt new file mode 100644 index 00000000..bd31b5d6 --- /dev/null +++ b/src/ResourceDetectors/Container/tests/Unit/fixtures/v2.mountinfo.k8s.txt @@ -0,0 +1,39 @@ +4129 4679 0:362 / / rw,relatime - overlay overlay rw,context="system_u:object_r:container_file_t:s0:c741,c758",lowerdir=/var/lib/containers/storage/overlay/l/CAURQBLP57ZJVKW2XK6RBHT2XT:/var/lib/containers/storage/overlay/l/BQSRYGKVUSPJYIXAYN3GRE7XV7:/var/lib/containers/storage/overlay/l/CLWTUDGVBTZKFU4Z675GXFXPMP:/var/lib/containers/storage/overlay/l/2U5ZCXUA56ANPDPHPEB6VYJPR4:/var/lib/containers/storage/overlay/l/M6E2CTY762WRFGWH3TS2P6ONMD:/var/lib/containers/storage/overlay/l/4PEGLBUJXYLUCBREJI6GVUYQY6:/var/lib/containers/storage/overlay/l/HO67AHLDHKU4BGVDQQIRHMWEIH:/var/lib/containers/storage/overlay/l/NPFKF3ZU7XJ5LU6RHADCRHERJ2:/var/lib/containers/storage/overlay/l/ENQKBKRWF333MJDVWX3QHU5BHE:/var/lib/containers/storage/overlay/l/KK6VKRFTFFOXJVKY3FY4QCE6TK:/var/lib/containers/storage/overlay/l/7UKV7RCONDCIVQ5R4KH7WF3EPX:/var/lib/containers/storage/overlay/l/S7FQJ3B7RMYLQBRMPF7F7OJ6IH:/var/lib/containers/storage/overlay/l/EP6A4UINXQEEWUQBHQVSQAW2OQ:/var/lib/containers/storage/overlay/l/ZROVLOOKVI4CLXUR6S3KTNT4JU,upperdir=/var/lib/containers/storage/overlay/713fceffbb83b19b98c6cd59996bed7719bddc1b86f9b7e6d85ceb0c2d519da4/diff,workdir=/var/lib/containers/storage/overlay/713fceffbb83b19b98c6cd59996bed7719bddc1b86f9b7e6d85ceb0c2d519da4/work,volatile +4130 4129 0:383 / /proc rw,nosuid,nodev,noexec,relatime - proc proc rw +4131 4129 0:384 / /dev rw,nosuid - tmpfs tmpfs rw,context="system_u:object_r:container_file_t:s0:c741,c758",size=65536k,mode=755,inode64 +4132 4131 0:385 / /dev/pts rw,nosuid,noexec,relatime - devpts devpts rw,context="system_u:object_r:container_file_t:s0:c741,c758",gid=5,mode=620,ptmxmode=666 +4133 4131 0:316 / /dev/mqueue rw,nosuid,nodev,noexec,relatime - mqueue mqueue rw,seclabel +4134 4129 0:386 / /sys ro,nosuid,nodev,noexec,relatime - sysfs sysfs ro,seclabel +4135 4134 0:387 / /sys/fs/cgroup rw,nosuid,nodev,noexec,relatime - tmpfs tmpfs rw,context="system_u:object_r:container_file_t:s0:c741,c758",mode=755,inode64 +4136 4135 0:27 /kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope /sys/fs/cgroup/systemd ro,nosuid,nodev,noexec,relatime master:9 - cgroup cgroup rw,seclabel,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd +4137 4135 0:30 /kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope /sys/fs/cgroup/net_cls,net_prio ro,nosuid,nodev,noexec,relatime master:10 - cgroup cgroup rw,seclabel,net_cls,net_prio +4138 4135 0:31 /kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope /sys/fs/cgroup/blkio ro,nosuid,nodev,noexec,relatime master:11 - cgroup cgroup rw,seclabel,blkio +4139 4135 0:32 /kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope /sys/fs/cgroup/cpu,cpuacct ro,nosuid,nodev,noexec,relatime master:12 - cgroup cgroup rw,seclabel,cpu,cpuacct +4140 4135 0:33 /kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope /sys/fs/cgroup/memory ro,nosuid,nodev,noexec,relatime master:13 - cgroup cgroup rw,seclabel,memory +4141 4135 0:34 /kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope /sys/fs/cgroup/misc ro,nosuid,nodev,noexec,relatime master:14 - cgroup cgroup rw,seclabel,misc +4142 4135 0:35 /kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope /sys/fs/cgroup/rdma ro,nosuid,nodev,noexec,relatime master:15 - cgroup cgroup rw,seclabel,rdma +4143 4135 0:36 /kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope /sys/fs/cgroup/hugetlb ro,nosuid,nodev,noexec,relatime master:16 - cgroup cgroup rw,seclabel,hugetlb +4144 4135 0:37 /kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope /sys/fs/cgroup/cpuset ro,nosuid,nodev,noexec,relatime master:17 - cgroup cgroup rw,seclabel,cpuset +4145 4135 0:38 /kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope /sys/fs/cgroup/freezer ro,nosuid,nodev,noexec,relatime master:18 - cgroup cgroup rw,seclabel,freezer +4146 4135 0:39 /kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope /sys/fs/cgroup/perf_event ro,nosuid,nodev,noexec,relatime master:19 - cgroup cgroup rw,seclabel,perf_event +4147 4135 0:40 /kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope /sys/fs/cgroup/pids ro,nosuid,nodev,noexec,relatime master:20 - cgroup cgroup rw,seclabel,pids +4148 4135 0:41 /kubepods.slice/kubepods-burstable.slice/kubepods-burstable-pod542985b6_0726_4d82_bf85_36e327b167b3.slice/crio-78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075.scope /sys/fs/cgroup/devices ro,nosuid,nodev,noexec,relatime master:21 - cgroup cgroup rw,seclabel,devices +4149 4131 0:315 / /dev/shm rw,nosuid,nodev,noexec,relatime master:1067 - tmpfs shm rw,context="system_u:object_r:container_file_t:s0:c741,c758",size=65536k,inode64 +4150 4129 0:25 /containers/storage/overlay-containers/c3e91a49d35e91f5ef2f672307a9ea830dbb80c488501ce2a6acb1cec7ee7b17/userdata/resolv.conf /etc/resolv.conf rw,nosuid,nodev,noexec master:28 - tmpfs tmpfs rw,seclabel,size=6418664k,nr_inodes=819200,mode=755,inode64 +4151 4129 0:25 /containers/storage/overlay-containers/c3e91a49d35e91f5ef2f672307a9ea830dbb80c488501ce2a6acb1cec7ee7b17/userdata/hostname /etc/hostname rw,nosuid,nodev master:28 - tmpfs tmpfs rw,seclabel,size=6418664k,nr_inodes=819200,mode=755,inode64 +4152 4129 0:25 /containers/storage/overlay-containers/c3e91a49d35e91f5ef2f672307a9ea830dbb80c488501ce2a6acb1cec7ee7b17/userdata/.containerenv /run/.containerenv rw,nosuid,nodev master:28 - tmpfs tmpfs rw,seclabel,size=6418664k,nr_inodes=819200,mode=755,inode64 +4153 4129 252:4 /ostree/deploy/rhcos/var/lib/kubelet/pods/542985b6-0726-4d82-bf85-36e327b167b3/etc-hosts /etc/hosts rw,relatime - xfs /dev/vda4 rw,seclabel,attr2,inode64,logbufs=8,logbsize=32k,prjquota +4154 4131 252:4 /ostree/deploy/rhcos/var/lib/kubelet/pods/542985b6-0726-4d82-bf85-36e327b167b3/containers/quoteservice/5e513aa6 /dev/termination-log rw,relatime - xfs /dev/vda4 rw,seclabel,attr2,inode64,logbufs=8,logbsize=32k,prjquota +4155 4129 0:25 /containers/storage/overlay-containers/78ea929aa43e7b71f7c36583d82038d92a76800bf5da9b8850e8bd7b514bc075/userdata/run/secrets /run/secrets rw,nosuid,nodev - tmpfs tmpfs rw,seclabel,size=6418664k,nr_inodes=819200,mode=755,inode64 +4156 4155 0:310 / /run/secrets/kubernetes.io/serviceaccount ro,relatime - tmpfs tmpfs rw,seclabel,size=40960k,inode64 +4157 4130 0:383 /bus /proc/bus ro,nosuid,nodev,noexec,relatime - proc proc rw +4158 4130 0:383 /fs /proc/fs ro,nosuid,nodev,noexec,relatime - proc proc rw +4159 4130 0:383 /irq /proc/irq ro,nosuid,nodev,noexec,relatime - proc proc rw +4160 4130 0:383 /sys /proc/sys ro,nosuid,nodev,noexec,relatime - proc proc rw +4161 4130 0:383 /sysrq-trigger /proc/sysrq-trigger ro,nosuid,nodev,noexec,relatime - proc proc rw +4162 4130 0:388 / /proc/acpi ro,relatime - tmpfs tmpfs ro,context="system_u:object_r:container_file_t:s0:c741,c758",inode64 +4163 4130 0:384 /null /proc/kcore rw,nosuid - tmpfs tmpfs rw,context="system_u:object_r:container_file_t:s0:c741,c758",size=65536k,mode=755,inode64 +4164 4130 0:384 /null /proc/keys rw,nosuid - tmpfs tmpfs rw,context="system_u:object_r:container_file_t:s0:c741,c758",size=65536k,mode=755,inode64 +4165 4130 0:384 /null /proc/timer_list rw,nosuid - tmpfs tmpfs rw,context="system_u:object_r:container_file_t:s0:c741,c758",size=65536k,mode=755,inode64 +4166 4130 0:389 / /proc/scsi ro,relatime - tmpfs tmpfs ro,context="system_u:object_r:container_file_t:s0:c741,c758",inode64 +4167 4134 0:390 / /sys/firmware ro,relatime - tmpfs tmpfs ro,context="system_u:object_r:container_file_t:s0:c741,c758",inode64 \ No newline at end of file diff --git a/src/ResourceDetectors/Container/tests/Unit/fixtures/v2.mountinfo.podman.txt b/src/ResourceDetectors/Container/tests/Unit/fixtures/v2.mountinfo.podman.txt new file mode 100644 index 00000000..6fb20214 --- /dev/null +++ b/src/ResourceDetectors/Container/tests/Unit/fixtures/v2.mountinfo.podman.txt @@ -0,0 +1,47 @@ +961 812 0:58 / / ro,relatime - overlay overlay rw,lowerdir=/home/dracula/.local/share/containers/storage/overlay/l/4NB35A5Z4YGWDHXYEUZU4FN6BU,upperdir=/home/dracula/.local/share/containers/storage/overlay/a73044caca1b918335d1db6f0052d21d35045136f3aa86976dbad1ec96e2fdde/diff,workdir=/home/dracula/.local/share/containers/storage/overlay/a73044caca1b918335d1db6f0052d21d35045136f3aa86976dbad1ec96e2fdde/work,userxattr +962 961 0:63 / /sys ro,nosuid,nodev,noexec,relatime - sysfs sysfs rw +963 961 0:64 / /run rw,nosuid,nodev,relatime - tmpfs tmpfs rw,uid=2024,gid=2024,inode64 +973 961 0:65 / /tmp rw,nosuid,nodev,relatime - tmpfs tmpfs rw,uid=2024,gid=2024,inode64 +974 961 0:66 / /proc rw,nosuid,nodev,noexec,relatime - proc proc rw +975 961 0:67 / /dev rw,nosuid - tmpfs tmpfs rw,size=65536k,mode=755,uid=2024,gid=2024,inode64 +976 961 0:68 / /var/tmp rw,nosuid,nodev,relatime - tmpfs tmpfs rw,uid=2024,gid=2024,inode64 +977 975 0:62 / /dev/mqueue rw,nosuid,nodev,noexec,relatime - mqueue mqueue rw +978 975 0:69 / /dev/pts rw,nosuid,noexec,relatime - devpts devpts rw,gid=427684,mode=620,ptmxmode=666 +979 975 0:57 / /dev/shm rw,nosuid,nodev,noexec,relatime - tmpfs shm rw,size=64000k,uid=2024,gid=2024,inode64 +980 963 0:56 /containers/overlay-containers/2a33efc76e519c137fe6093179653788bed6162d4a15e5131c8e835c968afbe6/userdata/.containerenv /run/.containerenv ro,nosuid,nodev,noexec,relatime - tmpfs tmpfs rw,size=783888k,nr_inodes=195972,mode=700,uid=2024,gid=2024,inode64 +981 961 0:56 /containers/overlay-containers/2a33efc76e519c137fe6093179653788bed6162d4a15e5131c8e835c968afbe6/userdata/resolv.conf /etc/resolv.conf ro,nosuid,nodev,noexec,relatime - tmpfs tmpfs rw,size=783888k,nr_inodes=195972,mode=700,uid=2024,gid=2024,inode64 +982 961 0:56 /containers/overlay-containers/2a33efc76e519c137fe6093179653788bed6162d4a15e5131c8e835c968afbe6/userdata/hosts /etc/hosts ro,nosuid,nodev,noexec,relatime - tmpfs tmpfs rw,size=783888k,nr_inodes=195972,mode=700,uid=2024,gid=2024,inode64 +983 961 0:56 /containers/overlay-containers/2a33efc76e519c137fe6093179653788bed6162d4a15e5131c8e835c968afbe6/userdata/hostname /etc/hostname ro,nosuid,nodev,noexec,relatime - tmpfs tmpfs rw,size=783888k,nr_inodes=195972,mode=700,uid=2024,gid=2024,inode64 +984 962 0:70 / /sys/fs/cgroup rw,nosuid,nodev,noexec,relatime - tmpfs cgroup rw,size=1024k,uid=2024,gid=2024,inode64 +985 984 0:44 / /sys/fs/cgroup/misc ro,nosuid,nodev,noexec,relatime - cgroup cgroup rw,misc +986 984 0:43 / /sys/fs/cgroup/freezer ro,nosuid,nodev,noexec,relatime - cgroup cgroup rw,freezer +987 984 0:42 /user.slice /sys/fs/cgroup/devices ro,nosuid,nodev,noexec,relatime - cgroup cgroup rw,devices +988 984 0:41 /user.slice/user-2024.slice/user@2024.service /sys/fs/cgroup/pids ro,nosuid,nodev,noexec,relatime - cgroup cgroup rw,pids +989 984 0:40 /user.slice /sys/fs/cgroup/blkio ro,nosuid,nodev,noexec,relatime - cgroup cgroup rw,blkio +990 984 0:39 / /sys/fs/cgroup/rdma ro,nosuid,nodev,noexec,relatime - cgroup cgroup rw,rdma +991 984 0:38 /user.slice/user-2024.slice/user@2024.service /sys/fs/cgroup/memory ro,nosuid,nodev,noexec,relatime - cgroup cgroup rw,memory +992 984 0:37 / /sys/fs/cgroup/cpuset ro,nosuid,nodev,noexec,relatime - cgroup cgroup rw,cpuset +993 984 0:36 / /sys/fs/cgroup/perf_event ro,nosuid,nodev,noexec,relatime - cgroup cgroup rw,perf_event +994 984 0:35 / /sys/fs/cgroup/net_cls,net_prio ro,nosuid,nodev,noexec,relatime - cgroup cgroup rw,net_cls,net_prio +995 984 0:34 /user.slice /sys/fs/cgroup/cpu,cpuacct ro,nosuid,nodev,noexec,relatime - cgroup cgroup rw,cpu,cpuacct +996 984 0:33 / /sys/fs/cgroup/hugetlb ro,nosuid,nodev,noexec,relatime - cgroup cgroup rw,hugetlb +997 984 0:30 /user.slice/user-2024.slice/user@2024.service/user.slice/podman-5094.scope /sys/fs/cgroup/systemd ro,nosuid,nodev,noexec,relatime - cgroup cgroup rw,xattr,name=systemd +998 975 0:5 /null /dev/null rw,relatime - devtmpfs devtmpfs rw,size=3912976k,nr_inodes=978244,mode=755,inode64 +999 975 0:5 /zero /dev/zero rw,relatime - devtmpfs devtmpfs rw,size=3912976k,nr_inodes=978244,mode=755,inode64 +1000 975 0:5 /full /dev/full rw,relatime - devtmpfs devtmpfs rw,size=3912976k,nr_inodes=978244,mode=755,inode64 +1001 975 0:5 /tty /dev/tty rw,relatime - devtmpfs devtmpfs rw,size=3912976k,nr_inodes=978244,mode=755,inode64 +1002 975 0:5 /random /dev/random rw,relatime - devtmpfs devtmpfs rw,size=3912976k,nr_inodes=978244,mode=755,inode64 +1003 975 0:5 /urandom /dev/urandom rw,relatime - devtmpfs devtmpfs rw,size=3912976k,nr_inodes=978244,mode=755,inode64 +1004 974 0:71 / /proc/acpi ro,relatime - tmpfs tmpfs rw,size=0k,uid=2024,gid=2024,inode64 +1005 974 0:5 /null /proc/kcore rw,relatime - devtmpfs devtmpfs rw,size=3912976k,nr_inodes=978244,mode=755,inode64 +1006 974 0:5 /null /proc/keys rw,relatime - devtmpfs devtmpfs rw,size=3912976k,nr_inodes=978244,mode=755,inode64 +1007 974 0:5 /null /proc/timer_list rw,relatime - devtmpfs devtmpfs rw,size=3912976k,nr_inodes=978244,mode=755,inode64 +1008 974 0:72 / /proc/scsi ro,relatime - tmpfs tmpfs rw,size=0k,uid=2024,gid=2024,inode64 +1009 962 0:73 / /sys/firmware ro,relatime - tmpfs tmpfs rw,size=0k,uid=2024,gid=2024,inode64 +1010 962 0:74 / /sys/dev/block ro,relatime - tmpfs tmpfs rw,size=0k,uid=2024,gid=2024,inode64 +1011 974 0:66 /bus /proc/bus ro,relatime - proc proc rw +1012 974 0:66 /fs /proc/fs ro,relatime - proc proc rw +1013 974 0:66 /irq /proc/irq ro,relatime - proc proc rw +1014 974 0:66 /sys /proc/sys ro,relatime - proc proc rw +1015 974 0:66 /sysrq-trigger /proc/sysrq-trigger ro,relatime - proc proc rw +813 975 0:69 /0 /dev/console rw,nosuid,noexec,relatime - devpts devpts rw,gid=427684,mode=620,ptmxmode=666 \ No newline at end of file