Skip to content

fix(evalhub): bind evalhub-events ClusterRole to server SA per tenant namespace - #857

Merged
ruivieira merged 2 commits into
trustyai-explainability:mainfrom
ruivieira:fix/eh-events-rbac
Aug 7, 2026
Merged

fix(evalhub): bind evalhub-events ClusterRole to server SA per tenant namespace#857
ruivieira merged 2 commits into
trustyai-explainability:mainfrom
ruivieira:fix/eh-events-rbac

Conversation

@ruivieira

@ruivieira ruivieira commented Aug 7, 2026

Copy link
Copy Markdown
Member

What and why

Kubernetes Events were not appearing for EvalHub evaluation lifecycle transitions (EvaluationRunning, EvaluationFailed) even though the trustyai.opendatahub.io/evaluation-phase label was being patched correctly.

Root cause: the evalhub-events ClusterRole (events create/patch) was bound via a static ClusterRoleBinding to the operator SA (controller-manager), not to the EvalHub server SA. The server's EventRecorder calls in NotifyJobPhaseTransition were silently rejected by the API server (the broadcaster is async so no error surfaced). Label patches worked because evalhub-jobs-writer (batch/jobs:patch) was correctly bound to the server SA per tenant namespace.

A secondary consequence: once the server sets evaluation-phase=Failed serverAlreadyHandledFailure()=true and skips its own event, leaving no event emitted from either path.

Fix: create a namespace-scoped RoleBinding for evalhub-events in each tenant namespace during reconcileTenantNamespaces, following the same pattern already used for evalhub-jobs-writer and evalhub-job-config. Because createJobRoleBinding stamps the standard job-resource labels, cleanupStaleTenantResources GCs the binding automatically when a namespace loses the tenant label (no additional cleanup code needed).

Also removes the stale static evalhub-events-binding ClusterRoleBinding: the operator SA already has events create/patch via its //+kubebuilder:rbac marker in evaluation_job_failure_reconciler.go, so that binding was redundant and bound to the wrong subject.

Relates to https://redhat.atlassian.net/browse/RHAISTRAT-1923

Type

  • feat
  • fix
  • docs
  • refactor / chore
  • test / ci

Testing

  • Tests added or updated
  • Tested manually

TestEvalHubReconciler_reconcileTenantNamespaces/should_provision_resources_in_labelled_tenant_namespace extended to assert the evalhub-events RoleBinding is created with the correct ClusterRole reference and subject (EvalHub server SA in the instance namespace).

Summary by CodeRabbit

  • Enhancements

    • Updated tenant namespace permissions so EvalHub can create and update lifecycle events within each tenant namespace.
    • Replaced broad event access with namespace-specific bindings, improving permission isolation and security.
  • Bug Fixes

    • Ensured event permissions are automatically established when tenant namespaces are reconciled.

… namespace

The evalhub-events ClusterRole (events create/patch) was bound only to
the operator SA via a static ClusterRoleBinding. The EvalHub server SA
had no events permission in tenant namespaces, so EventRecorder calls
from NotifyJobPhaseTransition were silently rejected by the API server.
Labels were patched correctly (jobs-writer covers batch/jobs:patch) but
no EvaluationRunning or EvaluationFailed events appeared.

Fix: create a namespace-scoped RoleBinding for evalhub-events per
tenant namespace in reconcileTenantNamespaces, following the same
pattern as the existing evalhub-jobs-writer and evalhub-job-config
bindings. Because createJobRoleBinding stamps the standard job-resource
labels, cleanupStaleTenantResources GCs the binding automatically when
a namespace loses the tenant label.

Remove the stale static evalhub-events-binding ClusterRoleBinding: the
operator SA already has events create/patch via its kubebuilder:rbac
marker in evaluation_job_failure_reconciler.go, making the ClusterRole
binding to controller-manager redundant. Remove both entries from the
OPA rbac.rego allowlist.

Fixes: https://redhat.atlassian.net/browse/RHAISTRAT-1923
@ruivieira ruivieira self-assigned this Aug 7, 2026
@ruivieira ruivieira added the kind/bug Something isn't working label Aug 7, 2026
@ruivieira ruivieira moved this to In Review in TrustyAI planning Aug 7, 2026
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@ruivieira, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 44 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: aa08ba1a-d6ab-4037-ac88-548c26622a1e

