| 1 |
== Configure "device", "class" and "group" options |
| 2 |
|
| 3 |
Beyond the global, network and subnet options already described, most sites |
| 4 |
will have a number of group or class based options, and have a requirement for |
| 5 |
setting reply parameters against individual devices. |
| 6 |
|
| 7 |
In general, FreeRADIUS does not differentiate between "classes" (memberships |
| 8 |
defined by some attribute of the DHCP request) and "groups" (memberships |
| 9 |
defined by some manually aggregation related devices, typically based on lists |
| 10 |
of MAC address). |
| 11 |
|
| 12 |
The sample DHCP configuration provided with FreeRADIUS makes use of an internal |
| 13 |
attribute `DHCP-Group-Name` to support the setting of different options for |
| 14 |
different groups of devices. |
| 15 |
|
| 16 |
In general the groups to which a device belongs is determined during the |
| 17 |
processing of a request and these are added as instances of the |
| 18 |
`DHCP-Group-Name` attribute. This may be by performing a test on one or more |
| 19 |
request parameters (akin to a "class"), hash-based lookup of up all of part of |
| 20 |
an attribute in a local list (akin to a "subclass"), or doing the same using a |
| 21 |
remote datastore (SQL, LDAP, REST API, etc). |
| 22 |
|
| 23 |
FreeRADIUS can then iterate over `DHCP-Group-Name` to set group-specific |
| 24 |
options. |
| 25 |
|
| 26 |
We describe some of these options in more detail. |
| 27 |
|
| 28 |
=== Directly in Policy |
| 29 |
|
| 30 |
Simple class options can be written directly into policy. This is most |
| 31 |
suited to those options that rarely change and are based on attributes in the |
| 32 |
request such as the `User-Class`. |
| 33 |
|
| 34 |
Consider the ISC DHCP configuration snippet: |
| 35 |
|
| 36 |
[source,iscdhcp] |
| 37 |
---- |
| 38 |
filename "undionly.kpxe"; |
| 39 |
class "pxeclient" { |
| 40 |
match option substring(user-class,0,4); |
| 41 |
} |
| 42 |
subclass "pxeclient" "iPXE" { |
| 43 |
filename "http://my.web.server/boot_script.php"; |
| 44 |
} |
| 45 |
---- |
| 46 |
|
| 47 |
Or the equivalent Kea configuration: |
| 48 |
|
| 49 |
[source,isckea] |
| 50 |
---- |
| 51 |
"Dhcp4": { |
| 52 |
"option-data": [ |
| 53 |
{ "name": "boot-file-name", "data": "undionly.kpxe" } |
| 54 |
], |
| 55 |
"client-classes": [ |
| 56 |
{ |
| 57 |
"name": "pxeclient", |
| 58 |
"test": "substring(option[77],0,4) == 'iPXE'", |
| 59 |
"option-data": [ |
| 60 |
{ |
| 61 |
"name": "boot-file-name", |
| 62 |
"data": "http://my.web.server/boot_script.php" |
| 63 |
} |
| 64 |
] |
| 65 |
} |
| 66 |
] |
| 67 |
... |
| 68 |
} |
| 69 |
---- |
| 70 |
|
| 71 |
These define the "filename" DHCP option differently based on whether or not the |
| 72 |
supplied "user-class" option begins with "iPXE". |
| 73 |
|
| 74 |
FreeRADIUS provides multiple ways for this to be configured. |
| 75 |
|
| 76 |
For example, the following "unlang" policy implements the class options defined |
| 77 |
above: |
| 78 |
|
| 79 |
[source,unlang] |
| 80 |
---- |
| 81 |
if (&DHCP-User-Class && "%{substring:&DHCP-User-Class 0 4}" == "iPXE") { |
| 82 |
update reply { |
| 83 |
&DHCP-Boot-Filename := "http://my.web.server/boot_script.php" |
| 84 |
} |
| 85 |
} else { |
| 86 |
update reply { |
| 87 |
&DHCP-Boot-Filename := "undionly.kpxe" |
| 88 |
} |
| 89 |
} |
| 90 |
---- |
| 91 |
|
| 92 |
Policy-based configuration of DHCP options is also useful for complex matching. |
| 93 |
For example, the following Unlang sets the DHCP-Boot-Filename parameter based |
| 94 |
on the request's DHCP-Client-Identifier using regular expression captures, |
| 95 |
provided that it matches the given format: |
| 96 |
|
| 97 |
[source,unlang] |
| 98 |
---- |
| 99 |
if (&DHCP-Client-Identifier && \ |
| 100 |
"%{string:DHCP-Client-Identifier}" =~ /^RAS([0-9])-site([A-Z])$/) { |
| 101 |
update reply { |
| 102 |
&DHCP-Boot-Filename := "rasboot-%{1}-%{2}.kpxe" |
| 103 |
} |
| 104 |
} |
| 105 |
---- |
| 106 |
|
| 107 |
=== In Text Files |
| 108 |
|
| 109 |
The `files` module that has already been described for global, network and |
| 110 |
subnet options can also be used to apply options to groups of clients. |
| 111 |
|
| 112 |
Firstly we must defined a mapping from a set of clients clients to their |
| 113 |
respective groups. One option for this is to use the `passwd` module, for |
| 114 |
which a sample configuration is included. |
| 115 |
|
| 116 |
Firstly symlink or copy the module configuration |
| 117 |
`<raddb>/mods-available/dhcp_passwd` into `<raddb>/mods-enabled/`. The |
| 118 |
suggested configuration expects the group membership file to be in |
| 119 |
`<raddb>/mods-config/files/dhcp_groups` and take the form of: |
| 120 |
|
| 121 |
[source,config] |
| 122 |
---- |
| 123 |
<group1 name>|<hardware address>,<hardware address>,<hardware address> |
| 124 |
<group2 name>|<hardware address>,<hardware address> |
| 125 |
---- |
| 126 |
|
| 127 |
i.e. one line for each group starting with the group name followed by a pipe |
| 128 |
character and then a comma-separated list of hardware addresses. |
| 129 |
|
| 130 |
The `allow_multiple_keys` option allows for a host to be a member of |
| 131 |
more than one group. |
| 132 |
|
| 133 |
Sample configuration for looking up group options is contained in |
| 134 |
`<raddb>/policy.d/dhcp` in the `dhcp_group_options` policy and in |
| 135 |
`<raddb>/mods-available/dhcp_files` as the `dhcp_set_group_options` instance. |
| 136 |
|
| 137 |
The same data file `<raddb>/mods-config/files/dhcp` is used to lookup |
| 138 |
group options as was used for global and network options. In this instance, |
| 139 |
add entries with the group name as the key such as: |
| 140 |
|
| 141 |
[source,config] |
| 142 |
---- |
| 143 |
group1 |
| 144 |
DHCP-Log-Server := 10.10.0.100, |
| 145 |
DHCP-LPR-Server := 10.10.0.200 |
| 146 |
|
| 147 |
group2 |
| 148 |
DHCP-LPR-Server := 192.168.20.200 |
| 149 |
---- |
| 150 |
|
| 151 |
=== In the SQL Database |
| 152 |
|
| 153 |
Policy and files are both read during startup and editing them while |
| 154 |
FreeRADIUS is running will not result in any changes in behaviour. If |
| 155 |
you require regular changes to DHCP options, then storing them in |
| 156 |
an SQL database provides greater flexibility since the queries will be run in |
| 157 |
response to each DHCP packet rather than requiring the server to be restarted. |
| 158 |
|
| 159 |
DHCP reply options for devices (including network-specific options) can be |
| 160 |
fetched from SQL using an arbitrary lookup key. This can be performed multiple |
| 161 |
times as necessary using different contexts, for example to first set |
| 162 |
subnet-specific options and then to set group-specific options. |
| 163 |
|
| 164 |
The default schema contains three tables to support this: |
| 165 |
|
| 166 |
"dhcpreply" contains reply options for a given identifier (e.g. MAC Address): |
| 167 |
|
| 168 |
.dhcpreply table |
| 169 |
|=== |
| 170 |
|Identifier |Attribute |Op |Value |Context |
| 171 |
|
| 172 |
|`02:01:aa:bb:cc:dd` |`DHCP-Log-Server` |`:=` |`192.0.2.10` |`by-mac` |
| 173 |
|`02:01:aa:bb:cc:dd` |`DHCP-LPR-Server` |`:=` |`192.0.2.11` |`by-mac` |
| 174 |
|`02:01:aa:bb:cc:dd` |`Fall-Through` |`:=` |`Yes` |`by-mac` |
| 175 |
|=== |
| 176 |
|
| 177 |
"dhcpgroup" maps identifiers to a group of options that can be shared: |
| 178 |
|
| 179 |
.dhcpgroup table |
| 180 |
|=== |
| 181 |
|Identifier |GroupName |Priority |Context |
| 182 |
|
| 183 |
|`02:01:aa:bb:cc:dd` |`salesdept` |`10` |`by-mac` |
| 184 |
|=== |
| 185 |
|
| 186 |
"dhcpgroupreply" contains reply options for each group: |
| 187 |
|
| 188 |
.dhcpgroupreply table |
| 189 |
|=== |
| 190 |
|GroupName |Attribute |Op |Value |Context |
| 191 |
|
| 192 |
|`salesdept` |`DHCP-NTP-Servers` |`:=` |`192.0.2.20` |`by-mac` |
| 193 |
|`salesdept` |`DHCP-Log-Server` |`+=` |`192.0.2.21` |`by-mac` |
| 194 |
|`salesdept` |`DHCP-LPR-Server` |`^=` |`192.0.2.22` |`by-mac` |
| 195 |
|=== |
| 196 |
|
| 197 |
Within the context of assigning options directly to devices, as well as to |
| 198 |
manually-curated groups of devices keyed by their MAC address: |
| 199 |
|
| 200 |
- Place device-specific options in the "dhcpreply" table. |
| 201 |
- Add `Fall-Through := Yes` to the options in the "dhcpreply" table in order |
| 202 |
to trigger group lookups, which are disabled by default. |
| 203 |
- Place entries in the "dhcpgroup" `identifier = <MAC-Address>, groupname = <group>, priority = |
| 204 |
<priority>` in the "dhcpgroup" table to map a device to its groups by |
| 205 |
priority. |
| 206 |
- Place the grouped options in the "dhcpgroupreply" table. |
| 207 |
- For each of the above, set `Context` to something by which the option |
| 208 |
lookup is referred to in the policy, for example `Context = 'by-mac'`. |
| 209 |
|
| 210 |
For the above example you would add the following to the DHCP virtual server to |
| 211 |
perform reply option lookup using the device's MAC address against the `by-mac` |
| 212 |
context: |
| 213 |
|
| 214 |
[source,unlang] |
| 215 |
---- |
| 216 |
update control { |
| 217 |
&DHCP-SQL-Option-Context := "by-mac" |
| 218 |
&DHCP-SQL-Option-Identifier := &request:DHCP-Client-Hardware-Address |
| 219 |
} |
| 220 |
dhcp_sql.authorize |
| 221 |
---- |
| 222 |
|
| 223 |
In the above, the DHCP reply options would be assigned to a device with MAC |
| 224 |
address 02:01:aa:bb:cc:dd as follows: |
| 225 |
|
| 226 |
- Firstly, the `DHCP-Log-Server` option would be set to `192.0.2.10` and the |
| 227 |
`DHCP-LPR-Server` option set to `192.0.2.11`. |
| 228 |
- `Fall-Through` is set, so the group mapping is then queried which |
| 229 |
determines that the device belongs to a single `salesdept` group. |
| 230 |
- Finally, the options for the `salesdept` group are now merged, setting a |
| 231 |
`DHCP-NTP-Servers` option to `192.0.2.20`, appending an additional |
| 232 |
`DHCP-Log-Server` option set to `192.0.2.21`, and prepending an additional |
| 233 |
`DHCP-LPR-Server` option set to `192.0.2.22`. |
| 234 |
|
| 235 |
If instead you wanted to perform a "subclass" lookup based on the first three |
| 236 |
octets of the device's MAC address then with tables containing the following |
| 237 |
sample data you could invoke an SQL lookup as shown: |
| 238 |
|
| 239 |
."dhcpreply" table: |
| 240 |
|=== |
| 241 |
|Identifier |Attribute |Op |Value |Context |
| 242 |
|
| 243 |
|`000393` |`Fall-Through` |`:=` |`Yes` |`class-vendor` |
| 244 |
|`000a27` |`Fall-Through` |`:=` |`Yes` |`class-vendor` |
| 245 |
|`f40304` |`Fall-Through` |`:=` |`Yes` |`class-vendor` |
| 246 |
|=== |
| 247 |
|
| 248 |
."dhcpgroup" table: |
| 249 |
|=== |
| 250 |
|Identifier |GroupName |Priority |Context |
| 251 |
|
| 252 |
|`000393` |`apple` |`10` |`class-vendor` |
| 253 |
|`000a27` |`apple` |`10` |`class-vendor` |
| 254 |
|`f40304` |`google` |`10` |`class-vendor` |
| 255 |
|=== |
| 256 |
|
| 257 |
."dhcpgroupreply" table: |
| 258 |
|=== |
| 259 |
|GroupName |Attribute |Op |Value |Context |
| 260 |
|
| 261 |
|`apple` |`DHCP-Boot-Filename` |`:=` |`apple.efi` |`class-vendor` |
| 262 |
|`google` |`DHCP-Boot-Filename` |`:=` |`google.efi` |`class-vendor` |
| 263 |
|=== |
| 264 |
|
| 265 |
|
| 266 |
[source,unlang] |
| 267 |
---- |
| 268 |
update control { |
| 269 |
&DHCP-SQL-Option-Context := "class-vendor" |
| 270 |
&DHCP-SQL-Option-Identifier := \ |
| 271 |
"%{substring:%{hex:&DHCP-Client-Hardware-Address} 0 6}" |
| 272 |
} |
| 273 |
dhcp_sql.authorize |
| 274 |
---- |
| 275 |
|
| 276 |
The file `policy.d/dhcp` contains a policy named `dhcp_policy_sql` which |
| 277 |
provides further worked examples for different types of option lookups. |
| 278 |
|
| 279 |
=== Testing "device", "class" and "group" options |
| 280 |
|
| 281 |
You should now test that any device-related options that you have configured |
| 282 |
using the various methods available are applied successfully by generating |
| 283 |
packets containing those parameters based upon which the reply options are set. |
| 284 |
|
| 285 |
For example, to test the iPXE user class example above you might want to |
| 286 |
generate a request as follows: |
| 287 |
|
| 288 |
[source,shell] |
| 289 |
---- |
| 290 |
cat <<EOF > dhcp-packet-ipxe-boot.txt |
| 291 |
DHCP-Message-Type := DHCP-Discover |
| 292 |
DHCP-Client-Hardware-Address := 02:01:aa:bb:cc:dd |
| 293 |
DHCP-User-Class := "iPXE-class-abc" |
| 294 |
EOF |
| 295 |
---- |
| 296 |
|
| 297 |
To which you would expect to see a response such as: |
| 298 |
|
| 299 |
.Example output from dhcpclient |
| 300 |
=============================== |
| 301 |
dhcpclient: ... |
| 302 |
---------------------------------------------------------------------- |
| 303 |
Waiting for DHCP replies for: 5.000000 |
| 304 |
---------------------------------------------------------------------- |
| 305 |
... |
| 306 |
DHCP-Message-Type = DHCP-Offer |
| 307 |
DHCP-Your-IP-Address = 1.2.3.4 |
| 308 |
DHCP-Boot-Filename := "http://my.web.server/boot_script.php" |
| 309 |
... |
| 310 |
=============================== |