<ServerTACACSPLUS>.TACACSContextSQL is used with
ServerTACACSPLUS when TACACS+ authorization requests
may arrive at a Radiator instance that does not have the required
authentication context in memory. This can happen, for example, after a
server restart or when TACACS+ authentication and authorization requests
are routed to different Radiator instances. The context database can be
shared by multiple Radiator instances. It can also be used by a single
Radiator server to share contexts between FarmSize
worker processes, or in simple setups to persist TACACS+ contexts over
Radiator restartsTACACSContextSQL stores the TACACS+ context
created after a successful authentication. The stored data includes the
user name, peer address and port information, TACACS+ port and remote
address information, creation and expiry times, and the reply attributes
that are needed later for TACACS+ authorization processing. When an
authorization request is received and the context is not available in
memory, ServerTACACSPLUS can fetch the context from
the SQL database by using the TACACSContextSQL
object.TACACSContextSQL object is selected by
configuring its Identifier and referring to that
identifier from ServerTACACSPLUS with the
TACACSContext parameter. Here is an example:<TACACSContextSQL>
Identifier TACACSCTXDB
DBSource dbi:mysql:tacacs;host=%{GlobalVar:dbserver};port=3306
DBUsername %{GlobalVar:dbusername}
DBAuth %{GlobalVar:dbpassword}
PurgeInterval 600
ContextTimeout 300
</TACACSContextSQL>
<ServerTACACSPLUS>
TACACSContext TACACSCTXDB
AuthorizationTimeout 100
...
</ServerTACACSPLUS>
<TACACSContextSQL> uses by defining one or more
sets of DBSource, DBUsername and
DBAuth parameters. It supports the common SQL
configuration parameters.ContextTimeout in
TACACSContextSQL may be different from
AuthorizationTimeout in
<ServerTACACSPLUS>. This allows contexts to be
kept in memory for a shorter time while remaining available from the
database for a longer time. When a context is read from the database, the
in-memory context on that Radiator instance is currently given the full
AuthorizationTimeout.tacacsplusserver-context.cfg for
a sample configuration file and
tacacsplusserver-context.sql for the SQL tables
matching the default SQL queries.TACACS_CONTEXT# Table for wired switch management Table TAC_CONTEXT_WIRED
<TACACSContextSQL> first runs
DeleteContextQuery for the same
context_key and then runs
AddContextQuery. If
ReplaceContextQuery is defined,
ReplaceContextQuery is used instead of the delete and
add sequence. Special formatting characters are supported.context_key.INSERT INTO TACACS_CONTEXT (context_key,username,peer_ip,peer_port,tacacs_port, tacacs_rem_addr,created_at,expires_at,rp_attrs) VALUES (%0,%1,%2,%3,%4,%5,%6,%7,%8)
AddContextQueryParam parameters are defined,
AddContextQuery is used with SQL bind variables
instead. Special formatting characters in
AddContextQueryParam are replaced before being bound
to the SQL statement.AddContextQueryParam:context_key.AddContextQuery INSERT INTO TACACS_CONTEXT \
(context_key,username,peer_ip,peer_port,tacacs_port, \
tacacs_rem_addr,created_at,expires_at,rp_attrs) \
VALUES (?,?,?,?,?,?,?,?,?)
AddContextQueryParam %0
AddContextQueryParam %1
AddContextQueryParam %2
AddContextQueryParam %3
AddContextQueryParam %4
AddContextQueryParam %5
AddContextQueryParam %6
AddContextQueryParam %7
AddContextQueryParam %8
ServerTACACSPLUS needs
context information that is not available in memory.GetContextQuery, that matches the default
AddContextQuery, must return these columns, in this
order: usernamepeer_ippeer_porttacacs_porttacacs_rem_addrcreated_atexpires_atrp_attrscontext_key.SELECT username,peer_ip,peer_port,tacacs_port,tacacs_rem_addr,
created_at,expires_at,rp_attrs
FROM TACACS_CONTEXT
WHERE context_key=%0 AND expires_at >= %1
GetContextQueryParam
parameters are defined, GetContextQuery is used with
SQL bind variables instead. Special formatting characters in
GetContextQueryParam are replaced before being bound
to the SQL query. GetContextQueryParam:
context_key.GetContextQuery SELECT username,peer_ip,peer_port,tacacs_port,tacacs_rem_addr, \
created_at,expires_at,rp_attrs \
FROM TACACS_CONTEXT \
WHERE context_key=? AND expires_at >= ?
GetContextQueryParam %0
GetContextQueryParam %1
context_key. Unless
ReplaceContextQuery is defined,
DeleteContextQuery is normally run before
AddContextQuery when storing a context. This clears
any existing row for the same context_key. Special
formatting characters are supported.context_key.DELETE FROM TACACS_CONTEXT WHERE context_key=%0
DeleteContextQueryParam parameters are
defined, DeleteContextQuery is used with SQL bind
variables instead. Special formatting characters in
DeleteContextQueryParam are replaced before being
bound to the SQL statement.DeleteContextQueryParam:context_key.DeleteContextQuery DELETE FROM TACACS_CONTEXT WHERE context_key=? DeleteContextQueryParam %0
ReplaceContextQuery is defined, it is used instead
of the default DeleteContextQuery and
AddContextQuery sequence. This can be more efficient
or atomic when the database supports a native replacement or upsert
syntax.-- SQLite INSERT OR REPLACE INTO TACACS_CONTEXT (context_key, username, peer_ip, peer_port, tacacs_port, tacacs_rem_addr, created_at, expires_at, rp_attrs) VALUES (%0,%1,%2,%3,%4,%5,%6,%7,%8) -- MySQL/MariaDB REPLACE INTO TACACS_CONTEXT (context_key, username, peer_ip, peer_port, tacacs_port, tacacs_rem_addr, created_at, expires_at, rp_attrs) VALUES (%0,%1,%2,%3,%4,%5,%6,%7,%8) -- PostgreSQL INSERT INTO TACACS_CONTEXT (context_key, username, peer_ip, peer_port, tacacs_port, tacacs_rem_addr, created_at, expires_at, rp_attrs) VALUES (%0,%1,%2,%3,%4,%5,%6,%7,%8) ON CONFLICT (context_key) DO UPDATE SET username=EXCLUDED.username, peer_ip=EXCLUDED.peer_ip, peer_port=EXCLUDED.peer_port, tacacs_port=EXCLUDED.tacacs_port, tacacs_rem_addr=EXCLUDED.tacacs_rem_addr, created_at=EXCLUDED.created_at, expires_at=EXCLUDED.expires_at, rp_attrs=EXCLUDED.rp_attrs
AddContextQuery. By default,
ReplaceContextQuery is not defined. ReplaceContextQueryParam parameters are
defined, ReplaceContextQuery is used with SQL bind
variables instead. Special formatting characters in
ReplaceContextQueryParam are replaced before being
bound to the SQL statement. The special formatting values are the same as
for AddContextQueryParam.DELETE FROM TACACS_CONTEXT WHERE expires_at < %0
PurgeExpiredQuery
is only run automatically when PurgeInterval is set
to a non-zero value. It can be enabled on every Radiator instance that
uses the database, or on only some instances. For large databases, it is
also possible to run purging from a dedicated instance. PurgeExpiredQueryParam parameters are defined,
PurgeExpiredQuery is used with SQL bind variables
instead. Special formatting characters in
PurgeExpiredQueryParam are replaced before being
bound to the SQL statement.PurgeExpiredQueryParam:PurgeExpiredQuery DELETE FROM TACACS_CONTEXT WHERE expires_at < ? PurgeExpiredQueryParam %0
PurgeInterval is
unset or set to 0, automatic purging is not
scheduled.# Run purge every 10 minutes PurgeInterval 600
ContextTimeout is not set,
<TACACSContextSQL> uses the
AuthorizationTimeout value from its
<ServerTACACSPLUS> clause when storing
contexts. ContextTimeout 300
rp_attrs column. Customised queries can used the
respective % formatter with their definitions. If
StoreJSON is enabled and a JSON backend is available,
reply attributes are stored as JSON.
[["tacacsgroup","group1"]]
StoreJSON is disabled, or JSON storage is not
available, reply attributes are stored in a line based format:
attribute=value attribute=value