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(src,cmake,go-worker): multiple fixes. #6

Merged
merged 1 commit into from
Dec 3, 2024
Merged

Conversation

FedeDP
Copy link
Owner

@FedeDP FedeDP commented Dec 3, 2024

First of all, podman had a runtime dep on gpgme (libgpgme-dev). Install it through vcpkg (as static) to avoid linking issues for the library consumer.

Second, in go-worker Container struct, omit empty structured fields (slices, maps...), to avoid wasting memory space (plus all the back and forth copies).

Finally, fixed some bugs all around the C++ implementation.

All of these were spotted thanks to the newly added possibility to load plugins in sinsp-example: falcosecurity/libs#2179.

- name: Install deps
run:
sudo apt-get install -y --no-install-recommends libbtrfs-dev libgpgme-dev
sudo apt-get install -y --no-install-recommends libbtrfs-dev
Copy link
Owner Author

@FedeDP FedeDP Dec 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only dep left, but is compile time only.

@@ -70,46 +70,49 @@ void from_json(const nlohmann::json& j, container_port_mapping& port) {
}

void from_json(const nlohmann::json& j, std::shared_ptr<container_info>& cinfo) {
std::shared_ptr<container_info> info = std::make_shared<container_info>();
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed cinfo filling to avoid dereferencing null ptr.

info->m_host_ipc = container.value("host_ipc", false);
info->m_host_network = container.value("host_network", false);
info->m_host_pid = container.value("host_pid", false);
info->m_container_ip = container.value("ip", "");
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed default value for m_container_ip that is actually a string.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed wrong TODOs.

int32_t(evt_reader.get_type()));
return false;
}
auto thread_id = evt_reader.get_tid();
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thread_id is actually an uint64_t, no need to check for <= 0.

SPDLOG_ERROR("cannot extract the container_id for the thread id '{}': {}",
} catch(falcosecurity::plugin_exception e) {
// Debug here since many events do not have thread id info (eg: schedswitch)
SPDLOG_DEBUG("cannot extract the container_id for the thread id '{}': {}",
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a debug here: there can be events (eg: schedswitch) that do not have any threadinfo associated.

@@ -138,15 +135,18 @@ std::string my_plugin::compute_container_id_for_thread(const falcosecurity::tabl
tr,
[&](const falcosecurity::table_entry& e)
{
if (!container_id.empty()) {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that returning false would stop the loop, instead it raised an exception 💀

}
return true;
} catch (falcosecurity::plugin_exception &e) {
SPDLOG_ERROR("cannot attach container_id to new process event for the thread id '{}': {}",
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually an error since we are parsing a process event (ie: execve, clone and so on), therefore thread_id MUST be present.

@@ -4,6 +4,7 @@
"license": "MIT",
"dependencies": [
"re2",
"spdlog"
"spdlog",
"gpgme"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New dep.

First of all, podman had a runtime dep on `gpgme` (`libgpgme-dev`).
Install it through vcpkg (as static) to avoid linking issues for the library consumer.

Second, in go-worker Container struct, omit empty structured fields (slices, maps...),
to avoid wasting memory space (plus all the back and forth copies).

Finally, fixed some bugs all around the C++ implementation.

Signed-off-by: Federico Di Pierro <[email protected]>
@FedeDP FedeDP force-pushed the fix/multiple_fixes branch from 0809359 to 178eb89 Compare December 3, 2024 15:47
@FedeDP FedeDP merged commit 43f179f into main Dec 3, 2024
1 check passed
@FedeDP FedeDP deleted the fix/multiple_fixes branch December 3, 2024 16:09
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.

1 participant