Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Added openwisp_radius installation #223

Closed
wants to merge 38 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
b1333c0
[feature] Added openwisp_radius installation
atb00ker Nov 29, 2020
4640bdc
Commented out mysql and postgres install.
nemesifier Dec 23, 2020
c36f1c8
Do not remove eap
nemesifier Dec 23, 2020
e989b1d
Do not modify clients (we'll configure sql module to read from DB)
nemesifier Dec 23, 2020
761a006
Avoid modifying the main radius config file since it shouldn't be needed
nemesifier Dec 23, 2020
055e443
Added possibility of turning off installation of freeradius
nemesifier Dec 23, 2020
ad13152
Add way to disable radius URLs if deployd on a different VM
nemesifier Dec 23, 2020
761327e
Simplified sql configuration
nemesifier Dec 23, 2020
31940d3
SQL: added read_clients = yes
nemesifier Dec 23, 2020
b6f9b3d
django-freeradius > openwisp-radius
nemesifier Dec 23, 2020
03156ab
Moved OPENWISP_USERS_AUTH_API out of the if openwisp_radius block
nemesifier Dec 23, 2020
a1e154e
Removed redundant urls
nemesifier Dec 23, 2020
c4b956b
Fixed redundant PRIVATE_STORAGE_ROOT definition
nemesifier Dec 24, 2020
21b2720
[chores] Install libpq-dev if using postgres
nemesifier Dec 24, 2020
c65d2bd
[feature] Added openwisp_radius installation
atb00ker Nov 29, 2020
fed2967
[radius] Removed database setup + minor
atb00ker Jan 1, 2021
6136f07
[chores] Import freeradius.yml only when openwisp2_radius is true
nemesifier Jan 7, 2021
6ea3bbe
[fix] Schedule openwisp-radius tasks only if radius enabled
nemesifier Jan 8, 2021
797e868
[radius] Removed database setup + minor
atb00ker Jan 1, 2021
69fad3e
[freeradius] Fix eap error
atb00ker Jan 9, 2021
37703eb
[fix] Fixed SQL parameters: host > server, user > login
nemesifier Jan 20, 2021
1332b1d
[chores] Added missing modules in authorize section
nemesifier Jan 20, 2021
c98e6c1
[chores] Fixed indentation of sql module
nemesifier Jan 20, 2021
b63c337
[fix] Fixed sql counter
nemesifier Jan 20, 2021
325ac68
[fix] Added patched postgresql counters
nemesifier Jan 21, 2021
7db00ab
[chores] Minor improvements
nemesifier Jan 21, 2021
f7f3468
[chores] Removed duplicated noresetcounter
nemesifier Jan 22, 2021
9c6ff64
[change] Adjusted interval of cron tasks
nemesifier Feb 5, 2021
3b035c5
[chores] Allow disabling openwisp_radius.tasks.delete_old_radacct
nemesifier Feb 5, 2021
1255daf
[chores] Added more notes to variables
nemesifier Feb 5, 2021
6680a18
[openwisp-radius] Add test to ensure freeradius is working
atb00ker Feb 8, 2021
ef14796
[chores] Added basic inner-tunnel
nemesifier Apr 24, 2021
8c0bbc8
[freeradius] Fixed problems prohibiting start
atb00ker Apr 28, 2021
9ab2950
Merge branch 'master' into openwisp_radius
nemesifier Jun 29, 2021
cd2eb08
Merge branch 'master' into openwisp_radius
nemesifier Aug 13, 2021
8bebc28
[fix] Added safe_characters to freeradius SQL conf
nemesifier Aug 13, 2021
2b717b1
Merge branch 'master' into openwisp_radius
nemesifier Sep 17, 2021
88c9acc
Merge branch 'master' into openwisp_radius
nemesifier Sep 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[radius] Removed database setup + minor
atb00ker committed Apr 27, 2021
commit fed2967f7e242671188eb2f5f59bb458509993e8
147 changes: 129 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -385,10 +385,6 @@ create an empty file named `playbook.yml` which contains the following:
# the following line is needed only when an IP address is used as the inventory hostname
vars:
postfix_myhostname: localhost
# Enable the modules you want to use
openwisp2_network_topology: true
openwisp2_firmware_upgrader: true
openwisp2_radius: true
```

**Step 6**: Run the playbook
@@ -405,6 +401,127 @@ username: admin
password: admin
```

Enabling the network topology module
------------------------------------

To enable the network topology module you need to set `openwisp2_network_topology` to `true` in
your `playbook.yml` file. Here's a short summary of how to do this:

**Step 1**: [Install ansible](#install-ansible)

**Step 2**: [Install this role](#install-this-role)

**Step 3**: [Create inventory file](#create-inventory-file)

**Step 4**: Create a playbook file with following contents:

```yaml
- hosts: openwisp2
become: "{{ become | default('yes') }}"
roles:
- openwisp.openwisp2
vars:
openwisp2_network_topology: true
```

**Step 5**: [Run the playbook](#run-the-playbook)

When the playbook is done running, if you got no errors you can login at:

https://openwisp2.mydomain.com/admin
username: admin
password: admin

Enabling the firmware upgrader module
-------------------------------------

**Note**: It is encouraged that you read the [quick-start guide of openwisp-firmware-upgrader](https://github.com/openwisp/openwisp-firmware-upgrader#quickstart)
before going ahead.

To enable the firmware upgrader module you need to set `openwisp2_firmware_upgrader` to `true` in
your `playbook.yml` file. Here's a short summary of how to do this:

**Step 1**: [Install ansible](#install-ansible)

**Step 2**: [Install this role](#install-this-role)

**Step 3**: [Create inventory file](#create-inventory-file)

**Step 4**: Create a playbook file with following contents:

```yaml
- hosts: openwisp2
become: "{{ become | default('yes') }}"
roles:
- openwisp.openwisp2
vars:
openwisp2_firmware_upgrader: true
```

**Step 5**: [Run the playbook](#run-the-playbook)

When the playbook is done running, if you got no errors you can login at:

https://openwisp2.mydomain.com/admin
username: admin
password: admin

**Note**: You can configure [openwisp-firmware-upgrader specific settings](https://github.com/openwisp/openwisp-firmware-upgrader#settings)
using `openwisp2_extra_django_settings` variable of this ansible role.
For example if you want to enable the [APIs of openwisp-firmware-upgrader](https://github.com/openwisp/openwisp-firmware-upgrader#rest-api),
you will update the above playbook as follows:

```yaml
- hosts: openwisp2
become: "{{ become | default('yes') }}"
roles:
- openwisp.openwisp2
vars:
openwisp2_firmware_upgrader: true
openwisp2_extra_django_settings:
OPENWISP_USERS_AUTH_API: true
OPENWISP_FIRMWARE_UPGRADER_API: true
```

Enabling the radius module
--------------------------

To enable the radius module you need to set `openwisp2_radius` to `true` in
your `playbook.yml` file. Here's a short summary of how to do this:

**Step 1**: [Install ansible](#install-ansible)

**Step 2**: [Install this role](#install-this-role)

**Step 3**: [Create inventory file](#create-inventory-file)

**Step 4**: Create a playbook file with following contents:

```yaml
- hosts: openwisp2
become: "{{ become | default('yes') }}"
roles:
- openwisp.openwisp2
vars:
openwisp2_radius: true
openwisp2_freeradius_install: true
# set to false when you don't want to register openwisp-radius
# API endpoints.
openwisp2_radius_urls: true
```

**Note:** `openwisp2_freeradius_install` option provides a basic configuration of freeradius for openwisp,
it sets up the [radius user token mechanism](https://openwisp-radius.readthedocs.io/en/latest/user/api.html#radius-user-token-recommended) if you want to use another mechanism or manage your freeradius separately,
please disable this option by setting it to `false`.

**Step 5**: [Run the playbook](#run-the-playbook)

When the playbook is done running, if you got no errors you can login at:

https://openwisp2.mydomain.com/admin
username: admin
password: admin

Troubleshooting
===============

@@ -509,10 +626,14 @@ Below are listed all the variables you can customize (you may also want to take
openwisp2_firmware_upgrader_version: "0.1"
openwisp2_radius_version: "0.1"
# Enable the modules you want to use
openwisp2_network_topology: true
openwisp2_firmware_upgrader: true
openwisp2_radius: true
openwisp2_radius_urls: true
openwisp2_network_topology: false
openwisp2_firmware_upgrader: false
openwisp2_radius: false
# when openwisp2_radius_urls is set to false, the radius module
# is setup but it's urls are not added, which means API and social
# views cannot be used, this is helpful if you have an external
# radius instance.
openwisp2_radius_urls: "{{ openwisp2_radius }}"
# you may replace the values of these variables with any URL
# supported by pip (the python package installer)
# use these to install forks, branches or development versions
@@ -707,18 +828,8 @@ Below are listed all the variables you can customize (you may also want to take
freeradius_mods_enabled_dir: "{{ freeradius_dir }}/mods-enabled"
freeradius_sites_available_dir: "{{ freeradius_dir }}/sites-available"
freeradius_sites_enabled_dir: "{{ freeradius_dir }}/sites-enabled"
freeradius_sql:
driver: rlm_sql_sqlite
dialect: sqlite
host: ""
port: ""
dbname: ""
user: ""
password: ""
freeradius_rest:
url: "https://{{ inventory_hostname }}/api/v1/freeradius"
freeradius_clients_ip: "0.0.0.0/0"
freeradius_clients_key: "admin"
cron_delete_old_notifications: "'hour': 0, 'minute': 0"
cron_deactivate_expired_users: "'hour': 0, 'minute': 0"
cron_delete_old_users: "'hour': 0, 'minute': 10"
21 changes: 10 additions & 11 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -125,22 +125,21 @@ freeradius_mods_enabled_dir: "{{ freeradius_dir }}/mods-enabled"
freeradius_sites_available_dir: "{{ freeradius_dir }}/sites-available"
freeradius_sites_enabled_dir: "{{ freeradius_dir }}/sites-enabled"
freeradius_db_map:
django.contrib.gis.db.backends.spatialite:
driver: rlm_sql_sqlite
dialect: sqlite
django.contrib.gis.db.backends.postgis:
driver: rlm_sql_postgresql
dialect: postgresql
django.contrib.gis.db.backends.mysql:
driver: rlm_sql_mysql
dialect: mysql
django.contrib.gis.db.backends.spatialite:
driver: rlm_sql_sqlite
dialect: sqlite
django.contrib.gis.db.backends.postgis:
driver: rlm_sql_postgresql
dialect: postgresql
django.contrib.gis.db.backends.mysql:
driver: rlm_sql_mysql
dialect: mysql
freeradius_sql:
driver: "{{ freeradius_db_map[openwisp2_database.engine].driver }}"
dialect: "{{ freeradius_db_map[openwisp2_database.engine].dialect }}"
freeradius_rest:
url: "https://{{ inventory_hostname }}/api/v1/freeradius"
freeradius_clients_ip: "0.0.0.0/0"
freeradius_clients_key: "admin"
freeradius_expire_attr_after_seconds: 86400
cron_delete_old_notifications: "'hour': 0, 'minute': 0"
cron_deactivate_expired_users: "'hour': 0, 'minute': 0"
cron_delete_old_users: "'hour': 0, 'minute': 10"
9 changes: 9 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -18,3 +18,12 @@
service:
name: redis
state: started

- name: update-ca-certificates
command: /usr/sbin/update-ca-certificates
when: ansible_os_family == "Debian"

- name: restart freeradius
service:
name: freeradius
state: started
38 changes: 0 additions & 38 deletions tasks/freeradius-mysql.yml

This file was deleted.

43 changes: 0 additions & 43 deletions tasks/freeradius-postgresql.yml

This file was deleted.

48 changes: 5 additions & 43 deletions tasks/freeradius.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,13 @@
---
- name: Freeradius system packages
when: openwisp2_radius
apt:
name:
- freeradius
- freeradius-rest
state: latest
notify: restart freeradius

# - import_tasks: freeradius-mysql.yml
# when: openwisp2_radius and freeradius_sql.dialect == "mysql"
#
# - import_tasks: freeradius-postgresql.yml
# when: openwisp2_radius and freeradius_sql.dialect == "postgresql"

# - name: Radius configurations
# when: openwisp2_radius
# template:
# src: freeradius/radiusd.conf.j2
# dest: "{{ freeradius_dir }}/radiusd.conf"
# mode: 0640
# owner: freerad
# group: freerad
# notify: restart freeradius

# - name: Clients configuration
# when: openwisp2_radius
# template:
# src: freeradius/clients.conf.j2
# dest: "{{ freeradius_dir }}/site"
# mode: 0640
# owner: freerad
# group: freerad
# notify: restart freeradius

# - name: Remove unnecessary modules
# when: openwisp2_radius
# file:
# dest: "{{ item }}"
# state: absent
# with_items:
# - "{{ freeradius_mods_enabled_dir }}/eap"

- name: SQL configuration
when: openwisp2_radius
template:
src: freeradius/sql.j2
dest: "{{ freeradius_mods_available_dir }}/sql"
@@ -53,7 +17,6 @@
notify: restart freeradius

- name: Enable SQL module
when: openwisp2_radius
file:
src: "{{ freeradius_mods_available_dir }}/sql"
dest: "{{ freeradius_mods_enabled_dir }}/sql"
@@ -63,7 +26,6 @@
group: freerad

- name: SQL Counter module
when: openwisp2_radius
template:
src: freeradius/sql_counter.j2
dest: "{{ freeradius_mods_available_dir }}/sql_counter"
@@ -73,7 +35,6 @@
notify: restart freeradius

- name: Enable SQL Counter module
when: openwisp2_radius
file:
src: "{{ freeradius_mods_available_dir }}/sql_counter"
dest: "{{ freeradius_mods_enabled_dir }}/sql_counter"
@@ -82,8 +43,12 @@
owner: freerad
group: freerad

- name: Add Attributes to freeradius dictionary
lineinfile:
path: "{{ freeradius_dir }}/dictionary"
line: "ATTRIBUTE Expire-After {{ freeradius_expire_attr_after_seconds }} integer"

- name: REST configuration
when: openwisp2_radius
template:
src: freeradius/rest.j2
dest: "{{ freeradius_mods_available_dir }}/rest"
@@ -93,7 +58,6 @@
notify: restart freeradius

- name: Enable REST module
when: openwisp2_radius
file:
src: "{{ freeradius_mods_available_dir }}/rest"
dest: "{{ freeradius_mods_enabled_dir }}/rest"
@@ -103,7 +67,6 @@
group: freerad

- name: Remove default site
when: openwisp2_radius
file:
dest: "{{ item }}"
state: absent
@@ -112,7 +75,6 @@
- "{{ freeradius_sites_enabled_dir }}/inner-tunnel"

- name: Site configuration
when: openwisp2_radius
template:
src: freeradius/openwisp_site.j2
dest: "{{ freeradius_sites_enabled_dir }}/openwisp_site"
2 changes: 1 addition & 1 deletion tasks/nginx.yml
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@
copy:
src: "{{ openwisp2_ssl_cert }}"
dest: /usr/local/share/ca-certificates/openwisp-ssl-server.crt
remote_src: yes
remote_src: true
owner: "root"
group: "root"
mode: "0644"
2 changes: 1 addition & 1 deletion tasks/pip.yml
Original file line number Diff line number Diff line change
@@ -150,7 +150,7 @@
state: latest
virtualenv: "{{ virtualenv_path }}"
virtualenv_python: "{{ openwisp2_python }}"
virtualenv_site_packages: yes
virtualenv_site_packages: true
notify: reload supervisor
retries: 5
delay: 10
7 changes: 0 additions & 7 deletions templates/freeradius/clients.conf.j2

This file was deleted.

63 changes: 0 additions & 63 deletions templates/freeradius/radiusd.conf.j2

This file was deleted.

25 changes: 25 additions & 0 deletions templates/freeradius/sql_counter.j2
Original file line number Diff line number Diff line change
@@ -39,3 +39,28 @@ sqlcounter dailybandwidthcounter {
WHERE UserName='%{${key}}' \
AND UNIX_TIMESTAMP(acctstarttime) + acctsessiontime > '%%b'"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The query may be slightly different for each DB, we need to add one include file for each DB.
I'm confident the queries I have for MySQL and PostgreSQL work, but not sure regarding sqlite, I will try to follow the format already used by freeradius.

}

sqlcounter monthlycounter {
sql_module_instance = sql
dialect = ${modules.sql.dialect}

counter_name = Monthly-Session-Time
check_name = Max-Monthly-Session
reply_name = Session-Timeout
key = User-Name
reset = monthly

$INCLUDE ${modconfdir}/sql/counter/${dialect}/${.:instance}.conf
}

sqlcounter expire_on_login {
sql_module_instance = sql
dialect = ${modules.sql.dialect}

counter_name = Expire-After-Initial-Login
check_name = Expire-After
key = User-Name
reset = never

$INCLUDE ${modconfdir}/sql/counter/${dialect}/${.:instance}.conf
}