RadSec Server
RadSec uses RADIUS over TLS on TCP port 2083. PyRad2's RadSec server uses secure TLS defaults:
- client certificates are required by default (
ssl.CERT_REQUIRED) - TLS 1.2 or newer is required by default
- the server can optionally restrict clients by SHA-256 certificate fingerprint
The examples include a local development CA, server certificate, and client
certificate under examples/certs. The bundled server certificate is valid for
localhost, 127.0.0.1, ::1, and radsec-server, so the example client can
run with hostname validation enabled.
These certificates and private keys are for local development only. For real
deployments, generate certificates from your own CA and make sure the server
certificate contains a subjectAltName entry for the DNS name or IP address
clients use to connect.
To pin which client certificates may connect, pass one or more SHA-256
certificate fingerprints with allowed_client_fingerprints:
server = RadSecServer(
hosts=hosts,
dictionary=dictionary,
certfile="certs/server/server.cert.pem",
keyfile="certs/server/server.key.pem",
ca_certfile="certs/ca/ca.cert.pem",
allowed_client_fingerprints={
"sha256:12:34:56:...",
},
)
Fingerprints may be plain lowercase/uppercase hex, colon-separated hex, or
prefixed with sha256:. PyRad2 normalizes the value before comparing it with
the SHA-256 fingerprint of the presented client certificate. If
allowed_client_fingerprints is omitted or empty, any certificate trusted by
ca_certfile is accepted.
The server reads packets in a loop on each accepted TLS connection. By default,
the connection stays open until the client disconnects. You can bound long-lived
connections with connection_read_timeout and max_packets_per_connection:
server = RadSecServer(
hosts=hosts,
dictionary=dictionary,
certfile="certs/server/server.cert.pem",
keyfile="certs/server/server.key.pem",
ca_certfile="certs/ca/ca.cert.pem",
connection_read_timeout=30,
max_packets_per_connection=1000,
)
Use verify_packet=True when the server should verify request authenticators
before dispatching to your handlers. Access-Request, Accounting, CoA, and
Disconnect packets are verified with their packet-specific verifier.
RadSec carries all RADIUS packet types on the same TLS/TCP listener. A subclass
must implement handle_access_request() and handle_accounting(). CoA and
Disconnect handlers are optional because they are Dynamic Authorization Server
behavior; by default PyRad2 responds to unsupported requests with CoA-NAK or
Disconnect-NAK and Error-Cause = Unsupported-Extension.
If a subclass does implement those handlers but you want to disable dispatch,
set enable_coa=False or enable_disconnect=False:
server = RadSecServer(
hosts=hosts,
dictionary=dictionary,
certfile="certs/server/server.cert.pem",
keyfile="certs/server/server.key.pem",
ca_certfile="certs/ca/ca.cert.pem",
enable_coa=False,
enable_disconnect=False,
)
Message-Authenticator policy
PyRad2 validates Message-Authenticator whenever the attribute is present. By
default, packets containing EAP-Message must include a valid
Message-Authenticator, while non-EAP packets remain compatible with older
clients.
To require Message-Authenticator on every incoming packet, enable
require_message_authenticator:
server = RadSecServer(
hosts=hosts,
dictionary=dictionary,
certfile="certs/server/server.cert.pem",
keyfile="certs/server/server.key.pem",
ca_certfile="certs/ca/ca.cert.pem",
require_message_authenticator=True,
)
Replies automatically include Message-Authenticator when the request included
one, when require_message_authenticator=True, or when the reply contains
EAP-Message.
RadSec servers answer RFC 5997 Status-Server health checks directly with
Access-Accept. Status-Server requests must include a valid
Message-Authenticator and do not invoke normal authentication, accounting, or
CoA handlers.
Use examples/status_radsec.py to send a Status-Server request to
examples/server_radsec.py. The plain examples/status.py script uses UDP
RADIUS on port 1812 and will not reach a RadSec server listening on TLS/TCP
port 2083.
RadSecServer
A RadSec as per RFC6614.
UDP + MD5 has proven to be a combination that has not survived the test of time. Hence, the RADIUS standard adopted RADSEC as a fundamentally more secure approach.
RADSEC effectively means performing communications over TCP instead of UDP (generally on port 2083) and use TLS as a security layer.
RADSEC is the same as “Radius Over TLS” or Radius/TLS.
The default destination port number for RADIUS over TLS is TCP/2083. There are no separate ports for authentication, accounting, and dynamic authorization changes.
Source code in pyrad2/radsec/server.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 | |
__init__(listen_address='0.0.0.0', listen_port=2083, hosts=None, dictionary=None, verify_packet=False, certfile='certs/server/server.cert.pem', keyfile='certs/server/server.key.pem', ca_certfile='certs/ca/ca.cert.pem', verify_mode=ssl.CERT_REQUIRED, minimum_tls_version=DEFAULT_MINIMUM_TLS_VERSION, ciphers=None, allowed_client_fingerprints=None, connection_read_timeout=None, max_packets_per_connection=None, require_message_authenticator=False, require_eap_message_authenticator=True, enable_coa=True, enable_disconnect=True, radius_versions=(RadiusVersion.V1_0,))
Initializes a RadSec server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
listen_address
|
str
|
IP address to bind to, defaults to 0.0.0.0 |
'0.0.0.0'
|
listen_port
|
int
|
Deafaults to 2083. |
2083
|
hosts
|
dict[str, RemoteHost]
|
Hosts who we can talk to. A dictionary mapping IP to RemoteHost class instances. |
None
|
dictionary
|
Dictionary
|
RADIUS dictionary to use. |
None
|
verify_packet
|
bool
|
If true, the packet will be verified against its secret |
False
|
certfile
|
str
|
Path to server SSL certificate |
'certs/server/server.cert.pem'
|
keyfile
|
str
|
Path to server SSL certificate |
'certs/server/server.key.pem'
|
ca_certfile
|
str
|
Path to server CA certfificate |
'certs/ca/ca.cert.pem'
|
verify_mode
|
VerifyMode
|
Client certificate verification mode. |
CERT_REQUIRED
|
minimum_tls_version
|
TLSVersion
|
Lowest TLS version to negotiate. |
DEFAULT_MINIMUM_TLS_VERSION
|
ciphers
|
str
|
Optional OpenSSL cipher string override. |
None
|
allowed_client_fingerprints
|
Iterable[str]
|
Optional SHA-256 certificate fingerprint allowlist for client certificates. |
None
|
connection_read_timeout
|
float
|
Optional timeout while waiting for the next packet on an established TLS connection. |
None
|
max_packets_per_connection
|
int
|
Optional packet limit before closing an accepted TLS connection. |
None
|
require_message_authenticator
|
bool
|
Require Message-Authenticator on incoming packets. |
False
|
require_eap_message_authenticator
|
bool
|
Require Message-Authenticator on packets containing EAP-Message. |
True
|
enable_coa
|
bool
|
Dispatch CoA-Request packets to |
True
|
enable_disconnect
|
bool
|
Dispatch Disconnect-Request packets to
|
True
|
radius_versions
|
Sequence[RadiusVersion]
|
RFC 9765 protocol
versions to advertise via ALPN. Defaults to |
(V1_0,)
|
Source code in pyrad2/radsec/server.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
handle_access_request(packet)
abstractmethod
async
handle_accounting(packet)
abstractmethod
async
Handle an Accounting-Request or Accounting-Response packet.
handle_coa(packet)
async
Handle an unsupported CoA-Request with a CoA-NAK by default.
Override this method when the RadSec server is acting as a Dynamic Authorization Server and can apply authorization changes.
Source code in pyrad2/radsec/server.py
handle_disconnect(packet)
async
Handle an unsupported Disconnect-Request with a NAK by default.
Override this method when the RadSec server is acting as a Dynamic Authorization Server and can terminate sessions.