Skip to content

fix(utils): restore path normalization for open events#773

Closed
yugal07 wants to merge 2 commits intokubescape:mainfrom
yugal07:normalisedPath
Closed

fix(utils): restore path normalization for open events#773
yugal07 wants to merge 2 commits intokubescape:mainfrom
yugal07:normalisedPath

Conversation

@yugal07
Copy link
Copy Markdown
Contributor

@yugal07 yugal07 commented Apr 5, 2026

Overview

Commit 9597da4 refactored datasource_event.go to suppress verbose field
length warnings, but silently dropped the NormalizePath() calls that were
introduced in eafe066. This caused raw eBPF paths to be surfaced without
normalization, resulting in:

  • Headless /proc paths: /46/task/46/fd instead of /proc/46/task/46/fd
  • runc paths reported as . instead of /
  • Relative paths missing a leading /

This PR restores pkg/utils/path.go with the NormalizePath() function and
re-wires it into the GetPath, GetFullPath, GetExePath, GetNewPath, and
GetOldPath getter methods in both DatasourceEvent and StructEvent.

Testing -
Deploy the node-agent and inspect open events or an ApplicationProfile.
Paths should be fully absolute (e.g. /proc/46/task/46/fd) with no bare .
entries.

Unit tests can be run locally with:
go test ./pkg/utils/...

This fixes #721

Summary by CodeRabbit

  • Bug Fixes

    • Improved path normalization for event paths to ensure consistent formatting across the system.
  • Tests

    • Added comprehensive test coverage for path normalization, including edge cases for special path formats and relative-to-absolute path conversions.

Signed-off-by: yugal07-tamasha <yugal.sadhwani@tamasha.live>
Signed-off-by: yugal07-tamasha <yugal.sadhwani@tamasha.live>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 5, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 16e69940-eba6-4e50-82e1-1d90ac206558

📥 Commits

Reviewing files that changed from the base of the PR and between 5eb0191 and ebd7e22.

📒 Files selected for processing (4)
  • pkg/utils/datasource_event.go
  • pkg/utils/normalize_path_test.go
  • pkg/utils/path.go
  • pkg/utils/struct_event.go

📝 Walkthrough

Walkthrough

This pull request introduces a NormalizePath utility function that detects and restores "headless" proc-like paths (e.g., /46/task/46/fd/proc/46/task/46/fd), along with comprehensive tests. The function is integrated into path-returning methods of DatasourceEvent and StructEvent to ensure consistent path normalization across the codebase.

Changes

Cohort / File(s) Summary
Path Normalization Utility
pkg/utils/path.go
New NormalizePath function that detects headless /proc-like paths via regex, prefixes them with /proc, ensures absolute path format, and applies path.Clean normalization. Also handles empty strings and . conversion.
Path Normalization Tests
pkg/utils/normalize_path_test.go
Comprehensive test coverage for NormalizePath via TestNormalizePath with subtests for empty strings, . conversion, absolute paths, headless /proc paths, idempotence, relative-to-absolute conversion, slash trimming, and ./.. resolution.
DatasourceEvent & StructEvent
pkg/utils/datasource_event.go, pkg/utils/struct_event.go
Updated GetExePath, GetFullPath, GetNewPath, GetOldPath, and GetPath methods to wrap return values with NormalizePath(...) for consistent path normalization before returning to callers.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A rabbit hops through paths once lost,
/proc was hiding, /46/ the cost!
Now normalization brings them to light,
Headless no more—all paths shine bright! ✨

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@yugal07 yugal07 closed this Apr 5, 2026
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.

Absolute paths partially changed to relative paths for OPEN_calls in Rule0002

2 participants