Skip to content

fix(core): use TaskExit type to unmarshal containerd exit events#2527

Merged
Aryan-sharma11 merged 2 commits into
kubearmor:mainfrom
Athang69:fix/containerd-exit-v2
Jun 9, 2026
Merged

fix(core): use TaskExit type to unmarshal containerd exit events#2527
Aryan-sharma11 merged 2 commits into
kubearmor:mainfrom
Athang69:fix/containerd-exit-v2

Conversation

@Athang69

@Athang69 Athang69 commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

Purpose of PR?:

/tasks/exit handler was using apievents.TaskStart instead of apievents.TaskExit causing GetPid() to always return 0, so destroy was never triggered leaving stale entries in dm.Containers and eBPF NsMap.

Fixes #2526

Does this PR introduce a breaking change?

No

If the changes in this PR are manually verified, list down the scenarios covered:
Container exit event correctly unmarshaled, GetPid() returns correct pid, destroy path triggers correctly, /tasks/start handling unaffected.

Additional information for reviewer? :
One line fix - apievents.TaskStart to apievents.TaskExit in /tasks/exit case. ContainerID is field1 in both types so container lookup worked fine making the bug subtle - only the pid comparison was silently broken. Added containerdHandler_test.go with 4 unit tests proving the mismatch and verifying the fix.

Issue

Checklist:

@Athang69

Athang69 commented Apr 9, 2026

Copy link
Copy Markdown
Contributor Author

Hi @Aryan-sharma11 @rksharma95, gentle ping on this PR would appreciate your review when possible. Thanks!

Comment thread .gitignore Outdated
@Athang69 Athang69 requested a review from Aryan-sharma11 April 10, 2026 04:20
Aryan-sharma11
Aryan-sharma11 previously approved these changes Apr 10, 2026
@Aryan-sharma11

Copy link
Copy Markdown
Member

LGTM @Athang69 🚀. Thanks for the PR.
go-vuln will be fixed after merging this PR #2487

Copilot AI review requested due to automatic review settings May 17, 2026 11:01

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

One-line bug fix in the containerd event handler: the /tasks/exit case was unmarshaling event payloads into apievents.TaskStart instead of apievents.TaskExit. Because the two protobuf types share field 1 (ContainerID) but differ in subsequent field numbers, GetPid() always returned 0, so the pid == exitTask.GetPid() guard failed and stale entries accumulated in dm.Containers and the eBPF NsMap.

Changes:

  • Swap apievents.TaskStart{} for apievents.TaskExit{} in the /tasks/exit branch of handleContainerdEvent.
  • Add unit tests demonstrating the proto field-number mismatch and verifying the fix.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
KubeArmor/core/containerdHandler.go Use correct TaskExit proto type when unmarshaling /tasks/exit events so GetPid() returns the actual exiting pid.
KubeArmor/core/containerdHandler_test.go New unit tests covering the bug, edge case (pid=0), shared ContainerID field, and unchanged TaskStart handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Athang69 Athang69 force-pushed the fix/containerd-exit-v2 branch from 6de4b64 to 85962ae Compare May 17, 2026 11:04
@Athang69

Copy link
Copy Markdown
Contributor Author

Raised PR #2605 for addressing the failing CI test

@Aryan-sharma11

Copy link
Copy Markdown
Member

@Athang69, kindly rebase this PR.

@Athang69 Athang69 force-pushed the fix/containerd-exit-v2 branch from 23c5096 to 7b22ae9 Compare June 4, 2026 06:49
@Athang69

Athang69 commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

@Aryan-sharma11 done.
PTAL

@Athang69

Athang69 commented Jun 6, 2026

Copy link
Copy Markdown
Contributor Author

@rksharma95 PTAL whenever convenient.
Thanks!

@Athang69

Athang69 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

This PR has received the required approvals. Could someone merge it when convenient?
Thankss!

@Aryan-sharma11 Aryan-sharma11 force-pushed the fix/containerd-exit-v2 branch from ddbd3e5 to 9e56cac Compare June 9, 2026 03:47
Athang69 added 2 commits June 9, 2026 14:53
/tasks/exit handler was using apievents.TaskStart instead of
apievents.TaskExit causing GetPid() to always return 0 and
stale entries in dm.Containers and eBPF NsMap.

Fixes kubearmor#2526

Signed-off-by: Athang69 <[email protected]>
@Aryan-sharma11 Aryan-sharma11 force-pushed the fix/containerd-exit-v2 branch from 9e56cac to da24840 Compare June 9, 2026 09:23
@Aryan-sharma11

Copy link
Copy Markdown
Member

LGTM! Thanks for the PR @Athang69

@Aryan-sharma11 Aryan-sharma11 merged commit 6dcee36 into kubearmor:main Jun 9, 2026
20 checks passed
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.

bug: /tasks/exit handler unmarshals into wrong protobuf type (TaskStart instead of TaskExit), causing stale container entries

5 participants