Documentation

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.

Text
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

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:

  1. 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}.
  2. 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:

Shell
# 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):

Shell
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:

Shell
sudo sh install.sh \
  --keycloak-url https://id.example.com \
  --realm        acme \
  --api-key      <INBOUND_API_KEY>

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.

Shell
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

<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:

Shell
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:

Shell
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):

Shell
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>"}'

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

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:

Text
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.