Skip to content

Conversation

@arxhive
Copy link
Contributor

@arxhive arxhive commented Jan 5, 2026

Summary

This PR fixes the remaining issue by ensuring that when falling back to fleet scope checks, the v2 implementation generates fleet-specific actions using the fleetMembers cluster type, consistent with how v1 handles this scenario.

The Problem

In the v2 checkAccessV2 function, actions were computed once at the beginning using a.clusterType:

actions, err := getDataActionsV2(ctx, request, a.clusterType, ...)

These same actions were then reused for fleet scope checks, which is incorrect. For a fleet member cluster with clusterType = managedClusters, this would send:

  • Microsoft.ContainerService/managedClusters/pods/read

Instead of the correct fleet member action:

  • Microsoft.ContainerService/fleets/members/pods/read

The Fix

Generate fleet-specific actions using fleetMembers cluster type before performing fleet scope checks:

fleetActions, err := getDataActionsV2(ctx, request, fleetMembers, ...)

This ensures roles like "Azure Kubernetes Fleet Manager RBAC Cluster Admin for Member Clusters" can properly authorize requests through the v2 API.

Changes

  • Generate fleetMembers actions for fleet scope and fleet managed namespace checks in v2
  • Add test TestCheckAccessV2_FleetActionsUseCorrectClusterType to verify correct actions are used

PR kubeguard#432 fixed the namespace scope order for fleet member clusters but
still used the original cluster type actions (e.g., managedClusters)
when checking fleet scope authorization in the v2 API path.

This fix ensures that when falling back to fleet scope checks, the v2
implementation generates fleet-specific actions using the fleetMembers
cluster type, consistent with how v1 handles this scenario.

For example, when a managedCluster fleet member needs to check fleet
authorization, the action should be:
  Microsoft.ContainerService/fleets/members/pods/read
instead of:
  Microsoft.ContainerService/managedClusters/pods/read

This enables roles like "Azure Kubernetes Fleet Manager RBAC Cluster
Admin for Member Clusters" to properly authorize requests to fleet
member clusters through the v2 API.

Also adds a test to verify the correct actions are used for each
authorization check in the fallback chain.

Signed-off-by: Artem Kolomeetc <akolomeetc@microsoft.com>
@arxhive arxhive requested a review from a team as a code owner January 5, 2026 21:59
Signed-off-by: Artem Kolomeetc <akolomeetc@microsoft.com>
Copy link
Contributor

@weinong weinong left a comment

Choose a reason for hiding this comment

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

LGTM

@weinong weinong merged commit babe83e into kubeguard:master Jan 6, 2026
3 checks 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.

3 participants