Unofficial Free Radius Docker With SQL Database Image
205
For usage this image, you can create a directory structure are below:
services:
freeradius-db:
image: postgres:17
container_name: freeradius-db
environment:
POSTGRES_DB: freeradius
POSTGRES_USER: freeradius
POSTGRES_PASSWORD: rtGzNNQzvvBXd3qw0mxx
volumes:
- freeradius-db-data:/var/lib/postgresql/freeradius-db-data
- ./config/pgsql/pg_hba.conf:/var/lib/postgresql/freeradius-db-data/pg_hba.conf
- ./config/radius/freeradius_schema.sql:/docker-entrypoint-initdb.d/schema.sql
- ./config/radius/custom.sql:/docker-entrypoint-initdb.d/custom.sql
networks:
- freeradius-network
healthcheck:
test: ["CMD", "pg_isready", "-U", "freeradius"]
interval: 1m30s
timeout: 30s
retries: 5
start_period: 30s
ports:
- "5433:5432"
restart: unless-stopped
freeradius-server:
container_name: freeradius-server
build:
context: ./config/docker
dockerfile: Dockerfile
networks:
- freeradius-network
extra_hosts:
- "host.docker.internal:host-gateway"
ports:
- 1812:1812/udp
- 1813:1813/udp
depends_on:
freeradius-db:
condition: service_started
volumes:
freeradius-db-data:
networks:
freeradius-network:
driver: bridge
Inside config then docker folder. Create Dockerfile file, and you can copy and paste the following content:
FROM teguh02/freeradius-server:pgsql
# Change the connection info in the /etc/freeradius/3.0/mods-available/sql file
# You can adjust the connection info to match your PostgreSQL database
# search server = "localhost" and replace it with your own server for example (another-host)
RUN sed -i 's/server = "localhost"/server = "freeradius-db"/g' /etc/freeradius/3.0/mods-available/sql
# search port = 5432 and replace it with your own port for example (5433)
# RUN sed -i 's/port = 5432/port = 5433/g' /etc/freeradius/3.0/mods-available/sql
# search login = "postgres" and replace it with your own username for example (freeradius)
RUN sed -i 's/login = "postgres"/login = "freeradius"/g' /etc/freeradius/3.0/mods-available/sql
# search password = "radpass" and replace it with your own password for example (rtGzNNQzvvBXd3qw0mxx)
RUN sed -i 's/password = "radpass"/password = "rtGzNNQzvvBXd3qw0mxx"/g' /etc/freeradius/3.0/mods-available/sql
# search radius_db = "freeradius" and replace it with your own database name for example (freeradius-db)
RUN sed -i 's/radius_db = "freeradius"/radius_db = "freeradius-db"/g' /etc/freeradius/3.0/mods-available/sql
# Expose the FreeRADIUS port
EXPOSE 1812/udp 1813/udp
# Stop first and Run the FreeRADIUS service
RUN service freeradius stop
CMD ["/usr/sbin/freeradius", "-X"]
You can adjust the free radius database connection use the Dockerfile instead of you are manual editing the freeradius sql file configuration
Inside the config then pgsql folder, please create pg_hba.conf file to configure PostgreSQL allowed host and the encryption algorithm, in this image you're must use scram-sha-256 algorithm
# PostgreSQL Client Authentication Configuration File
# ===================================================
#
# Refer to the "Client Authentication" section in the PostgreSQL
# documentation for a complete description of this file. A short
# synopsis follows.
#
# ----------------------
# Authentication Records
# ----------------------
#
# This file controls: which hosts are allowed to connect, how clients
# are authenticated, which PostgreSQL user names they can use, which
# databases they can access. Records take one of these forms:
#
# local DATABASE USER METHOD [OPTIONS]
# host DATABASE USER ADDRESS METHOD [OPTIONS]
# hostssl DATABASE USER ADDRESS METHOD [OPTIONS]
# hostnossl DATABASE USER ADDRESS METHOD [OPTIONS]
# hostgssenc DATABASE USER ADDRESS METHOD [OPTIONS]
# hostnogssenc DATABASE USER ADDRESS METHOD [OPTIONS]
#
# (The uppercase items must be replaced by actual values.)
#
# The first field is the connection type:
# - "local" is a Unix-domain socket
# - "host" is a TCP/IP socket (encrypted or not)
# - "hostssl" is a TCP/IP socket that is SSL-encrypted
# - "hostnossl" is a TCP/IP socket that is not SSL-encrypted
# - "hostgssenc" is a TCP/IP socket that is GSSAPI-encrypted
# - "hostnogssenc" is a TCP/IP socket that is not GSSAPI-encrypted
#
# DATABASE can be "all", "sameuser", "samerole", "replication", a
# database name, a regular expression (if it starts with a slash (/))
# or a comma-separated list thereof. The "all" keyword does not match
# "replication". Access to replication must be enabled in a separate
# record (see example below).
#
# USER can be "all", a user name, a group name prefixed with "+", a
# regular expression (if it starts with a slash (/)) or a comma-separated
# list thereof. In both the DATABASE and USER fields you can also write
# a file name prefixed with "@" to include names from a separate file.
#
# ADDRESS specifies the set of hosts the record matches. It can be a
# host name, or it is made up of an IP address and a CIDR mask that is
# an integer (between 0 and 32 (IPv4) or 128 (IPv6) inclusive) that
# specifies the number of significant bits in the mask. A host name
# that starts with a dot (.) matches a suffix of the actual host name.
# Alternatively, you can write an IP address and netmask in separate
# columns to specify the set of hosts. Instead of a CIDR-address, you
# can write "samehost" to match any of the server's own IP addresses,
# or "samenet" to match any address in any subnet that the server is
# directly connected to.
#
# METHOD can be "trust", "reject", "md5", "password", "scram-sha-256",
# "gss", "sspi", "ident", "peer", "pam", "ldap", "radius" or "cert".
# Note that "password" sends passwords in clear text; "md5" or
# "scram-sha-256" are preferred since they send encrypted passwords.
#
# OPTIONS are a set of options for the authentication in the format
# NAME=VALUE. The available options depend on the different
# authentication methods -- refer to the "Client Authentication"
# section in the documentation for a list of which options are
# available for which authentication methods.
#
# Database and user names containing spaces, commas, quotes and other
# special characters must be quoted. Quoting one of the keywords
# "all", "sameuser", "samerole" or "replication" makes the name lose
# its special character, and just match a database or username with
# that name.
#
# ---------------
# Include Records
# ---------------
#
# This file allows the inclusion of external files or directories holding
# more records, using the following keywords:
#
# include FILE
# include_if_exists FILE
# include_dir DIRECTORY
#
# FILE is the file name to include, and DIR is the directory name containing
# the file(s) to include. Any file in a directory will be loaded if suffixed
# with ".conf". The files of a directory are ordered by name.
# include_if_exists ignores missing files. FILE and DIRECTORY can be
# specified as a relative or an absolute path, and can be double-quoted if
# they contain spaces.
#
# -------------
# Miscellaneous
# -------------
#
# This file is read on server startup and when the server receives a
# SIGHUP signal. If you edit the file on a running system, you have to
# SIGHUP the server for the changes to take effect, run "pg_ctl reload",
# or execute "SELECT pg_reload_conf()".
#
# ----------------------------------
# Put your actual configuration here
# ----------------------------------
#
# If you want to allow non-local connections, you need to add more
# "host" records. In that case you will also need to make PostgreSQL
# listen on a non-local interface via the listen_addresses
# configuration parameter, or via the -i or -h command line switches.
# DO NOT DISABLE!
# If you change this first entry you will need to make sure that the
# database superuser can access the database using some other method.
# Noninteractive access to all databases is required during automatic
# maintenance (custom daily cronjobs, replication, and similar tasks).
#
# Database administrative login by Unix domain socket
local all postgres scram-sha-256
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all scram-sha-256
# IPv4 local connections:
host all all 127.0.0.1/32 scram-sha-256
host freeradius all 0.0.0.0/0 scram-sha-256
host radius all 0.0.0.0/0 scram-sha-256
# IPv6 local connections:
host all all ::1/128 scram-sha-256
# Allow replication connections from localhost, by a user with the
# replication privilege.
local replication all scram-sha-256
host replication all 127.0.0.1/32 scram-sha-256
host replication all ::1/128 scram-sha-256
Inside config folder then radius folder, create freeradius_schema.sql file, this file are free radius tables definition scheme.
/*
*
* PostgreSQL schema for FreeRADIUS
*
*/
/*
* Table structure for table 'radacct'
*
*/
CREATE TABLE IF NOT EXISTS radacct (
RadAcctId bigserial PRIMARY KEY,
AcctSessionId text NOT NULL,
AcctUniqueId text NOT NULL UNIQUE,
UserName text,
Realm text,
NASIPAddress inet NOT NULL,
NASPortId text,
NASPortType text,
AcctStartTime timestamp with time zone,
AcctUpdateTime timestamp with time zone,
AcctStopTime timestamp with time zone,
AcctInterval bigint,
AcctSessionTime bigint,
AcctAuthentic text,
ConnectInfo_start text,
ConnectInfo_stop text,
AcctInputOctets bigint,
AcctOutputOctets bigint,
CalledStationId text,
CallingStationId text,
AcctTerminateCause text,
ServiceType text,
FramedProtocol text,
FramedIPAddress inet,
FramedIPv6Address inet,
FramedIPv6Prefix inet,
FramedInterfaceId text,
DelegatedIPv6Prefix inet,
Class text
);
-- For use by update-, stop- and simul_* queries
CREATE INDEX radacct_active_session_idx ON radacct (AcctUniqueId) WHERE AcctStopTime IS NULL;
-- For use by on-off-
CREATE INDEX radacct_bulk_close ON radacct (NASIPAddress, AcctStartTime) WHERE AcctStopTime IS NULL;
-- and for common statistic queries:
CREATE INDEX radacct_start_user_idx ON radacct (AcctStartTime, UserName);
-- and for Class
CREATE INDEX radacct_calss_idx ON radacct (Class);
/*
* Table structure for table 'radcheck'
*/
CREATE TABLE IF NOT EXISTS radcheck (
id serial PRIMARY KEY,
UserName text NOT NULL DEFAULT '',
Attribute text NOT NULL DEFAULT '',
op VARCHAR(2) NOT NULL DEFAULT '==',
Value text NOT NULL DEFAULT ''
);
create index radcheck_UserName on radcheck (UserName,Attribute);
/*
* Table structure for table 'radgroupcheck'
*/
CREATE TABLE IF NOT EXISTS radgroupcheck (
id serial PRIMARY KEY,
GroupName text NOT NULL DEFAULT '',
Attribute text NOT NULL DEFAULT '',
op VARCHAR(2) NOT NULL DEFAULT '==',
Value text NOT NULL DEFAULT ''
);
create index radgroupcheck_GroupName on radgroupcheck (GroupName,Attribute);
/*
* Table structure for table 'radgroupreply'
*/
CREATE TABLE IF NOT EXISTS radgroupreply (
id serial PRIMARY KEY,
GroupName text NOT NULL DEFAULT '',
Attribute text NOT NULL DEFAULT '',
op VARCHAR(2) NOT NULL DEFAULT '=',
Value text NOT NULL DEFAULT ''
);
create index radgroupreply_GroupName on radgroupreply (GroupName,Attribute);
/*
* Table structure for table 'radreply'
*/
CREATE TABLE IF NOT EXISTS radreply (
id serial PRIMARY KEY,
UserName text NOT NULL DEFAULT '',
Attribute text NOT NULL DEFAULT '',
op VARCHAR(2) NOT NULL DEFAULT '=',
Value text NOT NULL DEFAULT ''
);
create index radreply_UserName on radreply (UserName,Attribute);
/*
* Table structure for table 'radusergroup'
*/
CREATE TABLE IF NOT EXISTS radusergroup (
id serial PRIMARY KEY,
UserName text NOT NULL DEFAULT '',
GroupName text NOT NULL DEFAULT '',
priority integer NOT NULL DEFAULT 0
);
create index radusergroup_UserName on radusergroup (UserName);
--
-- Table structure for table 'radpostauth'
--
CREATE TABLE IF NOT EXISTS radpostauth (
id bigserial PRIMARY KEY,
username text NOT NULL,
pass text,
reply text,
CalledStationId text,
CallingStationId text,
authdate timestamp with time zone NOT NULL default now(),
Class text
);
CREATE INDEX radpostauth_username_idx ON radpostauth (username);
CREATE INDEX radpostauth_class_idx ON radpostauth (Class);
/*
* Table structure for table 'nas'
*/
CREATE TABLE IF NOT EXISTS nas (
id serial PRIMARY KEY,
nasname text NOT NULL,
shortname text NOT NULL,
type text NOT NULL DEFAULT 'other',
ports integer,
secret text NOT NULL,
server text,
community text,
description text
);
create index nas_nasname on nas (nasname);
/*
* Table structure for table 'nasreload'
*/
CREATE TABLE IF NOT EXISTS nasreload (
NASIPAddress inet PRIMARY KEY,
ReloadTime timestamp with time zone NOT NULL
);
Inside the config then radius folder, please create custom.sql to insert several users and nas to testing purpose
-- Insert new user for testing
INSERT INTO radcheck (UserName, Attribute, op, Value) VALUES ('kiki', 'Cleartext-Password', ':=', '1234');
INSERT INTO radcheck (UserName, Attribute, op, Value) VALUES ('teguh02', 'MD5-Password', ':=', '5f4dcc3b5aa765d61d8327deb882cf99');
-- 5f4dcc3b5aa765d61d8327deb882cf99 = md5('password')
-- For Radius testing you can run
-- radtest kiki 1234 localhost 0 testing123
-- radtest teguh02 password localhost 0 testing123
-- Create new nas test server
INSERT INTO nas (nasname, shortname, type, ports, secret, community, description) VALUES ('127.0.0.1', 'localhost', 'other', 0, 'testing123', NULL, 'Local NAS for testing');
After that, you can run these command to run your radius server
docker compose up -d --build
For test your radius authentication, you can enter your container with these command
docker exec -it freeradius-server sh
and enter this command
radtest kiki 1234 localhost 0 testing123
Content type
Image
Digest
sha256:b56d7adc9…
Size
77.1 MB
Last updated
almost 2 years ago
docker pull teguh02/freeradius-server:pgsql