RADIUS with FreeRADIUS (incl. UCS)
Documentation
On this page
Plan feature RADIUS/VPN, from the Team plan on.
For VPN and Wi-Fi sign-ins you connect an existing FreeRADIUS 3.x to Okivo. FreeRADIUS checks the password as before (MSCHAPv2, PAP, LDAP …) and then requests a push from the Okivo plugin in your Keycloak. Only when the user approves in the app is the sign-in accepted.
RADIUS client ─(MSCHAPv2/PAP/…)→ FreeRADIUS ─(password ok)→ post-auth (rlm_rest) → Keycloak with Okivo plugin: push to the app → approve/block → HTTP 200/403 → FreeRADIUS: Access-Accept / Access-Reject
Fail-closed: every case except “approved” – blocked, timed out, no device, Keycloak unreachable – leads to Access-Reject.
For IPsec on a pfSense there is a simpler way without a separate RADIUS server: pfSense: IPsec VPN.
Requirements
Keycloak
- The Okivo plugin is installed and the realm is set up (Install the Keycloak plugin). The plan includes RADIUS/VPN.
- The users have set up a device in the Okivo app. Without a device every RADIUS sign-in is rejected. Invite them or let them sign in once in the browser.
- The username FreeRADIUS sees (RADIUS attribute
User-Name) is the same as in Keycloak. - On UCS: the users also exist in Keycloak, for example via an LDAP user federation. FreeRADIUS keeps checking the password; Keycloak only provides the push.
FreeRADIUS
- FreeRADIUS 3.x with the module
rlm_rest(part of the standard installation). - FreeRADIUS reaches Keycloak via HTTPS (port 443) with a valid certificate.
Network
| From | To | Port | Purpose |
|---|---|---|---|
| VPN gateway / Wi-Fi controller (NAS) | FreeRADIUS | 1812/UDP | RADIUS sign-in |
| FreeRADIUS | Keycloak | 443/TCP | Request a push (radius-authorize) |
| Keycloak | gateway.okivo.app |
443/TCP | Send the push |
Increase the timeout on the VPN gateway. Many gateways abort RADIUS requests after 5 to 10 seconds. Keycloak waits up to 60 seconds for the approval. Set more than 60 seconds on the gateway or NAS (e.g. 70), otherwise the request expires before the user can approve.
Inbound API key
FreeRADIUS calls the endpoint POST /realms/<realm>/push-mfa/radius-authorize in your Keycloak and
identifies itself with an API key (Authorization: Bearer …). This key can only trigger pushes for users
of this realm – it can't read or change settings and has no admin rights. So FreeRADIUS never needs a
Keycloak admin account.
Which key applies:
- Recommended: a separate key in the realm attribute
push-mfa.inboundApiKey. Like the tenant API key, it can reference the Keycloak vault, for example${vault.radius-inbound}. - Without this attribute the Tenant API Key from the portal applies. That's simpler, but it also hands the key for the push service to the RADIUS server.
Create and set a separate key:
# generate a key openssl rand -hex 32 # store it as a vault file (file vault, realm “acme”) echo -n '<key>' > /opt/keycloak/vault/acme_radius-inbound chmod 600 /opt/keycloak/vault/acme_radius-inbound
You set the realm attribute through the Keycloak admin API, with the token of an administrator of this realm (a master admin is not needed):
KC=https://id.example.com
H="Authorization: Bearer <admin-token>"
curl -s -H "$H" "$KC/admin/realms/acme" \
| jq '.attributes += {"push-mfa.inboundApiKey":"${vault.radius-inbound}"}' \
| curl -s -X PUT -H "$H" -H "Content-Type: application/json" -d @- "$KC/admin/realms/acme"
If you need a token without a master admin for this, temporarily create a client with Service accounts
roles in the realm, give it the role manage-realm from realm-management and get the token from the
token endpoint of this realm (grant_type=client_credentials). After the setup, disable or delete the
client again; its secret doesn't belong on the RADIUS server.
Installation
You get the installation package for FreeRADIUS from us together with the plugin. It contains install.sh,
uninstall.sh and, for UCS, the scripts under ucs/.
Any FreeRADIUS
Copy the package to the RADIUS server, then as root:
sudo sh install.sh \ --keycloak-url https://id.example.com \ --realm acme \ --api-key <INBOUND_API_KEY>
| Parameter | Required | Meaning |
|---|---|---|
--keycloak-url |
yes | Base address of Keycloak (with https:// the installer creates a tls block) |
--realm |
yes | Keycloak realm |
--api-key |
yes | Inbound API key (see above) |
--site |
no | Virtual server in sites-enabled (default default) |
--config-dir |
no | FreeRADIUS directory (detected: /etc/freeradius/3.0 or /etc/raddb) |
--no-reload |
no | Only write files, don't reload the service |
The installer asks for missing required values. It checks the configuration with freeradius -XC and rolls
everything back automatically on an error.
UCS (Univention Corporate Server)
UCS manages the FreeRADIUS configuration through UCR; direct changes would be overwritten by ucr commit or
updates. The UCS installer therefore creates module and policy as separate files and adds the call to the
UCR template of the virtual server – that way it survives updates.
sudo sh ucs/install-ucs.sh \ --keycloak-url https://id.example.com \ --realm acme \ --api-key <INBOUND_API_KEY>
The values are also stored in UCR (okivo/pushmfa/url, okivo/pushmfa/realm, okivo/pushmfa/apikey,
okivo/pushmfa/enable). If you call the installer without parameters, it takes the values from there.
UCS FreeRADIUS checks the password against Samba/LDAP as usual; Okivo is then added as the second factor.
What the installer changes
| File | Purpose |
|---|---|
<cfg>/mods-enabled/okivo_push |
rlm_rest instance for calling Keycloak, with timeout = 65 |
<cfg>/policy.d/okivo_push_mfa |
Sets the API key, calls okivo_push and rejects if the response isn't “approved” |
<cfg>/sites-enabled/<site> |
In the post-auth block a call to okivo_push_mfa, between the markers # >>> okivo-push-mfa >>> |
<cfg>/okivo-push-mfa.bak/ |
Backup of the original site |
<cfg> is the FreeRADIUS directory. Module and policy get permissions 640, because the API key is stored
in them in plain text.
Why timeout = 65: without a setting, rlm_rest aborts after 4 seconds. Keycloak waits up to 60 seconds
for the approval, so FreeRADIUS has to wait longer – and the gateway (NAS) longer still.
Reconfigure, disable, uninstall
Change address, realm or key: run the installer again with the new values. It overwrites module and policy, leaves the entry in the site in place, checks the configuration and reloads.
Different virtual server: --site <name> when installing. If you switch the site, first remove the old
one with uninstall.sh --site <old>.
Disable temporarily: comment out the call okivo_push_mfa in the site – or uninstall and reinstall when
needed.
Uninstall:
sudo sh uninstall.sh # any FreeRADIUS (optional --site <name>) sudo sh ucs/uninstall-ucs.sh # UCS: removes files, markers and UCR variables
After updates: if an update of FreeRADIUS or univention-radius replaces the site file or its template,
run the installer again. It recognises its own entries and creates nothing twice.
Testing
End to end via RADIUS:
radtest -t mschap <user> <password> <freeradius-host> 0 <shared-secret> # approve the push in the app -> Access-Accept # block / timed out / no device -> Access-Reject
radtest only waits a few seconds for a response. If you need longer to approve, test with radclient;
there -t 70 sets the time limit to 70 seconds.
Check Keycloak directly (without FreeRADIUS):
curl -i -X POST https://id.example.com/realms/acme/push-mfa/radius-authorize \
-H "Authorization: Bearer <INBOUND_API_KEY>" -H "Content-Type: application/json" \
-d '{"username":"<user>"}'
| Response | Meaning |
|---|---|
200 {"result":"approved"} |
Approved in the app |
403 {"result":"denied"} |
Blocked in the app |
403 {"result":"timeout"} or "expired" |
Not approved in time |
403 {"result":"no_device"} |
The user hasn't set up a device |
403 {"result":"unknown_user"} |
User unknown or disabled in Keycloak |
403 {"result":"misconfigured"} |
Credentials (Relay Base URL, Tenant ID, Tenant API Key) incomplete in the realm |
403 {"error":"feature_not_licensed"} |
RADIUS/VPN is not included in the plan |
401 |
API key wrong or missing |
Debug: stop the service and start freeradius -X in the foreground. You see the call, the HTTP status and
the decision in post-auth in plain text.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
| Reject, Keycloak log shows no push | User not found in the realm, or User-Name contains @domain |
Does the user exist in Keycloak? Right realm? Adjust the name if needed (below). |
403 no_device |
The user hasn't set up a device | Set it up in the Okivo app (deliberately fail-closed). |
403 feature_not_licensed |
Plan without RADIUS/VPN | Change the plan in the portal. |
401 |
API key wrong or missing | Compare push-mfa.inboundApiKey or the tenant API key with --api-key. |
| Reject after exactly ~4 s although the push arrives | timeout in the rest module too small |
timeout = 65 in mods-enabled/okivo_push (set by the installer). |
| Abort after 5–10 s at the gateway | Timeout on the NAS too small | Set more than 60 s on the gateway. |
freeradius -XC: “Duplicate virtual server default” |
A backup copy sits in sites-enabled/ |
Remove stray *.bak there; the installer backs up to okivo-push-mfa.bak/. |
TLS / certificate errors with https:// |
CA not trusted | Set ca_file or ca_path in the tls block of mods-enabled/okivo_push, or use a publicly valid certificate. |
| The push never reaches the device | Delivery | Test a sign-in in the browser; check the credentials in Keycloak and the connection to gateway.okivo.app. |
Adjust usernames: if the gateway sends user@domain but Keycloak only knows user, shorten the name in
the authorize block of the site, before post-auth:
if (&User-Name =~ /^([^@]+)@/) { update request { &User-Name := "%{1}" } }
Security
- No admin token at runtime. The only key on the RADIUS server is the inbound API key. You only need admin rights once for the setup.
- The key can trigger pushes for any user of this realm. Keep it secret, use a separate one instead of the tenant API key and connect FreeRADIUS and Keycloak only via HTTPS.
- Don't weaken fail-closed: the policy rejects everything that isn't “approved”. Leave it that way.
- An open request occupies a FreeRADIUS worker for up to 60 seconds. With many simultaneous sign-ins, size the number of workers and connections accordingly.