Initial role creation via keycloak

I have setup keycloak v20.0.2 using corteza 2022.9.5. It’s working for logging in etc.
What is not working is assignment of initial role on account signup.

What I have done is create a workflow that assigns an initial role after signup (which works), but was wondering if the initial role could come from either the keycloak roles or groups. I have used the role scope in the scopes setup, but the initial role is not assigned.

Is this a functionality or better to stay with the workflow approach?

Corteza won’t pull roles from the auth provider, so what I’d suggest is either

  • Manually create roles, set forced roles in the auth client settings
  • Utilise workflows to pull roles from keycloak API (if even an option) and then create/assign roles as needed

Hi @mperestrelo
Can you please share how you made the workflow that assigns role on user creation, having a hard time here

I can only add one image at a time
image

TYSM @Toocky
Let me try it out, it was the role membership function I was stuck at

Ok, the issue seems to be more than just workflow issue. I am not able to add a role to any user manually either.

Store error: pq: null value in column “rel_user” of relation “role_members” violates not-null constraint

cc @tjerman

Did you check this in the changelog?
https://docs.cortezaproject.org/corteza-docs/2024.9/changelog/index.html#2024_09_06-important

https://docs.cortezaproject.org/corteza-docs/2024.9/devops-guide/upgrade/index.html#_upgrading_to_2024_9_6

1 Like

Thanks @jfortun, the changes suggested in the upgrade guide worked but I am now facing the same trace not available error (as pointed out here "Trace not available" pop up in workflow - #6 by ajaymatharoo) in this workflow where in test mode the role is getting assigned to a user but in live, nothing gets assigned.

{
  "workflows": [
    {
      "handle": "",
      "enabled": true,
      "meta": {
        "name": "System User: After Create - Assign Base Role",
        "description": "For Democracy Distributed",
        "visual": {}
      },
      "keepSessions": 0,
      "steps": [
        {
          "stepID": "3",
          "kind": "function",
          "ref": "rolesAddMember",
          "arguments": [
            {
              "target": "role",
              "value": "dd_baseRole",
              "type": "Handle"
            },
            {
              "target": "user",
              "expr": "user",
              "type": "User"
            }
          ],
          "results": [],
          "meta": {
            "name": "",
            "description": "",
            "visual": {
              "defaultName": false,
              "id": "3",
              "parent": "1",
              "value": "Role membership add to dd_baseRole",
              "xywh": [
                2360,
                1864,
                200,
                80
              ]
            }
          }
        },
        {
          "stepID": "15",
          "kind": "termination",
          "ref": "",
          "arguments": null,
          "results": [],
          "meta": {
            "name": "",
            "description": "",
            "visual": {
              "defaultName": true,
              "id": "15",
              "parent": "1",
              "value": "Terminate workflow execution",
              "xywh": [
                2360,
                2048,
                200,
                80
              ]
            }
          }
        }
      ],
      "paths": [
        {
          "parentID": "3",
          "childID": "15",
          "meta": {
            "name": "",
            "description": "",
            "visual": {
              "id": "16",
              "parent": "1",
              "points": [],
              "style": "exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;",
              "value": null
            }
          }
        }
      ],
      "triggers": [
        {
          "resourceType": "system:user",
          "eventType": "afterCreate",
          "constraints": [],
          "enabled": true,
          "stepID": "3",
          "meta": {
            "description": "",
            "visual": {
              "defaultName": true,
              "edges": [
                {
                  "childID": "3",
                  "meta": {
                    "description": "",
                    "label": "",
                    "visual": {
                      "id": "14",
                      "parent": "1",
                      "points": [],
                      "style": "exitX=1;exitY=0.5;exitDx=0;exitDy=0;entryX=0;entryY=0.5;entryDx=0;entryDy=0;",
                      "value": null
                    }
                  },
                  "parentID": "4"
                }
              ],
              "id": "4",
              "parent": "1",
              "value": "System - User - After Create",
              "xywh": [
                2008,
                1864,
                200,
                80
              ]
            }
          }
        }
      ]
    }
  ]
}