Skip to content

ACM-37273 - adding clusterrole for hcp proxy - #397

Open
kurwang wants to merge 1 commit into
stolostron:mainfrom
kurwang:ACM-37273
Open

ACM-37273 - adding clusterrole for hcp proxy#397
kurwang wants to merge 1 commit into
stolostron:mainfrom
kurwang:ACM-37273

Conversation

@kurwang

@kurwang kurwang commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

📝 Summary

Ticket Summary (Title):
As a hub admin, I can grant a user access to specific hosting clusters for hcp from-hub using MulticlusterRoleAssignment

Ticket Link:
https://issues.redhat.com/browse/ACM-37273

Type of Change:

  • 🐞 Bug Fix
  • 🧹 Chore
  • ✨ Feature
  • 🔧 Refactor
  • 💸 Tech Debt
  • 🧪 Test-related
  • 📄 Docs

✅ Checklist

General

  • PR title follows the convention (e.g. ACM-12340 Fix bug with...)
  • Code builds and runs locally without errors
  • No test logs/printing output, commented-out code, or unnecessary files
  • All commits are meaningful and well-labeled

If Feature

  • All acceptance criteria met
  • Unit test coverage added or updated
  • Relevant documentation or comments included

If Bugfix

  • Root cause and fix summary are documented in the ticket (for future reference / errata)
  • Fix tested thoroughly and resolves the issue
  • Test(s) added to prevent regression

🗒️ Notes for Reviewers

Adds HCP hosting cluster RBAC support to the Helm chart:

  • AddOnTemplate: Two new ClusterRoles deployed to managed clusters via the addon framework:
    • acm-hcp-hosting:view — read-only access to HyperShift resources (hostedclusters, nodepools, status subresources)
    • acm-hcp-hosting:admin — full CRUD on HyperShift resources including secrets/configmaps for hcp from-hub create
  • Policy: policy-hcp-clusterroles ensures pre-existing HyperShift ClusterRoles (hypershift-admin, hypershift-reader) get discovery labels, following the same pattern as policy-virt-clusterroles
  • PlacementBinding: Updated to include the new HCP policy

Once these ClusterRoles are deployed to hosting clusters, hub admins can create a MulticlusterRoleAssignment referencing acm-hcp-hosting:admin to grant users access to specific hosting clusters for hcp from-hub operations.

Summary by CodeRabbit

  • New Features
    • Added read-only and administrative access roles for managing hosted control planes, clusters, node pools, and related resources.
    • Added policy-based enforcement for HyperShift administrative and reader permissions.
    • Enabled automatic application of the new access policy through placement bindings.

Signed-off-by: kurwang <kurwang@redhat.com>
@openshift-ci

openshift-ci Bot commented Aug 6, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kurwang

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

The pull request process is described 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

@openshift-ci openshift-ci Bot added the approved label Aug 6, 2026
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The chart adds view and admin ACM ClusterRoles for HyperShift hosted control plane resources. It also adds a policy that labels existing HyperShift ClusterRoles and includes that policy in the virtual RBAC placement binding.

Changes

HyperShift HCP RBAC

Layer / File(s) Summary
HCP hosting roles
charts/fine-grained-rbac/templates/acm-roles-addontemplate.yaml
Adds acm-hcp-hosting:view with read-only permissions and acm-hcp-hosting:admin with lifecycle permissions for HyperShift resources and related core resources.
ClusterRole policy wiring
charts/fine-grained-rbac/templates/policy-hcp-clusterroles-policy.yaml, charts/fine-grained-rbac/templates/binding-policy-virt-rbac-placementbinding.yaml
Adds conditional labeling and enforcement for existing hypershift-admin and hypershift-reader ClusterRoles, then attaches the policy to the placement binding.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title identifies the HCP proxy ClusterRole change and includes the Jira ticket, but it does not mention the related policy and placement binding updates.
Description check ✅ Passed The description includes the ticket, change type, checklist, implementation details, and reviewer notes; feature test and acceptance checkboxes remain unchecked.
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.

@kurwang

kurwang commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator Author

/hold
need to test locally once the env has the needed tests
also need to fix fast forwarding branch day

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
charts/fine-grained-rbac/templates/policy-hcp-clusterroles-policy.yaml (1)

4-47: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add an operational description and template comments.

Line 7 sets the policy description to an empty value. Lines 24-47 do not explain why the policy exposes these ClusterRoles for discovery. Add a meaningful description and comments for the label-enforcement rules.

As per coding guidelines, “Add meaningful labels and annotations to Kubernetes resources” and “Add comments explaining permission purposes in RBAC configurations.”

🤖 Prompt for 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.

In `@charts/fine-grained-rbac/templates/policy-hcp-clusterroles-policy.yaml`
around lines 4 - 47, Update the policy annotation description from empty to a
meaningful operational explanation of the HCP ClusterRole discovery policy, and
add template comments near the hypershift-admin and hypershift-reader
label-enforcement rules explaining their discovery purpose. Keep the existing
lookup and enforcement behavior unchanged.

