How to configure group attributes for strongswan EAP-radius with freeradius mysql

3 min read 23-10-2024
How to configure group attributes for strongswan EAP-radius with freeradius mysql

In the world of network security, establishing a robust authentication system is crucial. Using StrongSwan for IPsec VPN and FreeRADIUS for Remote Authentication Dial-In User Service (RADIUS) offers a powerful combination for secure connections. However, configuring group attributes can sometimes be challenging. In this article, we’ll explain how to properly set up group attributes for StrongSwan EAP-RADIUS using FreeRADIUS with MySQL, ensuring a seamless integration of your authentication process.

Original Problem Scenario

The original problem scenario can be summarized as follows: How do I configure group attributes for StrongSwan EAP-RADIUS with FreeRADIUS MySQL?

Understanding the Configuration Process

To tackle this challenge effectively, let's first review the essential components of our setup:

  1. StrongSwan: An open-source VPN solution that supports IPsec and IKE protocols.
  2. FreeRADIUS: A high-performance RADIUS server capable of authenticating users.
  3. MySQL: A relational database management system used to store user data.

Step-by-Step Configuration

The following steps outline how to configure group attributes effectively.

1. Install Required Packages

Make sure you have StrongSwan and FreeRADIUS installed along with the FreeRADIUS MySQL module. You can install them using your package manager:

sudo apt-get update
sudo apt-get install strongswan freeradius freeradius-mysql

2. Configure the FreeRADIUS MySQL Module

Edit the sql.conf file located in /etc/freeradius/ directory to ensure FreeRADIUS can connect to your MySQL database:

# /etc/freeradius/sql.conf
driver = "rlm_sql_mysql"
server = "localhost"
login = "freeradius"
password = "your_password"
radius_db = "radius"

3. Create the MySQL Database and Tables

You will need to create the RADIUS database along with user and group tables. Use the following commands in MySQL:

CREATE DATABASE radius;
USE radius;

CREATE TABLE radcheck (
    id INT NOT NULL AUTO_INCREMENT,
    username VARCHAR(64) NOT NULL,
    attribute VARCHAR(64) NOT NULL,
    op VARCHAR(2) NOT NULL,
    value VARCHAR(253) NOT NULL,
    PRIMARY KEY (id)
);

CREATE TABLE radgroupreply (
    id INT NOT NULL AUTO_INCREMENT,
    groupname VARCHAR(64) NOT NULL,
    attribute VARCHAR(64) NOT NULL,
    op VARCHAR(2) NOT NULL,
    value VARCHAR(253) NOT NULL,
    PRIMARY KEY (id)
);

4. Add User and Group Entries

Insert user and group entries in the radcheck and radgroupreply tables respectively. This is crucial to establishing group attributes:

INSERT INTO radcheck (username, attribute, op, value) VALUES ('user1', 'Cleartext-Password', ':=', 'password1');
INSERT INTO radgroupreply (groupname, attribute, op, value) VALUES ('admins', 'Service-Type', ':=', 'NAS-Prompt-User');

5. Configure StrongSwan

In your StrongSwan configuration file (usually found at /etc/strongswan/ipsec.conf), enable EAP and specify the use of FreeRADIUS for authentication:

conn %default
    keyexchange=ikev2
    eap_identity=%identity

conn myvpn
    right=%any
    rightid=%wildcard
    rightauth=eap-radius
    eap=peap
    leftauth=pubkey
    leftcert=mycert.pem
    leftsendcert=always

6. Test Your Configuration

Once the configuration is complete, restart both FreeRADIUS and StrongSwan services and conduct tests to ensure that users are authenticated correctly based on group attributes.

sudo systemctl restart freeradius
sudo systemctl restart strongswan

Analysis and Practical Examples

Why Use Group Attributes?

Using group attributes in FreeRADIUS allows for efficient user management. You can assign different access levels based on user groups, making it easier to maintain security policies and manage user permissions.

For example, if you have a group named admins, you can easily assign them additional privileges such as access to sensitive internal resources.

Troubleshooting Common Issues

  1. Debugging Authentication Failures: If authentication fails, utilize the FreeRADIUS debug mode to see where the process may be breaking down:

    sudo freeradius -X
    
  2. Check Database Connections: Ensure that the FreeRADIUS service can connect to MySQL, check configurations, and verify that the MySQL server is running.

Useful Resources

Conclusion

Configuring group attributes for StrongSwan EAP-RADIUS with FreeRADIUS and MySQL can be complex, but by following the steps outlined in this guide, you can ensure a robust authentication system for your VPN setup. This approach not only enhances security but also simplifies user management. For further insights and troubleshooting, refer to the resources provided above. Happy configuring!