Skip to content

fix(exceptions): resolve ephemeral container paths for containerName exceptions - #196

Merged
matthyx merged 1 commit into
kubescape:mainfrom
VISHNU0906:fix/exception-ephemeral-container-paths
Nov 10, 2026
Merged

matthyx merged 1 commit into
kubescape:mainfrom
VISHNU0906:fix/exception-ephemeral-container-paths

Conversation

@VISHNU0906

Copy link
Copy Markdown
Contributor

Overview

The regolibrary container rules now report Pod findings on spec.ephemeralContainers[N] (e.g. container-hostPort, set-seLinuxOptions). extractFailingContainerNames only recognised containers[N] and initContainers[N], so for those findings it returned nothing and compareContainerName fell back to scanning the regular and init containers. Two things go wrong:

  • an exception with containerName: app also silences a finding on the ephemeral debugger container in the same Pod, which is the case a0483ba set out to prevent;
  • an exception that names the ephemeral container never matches, because the fallback scan doesn't look at ephemeral containers.

This change parses ephemeralContainers[N] paths and adds ephemeral containers to the fallback scan. The pinned k8s-interface version has no ephemeral container getter, so the names are read from spec.ephemeralContainers in a small helper.

How to Test

  • New TestSetRuleResponsExceptions_EphemeralContainerPrecision goes through SetRuleResponsExceptions with a Pod that has app and an ephemeral debugger: exception on the failing ephemeral container applies, exception on app does not, and the no-paths fallback finds debugger.
  • TestComparator_compareContainerName gets an ephemeral case, plus a unit test for the helper.
  • Reverting the path regex or the fallback loop makes the matching cases fail. go test -race ./..., go test ./... -covermode=count and go build ./... pass; golangci-lint shows the same two existing staticcheck findings as on main.

cc @matthyx

…exceptions

Container rules now report Pod findings on spec.ephemeralContainers[N], but
the failed-path parser only knew containers[N] and initContainers[N]. The
finding fell back to the whole-workload scan, so an exception for container
"app" also silenced a finding on an ephemeral "debugger" container, and
an exception naming the ephemeral container never matched.

Parse ephemeralContainers[N] paths and include ephemeral containers in the
fallback scan.

Signed-off-by: KVR Vishnu <46535652+VISHNU0906@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Nov 10, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1d559fb1-8a14-4dfd-b0a8-41498bc357ee
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@matthyx matthyx left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed head a32044a against main. No blockers: the change is needed and correct. Approving.

Non-blocking: in the new ephemeralContainerNames helper, a malformed entry without a string name is appended as "". Skipping it would be tidier, but this is harmless in practice.

@matthyx
matthyx merged commit b85e4ba into kubescape:main Nov 10, 2026
5 checks passed
@matthyx matthyx moved this to To Archive in KS PRs tracking Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

2 participants