Source: Coding guidelines

charts/fine-grained-rbac/templates/acm-roles-addontemplate.yaml (1)

575-685: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Document the new ClusterRoles and permission rules.

Lines 575-685 add labels but no meaningful annotations. The rules also have no comments that explain their permission purposes. Add role-purpose annotations and concise comments for each RBAC rule.

As per coding guidelines, “Add meaningful labels and annotations to Kubernetes resources” and “Add comments explaining permission purposes in RBAC configurations.”

🤖 Prompt for 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.

In `@charts/fine-grained-rbac/templates/acm-roles-addontemplate.yaml` around lines
575 - 685, Add meaningful purpose annotations to the ClusterRoles
acm-hcp-hosting:view and acm-hcp-hosting:admin, and add concise comments before
each rules entry explaining the permissions granted for its API group and
resources. Keep the existing labels, resources, verbs, and role behavior
unchanged.

Source: Coding guidelines

🤖 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 `@charts/fine-grained-rbac/templates/acm-roles-addontemplate.yaml`:
- Around line 646-659: Update the acm-hcp-hosting:admin RBAC definition so
Secret, ConfigMap, and Service permissions are granted through namespace-scoped
RoleBinding objects in the intended HCP namespaces. Split these
namespace-resource rules out of the ClusterRole and configure the related
MulticlusterRoleAssignment with explicit targetNamespaces, preventing creation
of a cluster-wide ClusterRoleBinding.

---

Nitpick comments:
In `@charts/fine-grained-rbac/templates/acm-roles-addontemplate.yaml`:
- Around line 575-685: Add meaningful purpose annotations to the ClusterRoles
acm-hcp-hosting:view and acm-hcp-hosting:admin, and add concise comments before
each rules entry explaining the permissions granted for its API group and
resources. Keep the existing labels, resources, verbs, and role behavior
unchanged.

In `@charts/fine-grained-rbac/templates/policy-hcp-clusterroles-policy.yaml`:
- Around line 4-47: Update the policy annotation description from empty to a
meaningful operational explanation of the HCP ClusterRole discovery policy, and
add template comments near the hypershift-admin and hypershift-reader
label-enforcement rules explaining their discovery purpose. Keep the existing
lookup and enforcement behavior unchanged.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d129cc68-3c26-4bb2-9773-0d57ac40f2b7

📥 Commits

Reviewing files that changed from the base of the PR and between 5906845 and 38035aa.

📒 Files selected for processing (3)
  • charts/fine-grained-rbac/templates/acm-roles-addontemplate.yaml
  • charts/fine-grained-rbac/templates/binding-policy-virt-rbac-placementbinding.yaml
  • charts/fine-grained-rbac/templates/policy-hcp-clusterroles-policy.yaml

Comment on lines +646 to +659
- apiGroups:
- ""
resources:
- secrets
- configmaps
- services
verbs:
- get
- list
- watch
- create
- update
- patch
- delete

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the assignment implementation and manifests for binding scope.
rg -n -C 8 \
  -g '*.go' -g '*.{yaml,yml}' \
  'MulticlusterRoleAssignment|acm-hcp-hosting:admin|kind:\s*(ClusterRoleBinding|RoleBinding)|namespace' .

Repository: stolostron/multicluster-role-assignment

Length of output: 50396


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Candidate files:"
fd -a 'acm-roles-addontemplate.yaml|multiclusterroleassignment_controller.go|.*_types.*\.go|clusterpermission.*' . | sed 's#^\./##' | head -200

echo
echo "Relevant chart section (acm-roles-addontemplate.yaml):"
sed -n '620,670p' charts/fine-grained-rbac/templates/acm-roles-addontemplate.yaml | cat -n

echo
echo "Definitions/usages for acm-hcp-hosting:admin:"
rg -n -C 5 'acm-hcp-hosting:admin|secrets|configmaps|services' charts/fine-grained-rbac templates internal manifests 2>/dev/null | head -300

echo
echo "Binding-related controller code locations:"
rg -n -C 4 'generateBindingName|createCPFor|apply.*ClusterPermission|ClusterRoleBinding|RoleBinding|TargetNamespace' internal/controller -g '*.go' | head -500

Repository: stolostron/multicluster-role-assignment

Length of output: 12518


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Controller outline around binding generation/configuration:"
ast-grep outline internal/controller/multiclusterroleassignment_controller.go --view compact | sed -n '1,220p'

echo
echo "Binding generation and applied binding methods:"
rg -n -C 6 'func .*generateBindingName|func .*apply.*Binding|func .*createCP|func .*ensureCluster|func .*apply.*Cluster|ClusterRoleBinding|RoleBinding|TargetNamespaces|RoleBindingSpec|kind:' internal/controller/multiclusterroleassignment_controller.go | sed -n '1,260p'

