I’m automating a Keycloak 26.1.2 installation and need to create a permanent admin user entirely via shell script and the Admin CLI (kcadm.sh/kc.sh), not via the web UI. My installation script does the following steps:
1. Bootstrap temporary admin
kc.sh bootstrap-admin user --username:env KC_BOOTSTRAP_ADMIN_USERNAME --password:env KC_BOOTSTRAP_ADMIN_PASSWORD --no‑prompt
(per https://www.keycloak.org/server/bootstrap-admin-recovery)
2. Start Keycloak with:
kc.sh start ...
3. Import custom realm.json:
kc.sh import --file realm.json --override=false ...
4. Create permanent “super‑admin” user—fully automated, not via the web UI—that:
- Has full realm‑admin rights in the imported custom realm
- Ideally also has full realm‑admin rights in the master realm
5. Cleanup: Delete the temporary bootstrap user once the permanent admin exists
I’m stuck on Step 4: how exactly do I grant this user the built‑in realm‑admin role (or equivalent full‑access roles) in both realms programmatically with kcadm.sh? All I’ve found online so far explains how to do it via the Admin Console UI, or only covers the temporary bootstrap user. I need the exact kcadm.sh add-roles (or other) invocation(s).
Question
How do I, in Keycloak 26.1.2, grant a non‑UI, script‑driven permanent admin user full administrative access to:
- The master realm
- A custom imported realm
using only kcadm.sh (and no interactive login)?
Edit
The question How do I create a permanent admin account in Keycloak 26.0.0? unfortunately doesn't answer my question, as it partly involves the UI, and I also want to give the permanent admin full permissions to both the master and custom realms. This isn't described there.