Skip to content

Commit

Permalink
Radius enforce roles (librenms#15294)
Browse files Browse the repository at this point in the history
Add new setting to specify if user roles will be set at login or not.
Without this setting enabled, roles are only set when the user is first created and never after that. If roles set via Filter-ID attribute or radius.default_roles change, they will never be reflected on existing users.
For that reason, the default is set to enabled.  Historically, radius did not enforce roles.
  • Loading branch information
murrant authored Sep 7, 2023
1 parent 2618a99 commit b51ae39
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion LibreNMS/Authentication/RadiusAuthorizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function authenticate($credentials)
'auth_type' => LegacyAuth::getType(),
'can_modify_passwd' => 0,
]);
$new_user = ! $user->exists;
$user->save();

// cache a single role from the Filter-ID attribute now because attributes are cleared every accessRequest
Expand All @@ -50,7 +51,9 @@ public function authenticate($credentials)
$this->roles[$credentials['username']] = [substr($filter_id_attribute, 14)];
}

$user->setRoles($this->roles[$credentials['username']] ?? $this->getDefaultRoles(), true);
if (Config::get('radius.enforce_roles') || $new_user) {
$user->setRoles($this->roles[$credentials['username']] ?? $this->getDefaultRoles(), true);
}

return true;
}
Expand Down
4 changes: 4 additions & 0 deletions lang/en/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,10 @@
'description' => 'Default user roles',
'help' => 'Sets the roles that will be assigned to the user unless Radius sends attributes that specify role(s)',
],
'enforce_roles' => [
'description' => 'Enforce roles at login',
'help' => 'If enabled, roles will be set to the ones specified by the Filter-ID attribute or radius.default_roles at login. Otherwise, they will be set when the user is created and never changed after that.',
],
],
'reporting' => [
'error' => [
Expand Down
9 changes: 8 additions & 1 deletion misc/config_definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"value": "array",
"value.*": "string"
}
},
},
"alert_colour.ok": {
"default": "#00ff00",
"type": "color"
Expand Down Expand Up @@ -5111,6 +5111,13 @@
"order": 3,
"type": "array"
},
"radius.enforce_roles": {
"default": true,
"group": "auth",
"section": "radius",
"order": 4,
"type": "boolean"
},
"rancid_configs": {
"default": [],
"type": "array"
Expand Down

0 comments on commit b51ae39

Please sign in to comment.