| 1 |
= Using configuration and run-time variables |
| 2 |
|
| 3 |
*Goal:* To use run-time variable expansion. |
| 4 |
|
| 5 |
*Time:* 15-30 minutes. |
| 6 |
|
| 7 |
*Files:* |
| 8 |
|
| 9 |
- `etc/raddb/radiusd.conf` |
| 10 |
- `etc/raddb/users` |
| 11 |
- `etc/raddb/mods-available/detail` |
| 12 |
|
| 13 |
*`man` page:* `radiusd.conf` |
| 14 |
|
| 15 |
*documentation page:* xref:unlang:xlat/index.adoc[Dynamic expansions] |
| 16 |
|
| 17 |
There are two kinds of variables within the server. The first is within |
| 18 |
`radiusd.conf` and related files. These variables are referenced via the |
| 19 |
`$` character, which is used to define common terms (e.g. `${logdir}` so that |
| 20 |
those terms do not have to be repeated multiple times in the |
| 21 |
configuration files. These variables are used only when the server reads |
| 22 |
the configuration files, and they cannot be updated or edited once the files |
| 23 |
have been read. |
| 24 |
|
| 25 |
The second kind of variable is a run-time variable, which is dynamically |
| 26 |
expanded for each request received by the server. These variables are |
| 27 |
referenced by the `%` character, and they may be used to pull the values of |
| 28 |
attributes from the request to be used by a module. These variables may |
| 29 |
also be used by one module to obtain information from another module. |
| 30 |
|
| 31 |
In this exercise, we cover configuration variables and some simple |
| 32 |
properties of the run-time variables. Later exercises cover additional |
| 33 |
properties of the run-time variables. |
| 34 |
|
| 35 |
The main configuration file `radiusd.conf` and the module configuration |
| 36 |
files contains a number of examples of the use of variables. For example, |
| 37 |
the `detail` module (configured in `etc/raddb/mods-enabled/detail`) |
| 38 |
has a configuration entry named "filename", which by default has the |
| 39 |
following value: |
| 40 |
|
| 41 |
---------------------------------------------------------------- |
| 42 |
filename = ${radacctdir}/%{Net.Src.IP}/detail-%Y%m%d |
| 43 |
---------------------------------------------------------------- |
| 44 |
|
| 45 |
The configuration entry is composed of two kinds of variable expansion. |
| 46 |
One references the `${radacctdir}` configuration variable, which was |
| 47 |
previously defined in `radiusd.conf`. The following variables are |
| 48 |
expanded at run time and depend on information in the request packet |
| 49 |
and other dynamically calculated data. |
| 50 |
|
| 51 |
Start the server in debugging mode (`radiusd -X`). |
| 52 |
In the server output, look for the `detail` module and the `filename` |
| 53 |
configuration entry for that module. Verify that the string printed |
| 54 |
for the `filename` does not print the reference to the `${radacctdir}` |
| 55 |
variable, but instead has substituted the value of that variable. |
| 56 |
Verify also that the values of the run-time variables have _not_ |
| 57 |
been substituted and that they are still printed as variables. |
| 58 |
|
| 59 |
If you don't see any configuration printed for the `detail` file module |
| 60 |
ensure it is uncommented in the `accounting {}` section of the |
| 61 |
`raddb/sites-available/default` virtual server. |
| 62 |
|
| 63 |
Now read the |
| 64 |
https://github.com/FreeRADIUS/freeradius-server/blob/v3.2.x/doc/configuration/variables.rst[variables] |
| 65 |
documentation file to determine the meaning of the variables used in the `filename` configuration entry. |
| 66 |
Once you are done, send the server an accounting packet (e.g., |
| 67 |
`bob-acct-stop.sh`), and go look for the detail file, which will be |
| 68 |
dynamically created. Verify that the contents of the file are the |
| 69 |
accounting packet you just sent. |
| 70 |
|
| 71 |
In addition to being used in the configuration files, run-time variables |
| 72 |
may also be used to create values for reply attributes. Stop the server, |
| 73 |
and edit the users file to add the following entry at the top: |
| 74 |
|
| 75 |
----------------------------------------------------------------------------- |
| 76 |
bob Password.Cleartext := "hello" |
| 77 |
Reply-Message = "Hello %{User-Name}, your NAS port is %{NAS-Port}", |
| 78 |
Reply-Message += "at time %T" |
| 79 |
----------------------------------------------------------------------------- |
| 80 |
|
| 81 |
Start the server, and run the `bob-login-one.sh` script. Verify that the |
| 82 |
`Reply-Message` attributes contain the user name, NAS port, time, and a |
| 83 |
copy of the `Class` attribute from the reply. |
| 84 |
|
| 85 |
== Questions |
| 86 |
|
| 87 |
1. Why are run-time variables useful? |
| 88 |
2. How would you configure that entry in the file to reply with the |
| 89 |
directory name where the `radiusd.conf` file is stored? Why is this a |
| 90 |
bad idea? |
| 91 |
3. How would you create an entry in the users file that matched users when |
| 92 |
their `Class` was the same as their `NAS-Port`? |
| 93 |
|
| 94 |
// Copyright (C) 2021 Network RADIUS SAS. Licenced under CC-by-NC 4.0. |
| 95 |
// This documentation was developed by Network RADIUS SAS. |