Skip to content

[BUG] Add Option to Disable Sorting of compositeRolesRefs in Keycloak Provider #462

@yoelpadronglez

Description

@yoelpadronglez

Metadata

  • keycloak version: 26.4.2
  • crossplane version: 2.1.0
  • keycloak provider version: 2.10.1

Reproducible example

When a list of compositeRolesRefs are specified in the role.role.keycloak.crossplane.io manifest, from version 2 this list is sorted according to role UUID value.

Given this example

apiVersion: role.keycloak.crossplane.io/v1alpha1
kind: Role
metadata:
  name: admin
spec:
  forProvider:
    clientIdSelector:
      matchLabels:
        upbound.io/name: springboot-app
    compositeRolesRefs:
      - name: read
        policy:
          resolution: Required
          resolve: Always
      - name: write
        policy:
          resolution: Required
          resolve: Always
    description: Springboot
    name: admin
    realmId: myrealm
  managementPolicies:
    - '*'

What do you expect?

I expect that the keycloak provider can populate the compositeRoles list with the ids but without sorting the existing compositeRoleRef list originally provided in the manifest.

What is the error?

Since the Keycloak operator is modifying the original manifest, I have an unsync issue with my deployment tool(ArgoCD). After running kubectl diff -f template.yaml, I detect that the operator changed the order of the compositeRoleRefs list.

     compositeRolesRefs:
-    - name: write
+    - name: read
       policy:
         resolution: Required
         resolve: Always
-    - name: write
+    - name: read
       policy:
         resolution: Required
         resolve: Always

Given that role IDs in Keycloak are UUID values, the compositeRoleRefs attribute has been very beneficial for us, as it allows using the same manifest across different environments where the UUIDs differ and they can be originally unknown. However, starting from v2, the resolver function also modifies the original manifest when the compositeRoleRefs attribute is specified.

Code Lines:

https://github.com/crossplane-contrib/provider-keycloak/blob/main/apis/cluster/role/v1alpha1/zz_generated.resolvers.go#L49

https://github.com/crossplane/crossplane-runtime/blob/main/pkg/reference/reference.go#L408

Although the Crossplane runtime's ResolveMultiple reference function sorts references by ID, could you add a mechanism to disable this at the Keycloak provider level? I guess this feature is useful for many Crossplane providers, but for Keycloak, from my point of view , it’s more of a drawback — role IDs are randomly generated by the Keycloak database, while names and labels are more meaningful and likely to be provided through Crossplane.

I have just tested the Role.role.keycloak.crossplane.io object, but I'm afraid that others which use references might be affected as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    blockedbugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions