Skip to content

fix(kubernetes): report the container at fault in KSV-0024, KSV-0119 and KSV-0120 - #654

Open
arpitjain099 wants to merge 2 commits into
aquasecurity:mainfrom
arpitjain099:fix/container-scoped-findings
Open

arpitjain099 wants to merge 2 commits into
aquasecurity:mainfrom
arpitjain099:fix/container-scoped-findings

Conversation

@arpitjain099

Copy link
Copy Markdown
Contributor

All three checks build a set of the offending containers, then iterate that set again inside the sprintf, so the message and the cause come from unrelated iterations.

KSV-0024 also tests container objects for membership in a set of container names, which never matches, so deny runs over every container in the pod. A pod with one container that sets a hostPort and one that does not gets two findings, both naming the first container, and one of them pointing at the container that is fine. In KSV-0119 the cause is a name rather than a container, so the findings carry no line numbers. KSV-0120 prints the container object itself in the message and reports one finding per pair of offending containers.

Each check now walks the offending containers once and passes the container to result.new, as the other container checks here do.

Checked with trivy 0.76.1 reading the checks from this tree: KSV-0024 drops from two findings to one, on the right lines, and KSV-0120 from four to two.

…and KSV-0120

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Arpit Jain <arpitjain099@gmail.com>

@nikpivkin nikpivkin 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.

The failHostPorts, failCapsNetRaw and failCapsSysModule defaults are not used anywhere. This PR already removes getContainersWitNohDisallowedHostPorts, so drop them too.

}

# Each offending container is reported once, named, and not as a dump of the whole
# container object.

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.

The comment describes the old bug, which will not exist after merge. Drop "and not as a dump of the whole container object".

…psSysModule defaults

These default definitions are no longer referenced after removing getContainersWitNohDisallowedHostPorts, and the SYS_MODULE test comment no longer needs to describe the old behaviour.

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
@arpitjain099

Copy link
Copy Markdown
Contributor Author

Thanks @nikpivkin. I dropped the three unused defaults (failHostPorts, failCapsNetRaw, failCapsSysModule) and reworded the SYS_MODULE test comment to drop the old-behaviour phrasing. fmt and the Rego tests pass. Please let me know if you want anything else changed.

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.

2 participants