Repository navigation
classifier: skip Docker container processes to fix docker exec failure #334
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -471,11 +471,43 @@ void ContextualClassifier::loadStaticProcData() { | |
| LOGI(CLASSIFIER_TAG, "Successfully loaded static proc data"); | ||
| } | ||
|
|
||
| int8_t ContextualClassifier::isContainerProcess(pid_t pid) { | ||
| // Check if the process lives inside a container cgroup scope by reading | ||
| // /proc/<pid>/cgroup. A Docker container init process has a path like: | ||
| // 0::/system.slice/docker-<CID>.scope | ||
| // Moving it out of this scope causes systemd to remove the now-empty scope, | ||
| // which breaks subsequent docker exec calls with: | ||
| // "can't open cgroup: .../docker-<CID>.scope: No such file or directory" | ||
|
|
||
| // TODO: extend to Kubernetes container runtimes when needed: | ||
| // - containerd (k8s default runtime): cgroup path contains "containerd-<CID>.scope" | ||
| // - CRI-O (OpenShift / k8s alternative): cgroup path contains "crio-<CID>.scope" | ||
|
|
||
| std::ifstream cgroupFile("/proc/" + std::to_string(pid) + "/cgroup"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can't we add this to a exclusion list that classifier already has, why whitelisting code needed?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if(cgroupFile.is_open()) { | ||
| std::string line; | ||
| while(std::getline(cgroupFile, line)) { | ||
| if(line.find("docker-") != std::string::npos && | ||
| line.find(".scope") != std::string::npos) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+485
to
+495
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Functionality] Fragile substring matching for container-scope detection - Medium In Fixed Code Snippet#include <regex>
...
static const std::regex kDockerScopeRegex(R"(docker-[0-9a-fA-F]+\.scope)");
...
while(std::getline(cgroupFile, line)) {
if(std::regex_search(line, kDockerScopeRegex)) {
return true;
}
} |
||
| return false; | ||
| } | ||
|
|
||
| int8_t ContextualClassifier::shouldProcBeIgnored(int32_t evType, pid_t pid) { | ||
| if(evType == CC_APP_CLOSE) { | ||
| return false; | ||
|
Comment on lines
+484
to
501
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Functionality] Substring-based docker scope detection may produce false positives The detection logic checks whether a single cgroup line contains both Consider using a more precise match, e.g., checking that Fixed Code Snippet// Example of tighter matching using find + suffix check
size_t dockerPos = line.find("docker-");
if(dockerPos != std::string::npos &&
line.compare(line.size() - 6, 6, ".scope") == 0) {
return true;
} |
||
| } | ||
|
|
||
| // Skip Docker container init processes to avoid breaking docker exec. | ||
| if(this->isContainerProcess(pid)) { | ||
| LOGI(CLASSIFIER_TAG, | ||
| "Ignoring Docker container process PID: " + std::to_string(pid)); | ||
| return true; | ||
| } | ||
|
|
||
| std::string procName = ""; | ||
| if(AuxRoutines::fetchComm(pid, procName) != 0) { | ||
| return true; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the current
name-basedfiltering is more of a Docker-specific workaround. Sincesystemd-run,systemd-nspawn, and other cgroup-managed workloads may run into the same issue, is there a more generic solution based on cgroup hierarchy rather than process/container names?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is intentionally specific to Docker.
Consider this a hotfix for the issue reported in https://orbit/CR/4689720. A more generic solution (e.g. detecting any external cgroup manager, not just Docker) that we can track through #333 urm issue