I would like to automated the creation of a few Groovy rules. However, only the superuser is allowed to create such rules and I still couldn’t find a way to authenticate programmatically as a superuser (e.g., admin).
Until we have a robust groovy sandbox then indeed you need to be a superuser to create groovy rules (as well as have the write:rules client role).
A superuser is defined as a user in the master realm with the admin realm role; as this cannot be set with the users page in the manager UI you can go to the Keycloak admin UI /admin and you can manually add the admin realm role to your master realm service user as follows:
Login as admin
Select master realm
Select clients (service users are actually defined as clients with a service user account)
Select the client with the same name as your service user
Select Service Account Roles tab
Select the admin realm role and click add selected
Keycloak has a REST API (which is what our manager uses to manage users) so you could also use that programmatically to add the admin role; I don’t know your use case but I assume you want to do this for lots of users over time? Are you using the auto provisioning functionality over MQTT or are your service users being manually created?