| 1 |
= Update blocks and simple conditions |
| 2 |
|
| 3 |
*Goal:* Explore uses of update blocks in the policy language |
| 4 |
|
| 5 |
*Time:* 10-25 minutes |
| 6 |
|
| 7 |
*File:* |
| 8 |
|
| 9 |
- `sites-available/default` |
| 10 |
|
| 11 |
*`man` page:* unlang |
| 12 |
|
| 13 |
*documentation page(s):* |
| 14 |
|
| 15 |
- xref:unlang:condition/index.adoc[Conditional Expressions] |
| 16 |
- xref:unlang:update.adoc[The Update Statement] |
| 17 |
|
| 18 |
include::partial$unlang_start.adoc[] |
| 19 |
include::partial$common_control_attrs_sidebar.adoc[] |
| 20 |
|
| 21 |
Unlang `update` blocks are used to update one or attributes in one |
| 22 |
of the server's xref:unlang:list.adoc[attribute lists]. |
| 23 |
|
| 24 |
|
| 25 |
In previous tutorials we've used the `files` modules, and the authorize |
| 26 |
methods of authentication modules such as `pap` and `chap` to alter how |
| 27 |
the server processes requests by setting a `Auth-Type` value. |
| 28 |
Here, we will emulate that behaviour using the policy language. |
| 29 |
|
| 30 |
* Create a condition (_condition 1_) to execute policy code if |
| 31 |
the `User-Name` in the request is 'bob'. |
| 32 |
* Within that condition block, set the control attribute `Password.Cleartext` |
| 33 |
to be 'hello', and instruct the server to run the the `authenticate { ... }` |
| 34 |
subsection for `pap`. |
| 35 |
* Use the `bob.sh` script to verify that you see an `Access-Accept` returned |
| 36 |
despite the `files` module not being called. |
| 37 |
|
| 38 |
Using additional conditions and update blocks, emulate the logic implemented |
| 39 |
using the files module in the xref:matching_users.adoc[Matching Users] |
| 40 |
exercise. |
| 41 |
|
| 42 |
To recap: |
| 43 |
|
| 44 |
* If an incoming request contains a `User-Name` attribute with the value |
| 45 |
'bob', and contains an attribute `Framed-Protocol` with value `PPP` |
| 46 |
(_condition 2_), reply with a `Framed-IP-Address` attribute with the value |
| 47 |
`192.168.10.12`. |
| 48 |
* If an incoming request contains a `Service-Type` attribute with a value |
| 49 |
of `Framed-User` (_condition 3_), reply with a `Framed-Route` attribute |
| 50 |
assigning a default route of `192.168.10.1` (`0.0.0.0/0 192.168.10.1 1`) and |
| 51 |
a `Framed-IP-Netmask` attribute with a value of `255.255.255.0`. |
| 52 |
|
| 53 |
Again test the server with username "bob" and password "hello". Use the |
| 54 |
debug output of the server to see which unlang conditions evaluated to |
| 55 |
true. You may use `radclient` or the `bob.sh` script to send the packets. |
| 56 |
|
| 57 |
Perform other authentication tests, adding the appropriate attributes to |
| 58 |
the test requests to exercise the different conditions. If you already have |
| 59 |
test packets from the xref:matching_users.adoc[Matching Users] exercises, |
| 60 |
you may use those, otherwise continue until you have packets that will match: |
| 61 |
|
| 62 |
* conditions 1 and 2, but not 3. |
| 63 |
* conditions 1 and 3, but not 2. |
| 64 |
* conditions 1, 2, and 3. |
| 65 |
|
| 66 |
== Questions |
| 67 |
|
| 68 |
1. What are the advantages of unlang over the files module when creating |
| 69 |
policies? |
| 70 |
2. What are the advantages of the files modules over unlang? Are there |
| 71 |
any situations where you think the files module might be better suited |
| 72 |
to a task than unlang? |
| 73 |
3. Can you think of any efficiencies the users module might have over |
| 74 |
multiple conditions, where policies are being assigned to many different |
| 75 |
users? |
| 76 |
|
| 77 |
|
| 78 |
// Copyright (C) 2025 Network RADIUS SAS. Licenced under CC-by-NC 4.0. |
| 79 |
// This documentation was developed by Network RADIUS SAS. |