Skip to content

Commit ebb90da

Browse files
committed
fix: address review comments
Signed-off-by: Roberto Scolaro <[email protected]>
1 parent 744ef78 commit ebb90da

File tree

7 files changed

+64
-38
lines changed

7 files changed

+64
-38
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
git \
4141
libelf-dev \
4242
libtool \
43-
linux-tools-`uname -r` \
43+
linux-tools-$(uname -r) \
4444
llvm \
4545
ninja-build \
4646
pkg-config \

.github/workflows/release-draft.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
git \
5151
libelf-dev \
5252
libtool \
53-
linux-tools-`uname -r` \
53+
linux-tools-$(uname -r) \
5454
llvm \
5555
ninja-build \
5656
pkg-config \

cmake/modules/container_plugin.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ include(ExternalProject)
1717

1818
string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} PLUGINS_SYSTEM_NAME)
1919

20-
set(CONTAINER_VERSION "0.3.7")
20+
set(CONTAINER_VERSION "0.4.1")
2121

2222
if(UNIX AND NOT APPLE)
2323

2424
set(CONTAINER_LIBRARY
2525
"${CMAKE_BINARY_DIR}/container_plugin-prefix/src/container_plugin/libcontainer.so"
2626
)
2727
if(${CMAKE_HOST_SYSTEM_PROCESSOR} STREQUAL "x86_64")
28-
set(CONTAINER_HASH "fd4e0b36ff9eb8ea34ee8166d0bfa29f9de7939e7c6e1ef931a9d6261b20f5ab")
28+
set(CONTAINER_HASH "2ca0390f8b44bb4d0ec4c7f030dfb82af349897d00276393b6cb29281e14588e")
2929
else() # arm64
30-
set(CONTAINER_HASH "fb13572da413d2272d249459f0afd1879514a265e43acaaa8a844163bede239d")
30+
set(CONTAINER_HASH "aa69ae222fb3947d9eac3756e06d5006964e1544130d3ebff398a18462fd0b12")
3131
endif()
3232