echo
echo "API type for TargetNamespaces and RoleAssignments:"
sed -n '1,220p' api/v1beta1/multiclusterroleassignment_types.go | cat -n

echo
echo "Template context for target namespaces / placement binding in chart:"
rg -n -C 6 'RoleAssignments|TargetNames|ClusterSelection|Placements|multiclusterRole|{{' charts/fine-grained-rbac/templates/acm-roles-addontemplate.yaml | sed -n '520,760p'

Repository: stolostron/multicluster-role-assignment

Length of output: 388


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Controller outline around binding generation/configuration:"
ast-grep outline internal/controller/multiclusterroleassignment_controller.go --view signatures | sed -n '1,220p'

echo
echo "Binding generation and applied binding methods:"
rg -n -C 6 'func .*generateBindingName|func .*apply.*Binding|func .*createCP|func .*ensureCluster|func .*apply.*Cluster|ClusterRoleBinding|RoleBoundary|RoleBinding|TargetNamespaces|RoleBindingSpec|kind:' internal/controller/multiclusterroleassignment_controller.go | sed -n '1,340p'

echo
echo "API type for TargetNamespaces and RoleAssignments:"
sed -n '1,220p' api/v1beta1/multiclusterroleassignment_types.go | cat -n

echo
echo "Template context for target namespaces / placement binding in chart:"
rg -n -C 6 'RoleAssignments|TargetNames|ClusterSelection|Placements|multiclusterRole|{{' charts/fine-grained-rbac/templates/acm-roles-addontemplate.yaml | sed -n '520,760p'

Repository: stolostron/multicluster-role-assignment

Length of output: 26277


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Template context for target namespaces / placement binding in chart:"
rg -n -C 6 'RoleAssignments|TargetNamesages|ClusterSelection|Placements|multiclusterRole|\\{\\{' charts/fine-grained-rbac/templates/acm-roles-addontemplate.yaml | sed -n '500,770p'

echo
echo "ClusterPermission type files:"
fd -a 'clusterpermission.*|.*_types.*\.go' internal api test charts | sed 's#^\./##' | sort

echo
echo "ClusterPermission type references:"
rg -n -C 4 'type ClusterPermission|ClusterPermissionSpec|ClusterRoleBindings|RoleBindings|roleBindings|clusterRoleBindings' api test internal -g '*.go' -g '*.yaml' | sed -n '1,260p'

Repository: stolostron/multicluster-role-assignment

Length of output: 503


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Template context for target namespaces / placement binding in chart:"
rg -n -C 6 'RoleAssignments|TargetNamesages|ClusterSelection|Placements|multiclusterRole' charts/fine-grained-rbac/templates/acm-roles-addontemplate.yaml | sed -n '500,770p'
echo "--- chart file around 50 lines ---"
cat -n charts/fine-grained-rbac/templates/acm-roles-addontemplate.yaml | sed -n '480,535p'

echo
echo "ClusterPermission type references:"
rg -n -C 5 'type ClusterPermission|type .*RoleBinding|ClusterRoleBindings|RoleBindings|roleBindings|clusterRoleBindings' api test internal -g '*.go' -g '*.yaml' | sed -n '1,260p'

Repository: stolostron/multicluster-role-assignment

Length of output: 246


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Chart file length and relevant region:"
wc -l charts/fine-grained-rbac/templates/acm-roles-addontemplate.yaml
cat -n charts/fine-grained-rbac/templates/acm-roles-addontemplate.yaml | sed -n '480,680p'

echo
echo "ClusterPermission references:"
rg -n -C 5 'type ClusterPermission|type .*RoleBinding|ClusterRoleBindings|RoleBindings|roleBindings|clusterRoleBindings' api test internal charts -g '*.go' -g '*.yaml' | sed -n '1,260p'

Repository: stolostron/multicluster-role-assignment

Length of output: 33184


Require namespace-scoped bindings for the HCP admin role.

MulticlusterRoleAssignment creates a ClusterRoleBinding whenever targetNamespaces is omitted, so this acm-hcp-hosting:admin ClusterRole with namespace resources allows the assigned user to read/create/unlimited Secret, ConfigMap, and Service objects cluster-wide. Use HCP namespace RoleBinding objects, split this ClusterRole into namespace-scoped rules, and enforce the intended namespace boundary.

🤖 Prompt for 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.

In `@charts/fine-grained-rbac/templates/acm-roles-addontemplate.yaml` around lines
646 - 659, Update the acm-hcp-hosting:admin RBAC definition so Secret,
ConfigMap, and Service permissions are granted through namespace-scoped
RoleBinding objects in the intended HCP namespaces. Split these
namespace-resource rules out of the ClusterRole and configure the related
MulticlusterRoleAssignment with explicit targetNamespaces, preventing creation
of a cluster-wide ClusterRoleBinding.

Source: Coding guidelines

@sonarqubecloud

sonarqubecloud Bot commented Aug 6, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant