Skip to content

fix(clusterroles): don't ParseBool aggregation label values#609

Merged
yonahd merged 2 commits into
yonahd:mainfrom
RaphaelKorPro:fix/clusterrole-aggregation-nonbool-label
Jun 29, 2026
Merged

fix(clusterroles): don't ParseBool aggregation label values#609
yonahd merged 2 commits into
yonahd:mainfrom
RaphaelKorPro:fix/clusterrole-aggregation-nonbool-label

Conversation

@RaphaelKorPro

Copy link
Copy Markdown
Collaborator

Problem

retrieveUsedClusterRoles aborts the entire ClusterRole scan on any cluster running a controller that ships aggregated ClusterRoles with non-boolean aggregation label values — notably Emissary / Ambassador:

Failed to get clusterRoles: couldn't convert string to bool strconv.ParseBool: parsing "emissary-emissary-ingress-agent": invalid syntax

In pkg/kor/clusterroles.go, when a ClusterRole's label matches an aggregation selector, the code did:

usedClusterRoles[clusterRole.Name], err = strconv.ParseBool(value)
if err != nil {
    return nil, fmt.Errorf("couldn't convert string to bool %v", err)
}

But value is the aggregation label value — an arbitrary string (e.g. emissary-emissary-ingress-agent), not a boolean. ParseBool errors and the whole non-namespaced ClusterRole scan bails out. The existing test only happened to use "true" as the value, so it never caught this.

Fix

A ClusterRole whose label matches an aggregation selector is pulled into the aggregated (used) ClusterRole, so it is itself used — set it to true rather than parsing the value. strconv is no longer needed.

Test

Adds TestRetrieveUsedClusterRoles_NonBooleanAggregationLabel, which reproduces the Emissary case (a non-boolean aggregation label value). It fails before the fix with the exact error above and passes after; existing clusterroles tests are unchanged.

retrieveUsedClusterRoles marked an aggregated ClusterRole as used by
parsing the aggregation label *value* as a boolean. Aggregation label
values are arbitrary strings (e.g. Emissary/Ambassador ship ClusterRoles
labelled `rbac.authorization.k8s.io/aggregate-to-...: emissary-emissary-ingress-agent`),
so strconv.ParseBool returned an error and aborted the entire ClusterRole
scan with "couldn't convert string to bool" on any cluster running such
controllers.

A ClusterRole whose label matches an aggregation selector is pulled into
the aggregated (used) role, so it is simply used — set it to true instead
of parsing the value. Adds a regression test with a non-boolean
aggregation label.
@codecov-commenter

codecov-commenter commented Jun 25, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46.59%. Comparing base (dc72918) to head (85530a5).
⚠️ Report is 1 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #609      +/-   ##
==========================================
+ Coverage   46.57%   46.59%   +0.02%     
==========================================
  Files          69       69              
  Lines        3957     3955       -2     
==========================================
  Hits         1843     1843              
+ Misses       1806     1805       -1     
+ Partials      308      307       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@yonahd

yonahd commented Jun 25, 2026

Copy link
Copy Markdown
Owner

@RaphaelKorPro Can you fix this in
ClusterRoleBinding and RoleBinding as well?

Comment thread pkg/kor/clusterroles.go Outdated
if err != nil {
return nil, fmt.Errorf("couldn't convert string to bool %v", err)
}
// A ClusterRole whose label matches an aggregation selector is

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

No need for this huge comment

@RaphaelKorPro

Copy link
Copy Markdown
Collaborator Author

Done — trimmed the comment to a single line.

On ClusterRoleBinding/RoleBinding: I don't think there's an equivalent change to make here. This bug was specific to the aggregation path — retrieveUsedClusterRoles calls strconv.ParseBool on an aggregation label value. AggregationRule only exists on ClusterRole (Kubernetes only aggregates ClusterRoles, not Roles or any *Binding), and clusterrolebindings.go / rolebindings.go / roles.go have no ParseBool and no label-value parsing — they match by name / the kor/used == "false" string check, neither of which can hit this error.

Happy to add something if you had a specific case in mind — let me know.

@yonahd yonahd merged commit 29f4cfd into yonahd:main Jun 29, 2026
1 check 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.

retrieveUsedClusterRoles is erroring, causing false-positive ClusterRole, ClusterRoleBinding and RoleBinding reports

4 participants