3333
if(NOT TARGET container_plugin)
@@ -75,7 +75,7 @@ else()
7575
ExternalProject_Add(
7676
container_plugin
7777
URL "https://github.com/falcosecurity/plugins/archive/refs/tags/plugins/container/v${CONTAINER_VERSION}.tar.gz"
78-
URL_HASH "SHA256=da063e8d99310596a4c369fb010053e391247f2db6cd3fae9e733582923b71c4"
78+
URL_HASH "SHA256=7adbd1062533dbd3f6d18e77abe44f63dd80cf40ebb7755d0a1bdb8298888ac4"
7979
SOURCE_SUBDIR plugins/container
8080
BUILD_IN_SOURCE 1
8181
BUILD_BYPRODUCTS "${CONTAINER_LIBRARY}"

userspace/sysdig/csysdig.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ limitations under the License.
2121

2222
#include <stdio.h>
2323
#include <iostream>
24-
#include <fstream>
25-
#include <sstream>
26-
#include <filesystem>
2724
#include <time.h>
2825
#include <signal.h>
2926
#include <fcntl.h>
@@ -418,19 +415,8 @@ sysdig_init_res csysdig_init(int argc, char **argv)
418415
plugins.add_directory(SYSDIG_PLUGINS_DIR);
419416
plugins.read_plugins_from_dirs(inspector);
420417

421-
// Load container plugin
422-
std::string container_config = R"({"hooks":["create","start"],"engines":{"docker":{"enabled":true,"sockets":["/var/run/docker.sock"]},"podman":{"enabled":true,"sockets":["/run/podman/podman.sock","/run/user/1000/podman/podman.sock"]},"containerd":{"enabled":false,"sockets":["/run/containerd/containerd.sock"]},"cri":{"enabled":true,"sockets":["/run/crio/crio.sock"]},"lxc":{"enabled":false},"libvirt_lxc":{"enabled":false},"bpm":{"enabled":false}}})";
423-
auto container_config_file = "/etc/sysdig/container.json";
424-
if (std::filesystem::exists(container_config_file))
425-
{
426-
std::ifstream file(container_config_file);
427-
std::stringstream buffer;
428-
buffer << file.rdbuf();
429-
container_config = buffer.str();
430-
}
431-
432-
plugins.load_plugin(inspector, "container");
433-
plugins.config_plugin(inspector, "container", container_config);
418+
// Load container plugin (if available)
419+
plugins.load_container_plugin_if_available(inspector);
434420

435421
//
436422
// Parse the args

userspace/sysdig/sysdig.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@ limitations under the License.
2121

2222
#include <stdio.h>
2323
#include <iostream>
24-
#include <fstream>
25-
#include <sstream>
2624
#include <time.h>
2725
#include <signal.h>
2826
#include <fcntl.h>
2927
#include <sys/stat.h>
3028
#include <assert.h>
3129
#include <algorithm>
3230
#include <atomic>
33-
#include <filesystem>
3431

3532
#include <libsinsp/sinsp.h>
3633
#include <libsinsp/sinsp_cycledumper.h>
@@ -1096,19 +1093,8 @@ sysdig_init_res sysdig_init(int argc, char **argv)
10961093
plugins.add_directory(SYSDIG_PLUGINS_DIR);
10971094
plugins.read_plugins_from_dirs(inspector.get());
10981095

1099-
// Load container plugin
1100-
std::string container_config = R"({"hooks":["create","start"],"engines":{"docker":{"enabled":true,"sockets":["/var/run/docker.sock"]},"podman":{"enabled":true,"sockets":["/run/podman/podman.sock","/run/user/1000/podman/podman.sock"]},"containerd":{"enabled":false,"sockets":["/run/containerd/containerd.sock"]},"cri":{"enabled":true,"sockets":["/run/crio/crio.sock", "/run/containerd/containerd.sock"]},"lxc":{"enabled":false},"libvirt_lxc":{"enabled":false},"bpm":{"enabled":false}}})";
1101-
auto container_config_file = "/etc/sysdig/container.json";
1102-
if (std::filesystem::exists(container_config_file))
1103-
{
1104-
std::ifstream file(container_config_file);
1105-
std::stringstream buffer;
1106-
buffer << file.rdbuf();
1107-
container_config = buffer.str();
1108-
}
1109-
1110-
plugins.load_plugin(inspector.get(), "container");
1111-
plugins.config_plugin(inspector.get(), "container", container_config);
1096+
// Load container plugin (if available)
1097+
plugins.load_container_plugin_if_available(inspector.get());
11121098

11131099
//
11141100
// Parse the args

userspace/sysdig/utils/plugin_utils.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ limitations under the License.
2222

2323
#include <utility>
2424
#include <filesystem>
25+
#include <fstream>
26+
#include <sstream>
2527
#include <yaml-cpp/yaml.h>
2628
#include <nlohmann/json.hpp>
2729

@@ -644,3 +646,52 @@ std::vector<std::unique_ptr<sinsp_filter_check>> plugin_utils::get_filterchecks(
644646
}
645647
return list;
646648
}
649+
650+
bool plugin_utils::load_container_plugin_if_available(sinsp *inspector)
651+
{
652+
// Check if container plugin exists in any of the plugin directories
653+
std::string soname = SHAREDOBJ_PREFIX "container" SHAREDOBJ_EXT;
654+
bool plugin_exists = false;
655+
656+
iterate_plugins_dirs(m_dirs, [&soname, &plugin_exists] (const std::filesystem::path file) -> bool {
657+
auto filename = file.filename().generic_string();
658+
if (filename == soname)
659+
{
660+
plugin_exists = true;
661+
return true; // break-out
662+
}
663+
return false;
664+
});
665+
666+
if (!plugin_exists)
667+
{
668+
fprintf(stderr, "Warning: container plugin (%s) not found in plugin directories. Container metadata will not be available.\n", soname.c_str());
669+
fprintf(stderr, " This is expected if you're running sysdig standalone (not installed via package manager).\n");
670+
return false;
671+
}
672+
673+
try
674+
{
675+
// Load container configuration from file or use default
676+
std::string container_config = R"({"hooks":["create","start"],"engines":{"docker":{"enabled":true,"sockets":["/var/run/docker.sock"]},"podman":{"enabled":true,"sockets":["/run/podman/podman.sock","/run/user/1000/podman/podman.sock"]},"containerd":{"enabled":false,"sockets":["/run/containerd/containerd.sock"]},"cri":{"enabled":true,"sockets":["/run/crio/crio.sock", "/run/containerd/containerd.sock"]},"lxc":{"enabled":false},"libvirt_lxc":{"enabled":false},"bpm":{"enabled":false}}})";
677+
auto container_config_file = "/etc/sysdig/container.json";
678+
if (std::filesystem::exists(container_config_file))
679+
{
680+
std::ifstream file(container_config_file);
681+
std::stringstream buffer;
682+
buffer << file.rdbuf();
683+
container_config = buffer.str();
684+
}
685+
686+
// Load and configure the plugin
687+
load_plugin(inspector, "container");
688+
config_plugin(inspector, "container", container_config);
689+
return true;
690+
}
691+
catch (const sinsp_exception& e)
692+
{
693+
fprintf(stderr, "Warning: failed to load container plugin: %s\n", e.what());
694+
fprintf(stderr, " Container metadata will not be available.\n");
695+
return false;
696+
}
697+
}

userspace/sysdig/utils/plugin_utils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class plugin_utils
3939

4040
void config_plugin(sinsp *inspector, const std::string& name, const std::string& conf);
4141

42+
// Load container plugin if available, with graceful fallback
43+
bool load_container_plugin_if_available(sinsp *inspector);
44+
4245
void select_input_plugin(sinsp *inspector, filter_check_list* flist, const std::string& name, const std::string& params);
4346
void clear_input_plugin();
4447

0 commit comments

Comments
 (0)