Freeradius en Part3 PDF
Freeradius en Part3 PDF
Freeradius en Part3 PDF
RADIUS Server
Aurélien Geron, Wifirst, january 7th 2011
• An Open-Source
(GPLv2) server
• A powerful configu-
ration system
• Many expansion
modules
• Modules configuration
• Roaming configuration
• Modules configuration
• Roaming configuration
BEGIN-VENDOR Cisco
END-VENDOR Cisco
• Modules configuration
• Roaming configuration
• You may also include a whole directory: all the files whose
name only contains letters, numbers, dots (.), and underscores
( _ ) will be included.
prefix = /usr
exec_prefix = /usr Paths to the main directories and files
sysconfdir = /etc (usually, they do not need to be changed)
localstatedir = /var
sbindir = ${exec_prefix}/sbin
logdir = /var/log/freeradius
raddbdir = /etc/freeradius
radacctdir = ${logdir}/radacct
name = freeradius
confdir = ${raddbdir}
run_dir = ${localstatedir}/run/${name}
db_dir = ${raddbdir}
libdir = /usr/lib/freeradius
pidfile = ${run_dir}/${name}.pid
#chroot = /path/to/chroot/directory
Un*x user and group that the server will run
user = freerad
group = freerad as (should usually not be changed)
max_request_time = 30 A few performance parameters that can be
cleanup_delay = 5 tweaked, depending on the load of the server
max_requests = 1024
(see the comments in radiusd.conf for
#... more details)
thread pool {
start_servers = 5
max_servers = 32
min_spare_servers = 3 Threads management
max_spare_servers = 10
max_requests_per_server = 0
}
log {
destination = files Logs management
file = ${logdir}/radius.log
syslog_facility = daemon
stripped_names = no
auth = no
auth_badpass = no
auth_goodpass = no
}
# ...
instantiate {
exec
expr
# daily Force instanciation of modules (see later)
expiration
logintime
}
Definitions of the virtual servers
$INCLUDE policy.conf
(they handle the requests) and their
$INCLUDE sites-enabled/ policies
• Modules configuration
• Roaming configuration
NAS
?
Access-Accept Response
or
Access-Reject List of attributes
User-Password=G!5#%d
User-Name=NT\alain
+ ...
Parse request
attributes
• Notes:
User-Password=G!5#%d
User-Name=NT\alain
...
Parse request
attributes
Authorization
authorize {
preprocess
files List of modules
pap
}
/etc/freeradius/sites-enabled/default
vendredi 21 janvier 2011
preprocess module
request control reply
Find NAS by IP Msg-Authenticator=...
User-Password=G!5#%d
User-Name=alain
...
Parse request
attributes = This module fixes
a few well-known attribute
oddities (ex: strip the NT
domain from the User-
Name)
Authorization
authorize { authorize
preprocess Il also handles
files
pap
preprocess hints and
huntgroups
} (see later)
User-Password=G!5#%d Filter-ID=web_only
User-Name=alain ...
...
Parse request +
attributes
This module applies
the rules defined in the
users file to add or
modify attributes
Authorization
authorize { authorize
preprocess
files
pap
files
}
• Example :
alain Huntgroup-Name == "switch7_ports_1_a_12", Cleartext-Password := "abc"
Reply-Message = "Hi alain!",
Filter-ID = "web_only"
Do not forget the commas
:= adds the attribute set to the given value, overwriting the existing value if
the attribute already exists
+= adds the attribute set to the given value, even if it already exists (the same
attribute may then appear multiple times in the RADIUS packet)
•
This will be dynamically substituted by
Example: the value of the User-Name attribute
• Modules sql, ldap, expr, exec and perl have an xlat function.
Here are a few examples:
• %{sql:select credit from credits where login='%{User-Name}'}
• %{ldap:ldap:///dc=company,dc=com?uid?sub?uid=%u}
• %{expr:2*%{Session-Timeout}+10}
• You may then filter on locations and ports in the users file by
applying a condition like Huntgroup-Name == "..."
• For example:
• For example:
DEFAULT Suffix == ".ppp", Strip-User-Name = Yes
Hint = "PPP",
Service-Type = Framed-User,
Framed-Protocol = PPP The User-Name attribute will be modified
in the request to remove the «.ppp» suffix
User-Password=G!5#%d Filter-ID=web_only
User-Name=alain ...
...
Parse request +
attributes
This module applies
the rules defined in the
users file to add or
modify attributes
Authorization
authorize { authorize
preprocess
files
pap
files
}
User-Password=G!5#%d
User-Name=alain
...
Parse request
attributes
If a module returns reject, then
freeRADIUS stops the request handling and
returns an Access-Reject
Authorization
authorize { authorize
preprocess
files
pap
files
}
User-Name=alain ...
...
Parse request +
attributes This module adds
Auth-Type=pap if the
User-Password attribute
is defined...
Authorization
authorize { authorize
preprocess
...unless
files
pap
pap Auth-Type is
} already set
User-Name=alain ...
...
Authorization
User-Name=alain ...
...
Authorization
Decipher the
User-Password
and check the
password
Authentication
authenticate { authenticate
Auth-Type PAP {
}
pap pap
}
User-Name=alain ...
...
Storage
Clear Crypt MD5 SHA1 SMD5 SSHA1 NT LM
Method
CHAP Yes No No No No No No No
EAP/MD5 Yes No No No No No No No
Storage
Clear Crypt MD5 SHA1 SMD5 SSHA1 NT LM
Method
• To do this, simply append a section to the module name, and set the
desired priorities in that section, for example:
authorize {
preprocess
authorize {
sql {
preprocess
ok = return
sql
updated = return
ldap
}
}
ldap
}
• Modules in a group are called one after the other, each one returning
a code, and the return code with the highest priority is returned by
the group itself (the group handling process is interrupted if a
module’s code has a return priority level)
• It’s the same thing, except that the default priority rules in a
redundant section are fail = 1 and default = return
authorize {
preprocess
group {
authorize {
sql_primary {
preprocess
fail = 1
redundant {
default = return
sql_primary
}
sql_backup1
sql_backup1 {
sql_backup2
fail = 1
default = return
fail = return
}
ok = return
sql_backup2
updated = return
}
ok = return
ldap
updated = return
}
}
ldap
}
vendredi 21 janvier 2011
Load balancing
• To load-balance requests between multiple modules (for example to
hit three different database servers), simply use a load-balance
section:
authorize {
preprocess
load-balance {
sql1
sql2
sql3
}
}
• One of the modules is chosen randomly and executed, and its result is
returned by the load-balance section itself (even if the module
returns fail)
• (return_code)
True if the last called module
returned this code, ex: (fail)
• Just like in the C language, you may use !a to express «not a»,
a && b for «a and b», and a || b for «a or b»
• This example will have the same result as the one we saw earlier with
the if, elsif and else instructions
vendredi 21 janvier 2011
The unlang «langage»
• By default, attributes are looked up in the request list
• You may specify another internal list using the following syntax:
%{list:attribute} for example %{control:Auth-Type}
• So far we have talked about the request, control and reply lists,
but there are a few other lists:
• proxy-request and proxy-reply contain the attributes
that are sent to or received from a Home-Server, when
freeRADIUS acts as a Proxy-Server
• outer.request, outer.reply, outer.control,
outer.proxy-request, and outer.proxy-reply allow
you to access the attribute lists of the outer EAP request during
the handling of the inner EAP request of a PEAP or TTLS tunnel
For the <= and >= operators, the attribute is added with the given value if it does not exist
policy {
add_welcome_message {
update reply {
Reply-Message := "Hello %{User-Name}"
}
}
}
• Modules configuration
• Roaming configuration
OR
a_param = 23 a_param = 23
another_param = "blabla" another_param = "blabla"
... ...
} }
usersfile = ${confdir}/users
acctusersfile = ${confdir}/acct_users
preproxy_usersfile = ${confdir}/preproxy_users
realm realmpercent {
format = suffix
delimiter = "%"
}
/etc/freeradius/modules/realm
ldap {
server = "ldap.example.com"
identity = "cn=admin,dc=example,dc=com"
...
tls {
start_tls = no
cacertfile = /path/to/cacert.pem
...
}
...
}
/etc/freeradius/modules/ldap
vendredi 21 janvier 2011
EAP configuration
• EAP configuration is also organized in subsections:
eap {
default_eap_type = md5
timer_expire = 60
...
md5 { Some submodules (such as md5) have no configuration, but
} you need to add a section if you want to enable them
...
tls { TLS configuration is required for
certdir = ${confdir}/certs
cadir = ${confdir}/certs EAP/TLS, PEAP and TTLS
...
}
... If this parameter is defined, then
peap { the inner EAP requests will be
default_eap_type = mschapv2 handled by the given virtual
copy_request_to_tunnel = yes
use_tunneled_reply = no server, or else it will be the same
# proxy_tunneled_request_as_eap = yes virtual server that handled the
virtual_server = "inner-tunnel" external EAP dialog
}
mschapv2 {
} This is one of the rare modules whose configu-
}
ration is not located in the modules directory
/etc/freeradius/eap.conf
vendredi 21 janvier 2011
Modules instantiation
• When freeRADIUS starts up, it parses the configuration
files and determines the list of all the modules that can
possibly be used
• Module configuration
• Roaming configuration
# revive_interval = 120
status_check = status-server
check_interval = 30
num_answers_to_alive = 3
}
home_server rad2_foo_telecom
type = auth Secondary Home-Server config
...
}
... # follows: home_server_pools and realms
status_check = status-server
check_interval = 30
num_answers_to_alive = 3 These settings can prevent
}
home_server rad2_foo_telecom
freeRADIUS from proxying requests
type = auth to a dead Home-Server
...
}
... # follows: home_server_pools and realms
# revive_interval = 120
...but it is preferable to send status requests to
status_check = status-server the Home-Server at regular intervals instead: in this
check_interval = 30 example, we query the Home-Server every 30s and
num_answers_to_alive = 3 it takes 3 successive successes to revive it
}
home_server rad2_foo_telecom
If we
type use status requests, then the Home-Server must be configured to handle them,
= auth
of course. If it’s a freeRADIUS server, you must create a listen section in its config with
...
} the status type, then set status_server=yes in the security section, and finally
... # follows: home_server_pools and realms
create a virtual server to handle status requests (see sites-available/status)
vendredi 21 janvier 2011
templates.conf
• The Home-Servers’ settings are often very similar
home_server rad1-bar {
$template home_server
ipaddr = 212.3.4.5 templates {
secret = "FRc0...7FL3b8" home_server {
} response_window = 20
home_server rad2-bar { zombie_period = 40
$template home_server revive_interval = 120
ipaddr = 212.3.4.6 }
secret = "GDCd...Ml$N3z"
} home_server foo-template {
type = auth
home_server rad1-foo { port = 1812
template = foo-template secret = "ApQj4...3g2sD"
ipaddr = 212.3.4.7 response_window = 20
} }
home_server rad2-foo { }
template = foo-template
ipaddr = 212.3.4.8 /etc/freeradius/templates.conf
}
/etc/freeradius/proxy.conf
vendredi 21 janvier 2011
templates.conf
In this example, we
configure a pool composed
of the two Home-Servers
... defined earlier
home_server_pool foo_telecom_pool {
type = fail-over
virtual_server = pre_post_proxy_for_foo All the Home-Servers in a pool
home_server = rad1_foo_telecom
home_server = rad2_foo_telecom must be have the same type
} (auth or acct or auth+acct)
realm foo.com {
auth_pool = foo_telecom_pool
nostrip
}
And finally, we point the
foo.com realm to this pool
• either use auth_pool (for Home-Servers of type auth)
and/or acct_pool (for Home-Servers of type acct)
• or use pool (for Home-Servers of type auth+acct)
• or finally use no pool at all, in which case the realm is
handled locally (no proxying to Home-Servers)
...
home_server_pool foo_telecom_pool {
type = fail-over A virtual server may be set, in which case
virtual_server = pre_post_proxy_for_foo its pre-proxy and post-proxy sections
home_server = rad1_foo_telecom will be executed before the request is
home_server = rad2_foo_telecom proxied, and after the response is
}
realm foo.com { received from the Home-Server
auth_pool = foo_telecom_pool
nostrip
}
By default, if a Stripped-User-Name attribute is present in the control list, then its value
is used for the User-Name attribute in the request that is proxied to the Home-Server.
For example, the Home-Server will receive a request for joe, and not for joe%foo.com.
The nostrip option allows you to specify that you want to keep the original User-Name
(this can be useful if the Home-Server also acts as a proxy server for example).
• client-balance: also random, but all the requests from a given NAS
are always proxied to the same Home-Server (as long as it is alive)
• keyed-balance: again random, but all the requests that have the same
Load-Balance-Key attribute value will be proxied to the same Home-
Server
➡ A module must therefore add this attribute to the control list, for
example by copying the value of the User-Name attribute (so that all the
requests from a given user will be proxied to the same Home-Server)
• Many people define a real called LOCAL with no pool (it will
therefore be handled locally): you can then force a requests to be
handled locally by adding the attribute Proxy-To-Realm in the
control list, with its value set to «LOCAL»
• For example:
home_server virtual_home_server_for_foo {
virtual_server = virtual_server_for_foo
}
• This is useful for example to execute some code when all Home-
Servers of a pool have failed:
home_server_pool foo_telecom_pool {
type = fail-over This is a pool of type fail-over, so
home_server = rad1_foo_telecom rad1 is tried first, and if it fails, then it
home_server = rad2_foo_telecom tries rad2, and if it fails too, then the
home_server = virtual_home_server_for_foo
virtual server is called
}
home_server_pool foo_telecom_pool {
type = load-balance In this example, the load is balanced
home_server = rad1_foo_telecom between servers rad1 and rad2. If both
home_server = rad2_foo_telecom servers die, then the pool falls back to
fallback = virtual_home_server_for_foo
virtual_home_server_for_foo.
}
• This file specifies, for each realm, which attributes are acceptable,
and with what values: non-compliant attributes are removed
...
/etc/freeradius/attrs