📥 Commits

Reviewing files that changed from the base of the PR and between 067959e and 2d0010e.

📒 Files selected for processing (1)
  • controllers/evalhub/service_accounts.go
📝 Walkthrough

Walkthrough

EvalHub replaces its static Events ClusterRoleBinding with tenant-specific RoleBindings. Tenant reconciliation binds the API ServiceAccount to the Events ClusterRole, removes the static resource and policy entries, and adds test coverage.

Changes

EvalHub Events RBAC

Layer / File(s) Summary
Tenant Events RoleBinding provisioning
controllers/evalhub/service_accounts.go, controllers/evalhub/tenant_namespaces.go, config/components/evalhub/kustomization.yaml, policy/rbac.rego
The controller defines the Events ClusterRole name and creates a tenant namespace RoleBinding for the EvalHub API ServiceAccount. The static binding is removed from Kustomize and the RBAC allowlist.
Tenant binding validation
controllers/evalhub/unit_test.go
The reconciliation test verifies the RoleBinding references the Events ClusterRole and the EvalHub ServiceAccount.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: julpayne, nbs-rh, ppadashe-psp

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes binding the EvalHub events ClusterRole to the server service account in each tenant namespace, which is the main change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ 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.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@controllers/evalhub/service_accounts.go`:
- Around line 270-273: The EvalHub Events ClusterRole name is inconsistent
between deployment manifests and the controller constant. Update the role
resource in evalhub_events_role.yaml and evalhubEventsClusterRoleName so both
resolve to the same name, preserving the RoleBinding lookup used by
reconcileTenantNamespaces.

In `@controllers/evalhub/tenant_namespaces.go`:
- Around line 108-119: Update reconcileServiceAccount to create an additional
namespace-scoped RoleBinding in instance.Namespace for
generateServiceAccountName(instance), using evalhubEventsClusterRoleName and the
existing events RoleBinding configuration. Preserve the current tenant-namespace
binding and ensure failures follow the method’s existing error-handling pattern.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 1fb763c6-d072-47d5-9573-d12e0e3b154f

📥 Commits

Reviewing files that changed from the base of the PR and between 1710b2b and 067959e.

📒 Files selected for processing (6)
  • config/components/evalhub/kustomization.yaml
  • config/components/evalhub/rbac/evalhub_events_binding.yaml
  • controllers/evalhub/service_accounts.go
  • controllers/evalhub/tenant_namespaces.go
  • controllers/evalhub/unit_test.go
  • policy/rbac.rego
💤 Files with no reviewable changes (3)
  • config/components/evalhub/rbac/evalhub_events_binding.yaml
  • config/components/evalhub/kustomization.yaml
  • policy/rbac.rego

Comment thread controllers/evalhub/service_accounts.go
Comment thread controllers/evalhub/tenant_namespaces.go
…le-tenant mode

resolveNamespace falls back to the server's in-cluster namespace
(instance.Namespace) when no explicit tenant is set, covering
single-tenant deployments where reconcileTenantNamespaces is skipped.
Without a RoleBinding there, EventRecorder calls from
NotifyJobPhaseTransition are silently rejected in that mode.

Add createEventsRoleBinding and call it from createServiceAccount,
following the same pattern as createJobsWriterRoleBinding,
createJobConfigRoleBinding, and createHardwareProfilesReaderRoleBinding.
Per-tenant bindings in reconcileTenantNamespaces are unchanged.

Relates to: https://redhat.atlassian.net/browse/RHAISTRAT-1923

@scheruku-rh scheruku-rh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@openshift-ci

openshift-ci Bot commented Aug 7, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: m-misiura, scheruku-rh

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ruivieira
ruivieira merged commit ddc0b8f into trustyai-explainability:main Aug 7, 2026
12 of 13 checks passed
@ruivieira
ruivieira deleted the fix/eh-events-rbac branch August 7, 2026 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working lgtm

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

3 participants