Setting Up FreeRADIUS with PAP & PostgreSQL (Development Environment)

This guide outlines the steps to configure a FreeRADIUS development environment using Docker, enabling PAP authentication against a PostgreSQL database.

Initial Host Machine Setup

Perform these steps in your project directory (e.g., freeradius-pg-docker).

1. Save Core Files:
2. Make Script Executable:

Run the following command:

chmod +x init-db.sh
3. Download Database Schema:

Get the PostgreSQL schema file:

curl -o schema.sql https://raw.githubusercontent.com/FreeRADIUS/freeradius-server/v3.2.x/raddb/mods-config/sql/main/postgresql/schema.sql
4. Set Secure Password:

IMPORTANT: Edit docker-compose.yml and replace BOTH instances of your_secure_password with a strong, unique password.

5. Create Host Directories:
mkdir ./raddb ./logs
6. Populate ./raddb with Default Config:

Copy the default FreeRADIUS configuration from the image to your host's ./raddb directory. You typically do this once.

# Build a temporary image first (if not already built)
docker build -t temp-freeradius-config .

# Copy config out from the temporary container
docker run --rm --entrypoint /bin/sh temp-freeradius-config -c "tar cf - -C /etc raddb" | tar xf - -C .

# Optionally remove the temporary image
# docker rmi temp-freeradius-config

Ensure the ./raddb directory exists and is populated before proceeding.

Configure FreeRADIUS (in ./raddb)

Edit the configuration files within your host's ./raddb directory. Changes made here will be reflected inside the container due to the volume mount specified in docker-compose.yml.

1. Configure SQL Module (./raddb/mods-available/sql):
2. Enable SQL Module (./raddb/mods-enabled/sql):
3. Configure Site Processing (./raddb/sites-enabled/default):

This file controls the main request flow. Modify the sections to integrate SQL and PAP.

4. Define RADIUS Clients (./raddb/clients.conf):
5. Configure PAP Users File (./raddb/users):

Key Configuration Files Overview (in ./raddb)

This section lists the primary files within your host's ./raddb directory that you'll typically interact with when configuring PAP and SQL (PostgreSQL) authentication:

./raddb/mods-available/sql

Purpose: Configures the core SQL module (rlm_sql).

Edits:

./raddb/mods-enabled/sql (Symlink)

Purpose: Enables the SQL module configured in mods-available/sql.

Action: This isn't a file you edit directly, but you must ensure it exists as a symbolic link pointing to ../mods-available/sql. You likely created this in the initial setup steps (ln -s ../mods-available/sql ./raddb/mods-enabled/sql).

./raddb/sites-enabled/default (and potentially inner-tunnel)

Purpose: Defines the request processing workflow (virtual server).

Edits: This is where you tell FreeRADIUS when and how to use the PAP and SQL modules within the different processing sections (authorize, authenticate, accounting, post-auth, session) as detailed in Step 3 of the configuration process above. You'll typically uncomment the sql entries or add them in the desired order relative to other modules like files, pap, chap, etc.

./raddb/users

Purpose: The default plain-text file for defining users, passwords (for PAP/CHAP if not using SQL for passwords), and attributes.

Edits:

./raddb/clients.conf

Purpose: Defines which RADIUS clients (NAS devices, switches, APs, VPN concentrators, test tools) are allowed to send requests and the shared secret for communication.

Edits: You absolutely need to edit this file to add the IP address and shared secret for any device sending requests, including localhost (IP 127.0.0.1) for testing with radtest.

Running and Testing

1. Start Services:
docker-compose up -d
2. Check Logs:

Monitor logs for errors or status messages:

docker-compose logs -f postgres freeradius
3. Add Test Users:
4. Test Authentication with radtest:

Development Workflow Summary

This Docker volume mount setup facilitates rapid development:

Remember to restart the freeradius service after saving changes to configuration files on your host for them to take effect. Carefully adapt the configurations to match your specific requirements.