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

feat: add support for PAM authentication #12

Merged
merged 25 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
19d2172
feat: added PAM Auth option
Oct 1, 2024
cd92023
chore: make linter happy
Oct 1, 2024
b314df3
fix: '{{ }}' in loop
adf-patrickha Sep 5, 2024
a760230
fix: bareos-dir.conf.j2 template TLS settings
adf-patrickha Oct 30, 2024
61a4a23
chore(meta): update TLS argument_specs
adf-patrickha Oct 30, 2024
e54b4d8
chore(ci): add TLS dummy test files for molecule
adf-patrickha Oct 30, 2024
a761f75
chore(ci): add TLS vars in molecule converge
adf-patrickha Oct 30, 2024
0a2f0bb
chore(ci): remove old distros from matrix
adf-patrickha Oct 30, 2024
2c0250e
fix(ci): drop unsupported distros
adf-patrickha Oct 30, 2024
7845994
chore(ci): rm TODO, requirements2png actions
adf-patrickha Oct 30, 2024
72f75e8
doc: update README
adf-patrickha Oct 30, 2024
d6ca5f5
ci: use reusable workflows
maxthier Oct 29, 2024
b637b07
chore: update options templates/console.conf.j2
adf-patrickha Nov 5, 2024
3a4fe7b
chore(meta): `bareos_dir_consoles` argument_specs
adf-patrickha Nov 5, 2024
5cf11cd
feat(ci): bareos_dir_consoles with PAM auth
adf-patrickha Nov 5, 2024
fc0cee4
Merge branch 'main' into sssd-auth
adf-patrickha Nov 5, 2024
7cd38fd
feat: add vars/defaults for PAM support
adf-patrickha Nov 6, 2024
1fe6120
chore(meta): argument_specs PAM auth variables
adf-patrickha Nov 6, 2024
ddd5381
feat: tasks/pam_auth.yml for PAM authentication
adf-patrickha Nov 6, 2024
1adb421
chore(ci): include PAM auth tasks in molecule
adf-patrickha Nov 6, 2024
96009c0
chore: add dedicated RedHat.yml vars
adf-patrickha Nov 6, 2024
32b019e
chore: /etc/pam.d template bareos
adf-patrickha Nov 6, 2024
2e490e1
chore: extend tasks/assert.yml
adf-patrickha Nov 6, 2024
9088411
chore: extend tasks/assert.yml
adf-patrickha Nov 6, 2024
6ce8348
fix: PAM auth console file name
adf-patrickha Nov 7, 2024
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
3 changes: 3 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,6 @@ bareos_dir_schedules: []

# A list of storages to configure.
bareos_dir_storages: []

# Enable PAM authentication
bareos_dir_pam_auth_enable: false
76 changes: 75 additions & 1 deletion meta/argument_specs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,44 @@ argument_specs:
bareos_dir_consoles:
type: "list"
default: []
description: "A list of consoled to configure."
description: "A list of consoles to configure."
elements: "dict"
options:
name:
type: "str"
required: true
description: >
The name of the console.
This name must match the name specified at the Console client.
description:
type: "str"
password:
type: "str"
required: true
description: >
Specifies the password that must be supplied for a named Bareos Console to be authorized.
commandacl:
type: "list"
elements: "str"
jobacl:
type: "list"
elements: "str"
profile:
type: "str"
description: >
See https://docs.bareos.org/Configuration/Director.html#directorresourceprofile
tls_enable:
type: "bool"
default: true
description: "Enable TLS support."
use_pam_authentication:
type: "bool"
default: false
description: >
Use PAM authentication for this console.
Cannot be used in combination with the option `profile` or `commandacl`!
See: https://github.com/bareos/bareos/tree/master/contrib/misc/bareos_pam_integration#pam-configuration

bareos_dir_counters:
type: "list"
default: []
Expand Down Expand Up @@ -130,3 +167,40 @@ argument_specs:
elements: "str"
required: false
version_added: v1.1.0
bareos_dir_pam_auth_enable:
type: "bool"
default: false
description: >
Setup Bareos Director to use PAM authentication via Unix socket or LDAP socket.
Follows the setup guide at
https://github.com/bareos/bareos/tree/master/contrib/misc/bareos_pam_integration#pam-configuration
bareos_dir_pam_auth_method:
type: "str"
default: "unix"
choices:
- "ldap"
- "unix"
description: "Decide if Unix or LDAP socket should be used for PAM authentication"
bareos_dir_pam_auth_profile:
type: "str"
default: "webui-admin"
description: "The Bareos profile to use for the user, after a successful login attempt"
bareos_dir_pam_auth_username:
type: "str"
default: "pam-adduser"
description: >
Technical user account for the Bareos Console connection.
Required to be able to add the user resources in Bareos, after a successful PAM authentication.
bareos_dir_pam_auth_password:
type: "str"
default: "lookup('ansible.builtin.password', '/dev/null', seed=inventory_hostname')"
description: >-
Password for technical user account for the Bareos Console connection.
Randomized, but idempotent password will be generated if variable is unset.
bareos_dir_pam_auth_tls_enable:
type: "bool"
default: false
description: >
If TLS should be used for the Bareos Console
WebUI does not support pre-shared keys (PSK), so if this is desired,
an actual CA and certificates need to be in place.
10 changes: 10 additions & 0 deletions molecule/default/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
- .status
jobacl:
- "*all"
tls_enable: true
- name: pam-console
description: "Console uses PAM authentication"
password: "MySecretPAMPassword"
tls_enable: true
use_pam_authentication: true
bareos_dir_clients:
- name: bareos-fd
address: 127.0.0.1
Expand Down Expand Up @@ -282,6 +288,10 @@
- "[email protected]"
- "[email protected]"

bareos_dir_pam_auth_enable: true
bareos_dir_pam_auth_method: unix
bareos_dir_pam_auth_tls_enable: true

- role: adfinis.bareos_console
bareos_console_directors:
- name: bareos-dir
Expand Down
30 changes: 29 additions & 1 deletion tasks/assert.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,20 @@
- bareos_dir_storages is iterable
quiet: true

- name: assert | Test bareos_dir_packages
ansible.builtin.assert:
that:
- bareos_dir_packages is defined
- bareos_dir_packages is iterable
quiet: true

- name: assert | Test bareos_dir_install_debug_packages
ansible.builtin.assert:
that:
- bareos_dir_install_debug_packages is defined
- bareos_dir_install_debug_packages is boolean
quiet: true


- name: assert | Test bareos_dir_catalogs
ansible.builtin.assert:
that:
Expand Down Expand Up @@ -185,3 +191,25 @@
ansible.builtin.assert:
that:
- bareos_dir_messages is defined
quiet: true

- name: assert | Test bareos_dir_pam_auth_enable
ansible.builtin.assert:
that:
- bareos_dir_pam_auth_enable is defined
- bareos_dir_pam_auth_enable is boolean
quiet: true

- name: assert | Test bareos_dir_pam_auth_requirements
ansible.builtin.assert:
that:
- bareos_dir_pam_auth_requirements is defined
- bareos_dir_pam_auth_requirements is iterable
quiet: true

- name: assert | Test bareos_dir_plugin_list
ansible.builtin.assert:
that:
- bareos_dir_plugin_list is defined
- bareos_dir_plugin_list is iterable
quiet: true
9 changes: 9 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,15 @@
- bareos_dir_plugins is defined
- bareos_dir_plugins is iterable

- name: Import PAM authentication tasklist
ansible.builtin.import_tasks:
file: pam_auth.yml
when:
- bareos_dir_pam_auth_enable
- bareos_dir_pam_auth_method is defined
- bareos_dir_pam_auth_method == "ldap" or
bareos_dir_pam_auth_method == "unix"

- name: Start bareos-dir
ansible.builtin.service:
name: bareos-dir
Expand Down
78 changes: 78 additions & 0 deletions tasks/pam_auth.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
# Follows the setup process according to
# https://github.com/bareos/bareos/tree/master/contrib/misc/bareos_pam_integration#pam-configuration

- name: pam_auth | Install PAM dependencies
ansible.builtin.package:
name: "{{ bareos_dir_pam_auth_requirements }}"
state: present

- name: pam_auth | Create bconsole password if bareos_dir_pam_auth_password unset
ansible.builtin.set_fact:
bareos_dir_pam_auth_password: "{{ lookup('ansible.builtin.password', '/dev/null', seed=inventory_hostname) }}"
when:
- bareos_dir_pam_auth_password is not defined or
bareos_dir_pam_auth_password == ""

- name: pam_auth | Create bareos conf in /etc/pam.d/
ansible.builtin.template:
src: templates/pam.d/bareos.j2
dest: /etc/pam.d/bareos
owner: root
group: bareos
mode: "0644"

# required for unix.socket auth to read /etc/shadow
- name: pam_auth | Add bareos user to group shadow
ansible.builtin.user:
name: bareos
groups: shadow
append: true
when:
- bareos_dir_pam_auth_method == "unix"
- ansible_facts.os_family == "Debian"

# required for unix.socket auth to read /etc/shadow
- name: pam_auth | Change permissions for /etc/shadow
ansible.builtin.file:
path: "/etc/shadow"
owner: root
group: bareos
mode: "0040"
when:
- bareos_dir_pam_auth_method == "unix"
- ansible_facts.os_family == "RedHat"

- name: pam_auth | Download pam_exec_add_bareos_user.py from bareos Github
ansible.builtin.get_url:
url: https://github.com/bareos/bareos/blob/master/contrib/misc/bareos_pam_integration/pam_exec_add_bareos_user.py
dest: "/usr/local/bin/pam_exec_add_bareos_user.py"
owner: bareos
group: bareos
mode: "0744"

- name: pam_auth | Create PAM specific Bareos Console
ansible.builtin.template:
src: console.conf.j2
dest: "/etc/bareos/bareos-dir.d/console/{{ item.name }}.conf"
owner: bareos
group: bareos
mode: "0644"
backup: "{{ bareos_dir_backup_configurations }}"
loop:
- name: "{{ bareos_dir_pam_auth_username | default('pam-adduser') }}"
description: >-
Dedicated Console for PAM authentication.
Using this, a user who successfully authenticates against LDAP,
will be created as Bareos user with ACLs as defined in profile {{ bareos_dir_pam_auth_profile | default('webui-admin') }}.
password: "{{ bareos_dir_pam_auth_password }}"
tls_enable: "{{ bareos_dir_pam_auth_tls_enable | default(false) }}"
commandacl:
- ".api"
- ".profiles"
- ".users"
- "configure"
- "version"
notify:
- Check configuration
- Reload bareos-dir
9 changes: 5 additions & 4 deletions templates/console.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ Console {
Description = "{{ item.description }}"
{% endif %}
Password = "{{ item.password }}"
TLS Enable = {{ item.tls_enable | default(true) | ternary('Yes', 'No') }}
{% if item.commandacl is defined %}
CommandACL = {{ item.commandacl | join(', ') }}
Command ACL = {{ item.commandacl | join(', ') }}
{% endif %}
{% if item.jobacl is defined %}
JobACL = {{ item.jobacl | join(', ') }}
Job ACL = {{ item.jobacl | join(', ') }}
{% endif %}
{% if item.profile is defined %}
Profile = "{{ item.profile }}"
{% endif %}
{% if item.tlsenable is defined %}
TlsEnable = {{ item.tlsenable | ternary('Yes', 'No') }}
{% if item.use_pam_authentication is defined %}
UsePamAuthentication = {{ item.use_pam_authentication | ternary('Yes', 'No') }}
{% endif %}
}
{% else %}
Expand Down
9 changes: 9 additions & 0 deletions templates/pam.d/bareos.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{ ansible_managed | comment }}
{% if bareos_dir_pam_auth_method | default("unix") == "unix" %}
auth required pam_unix.so
account requisite pam_unix.so
{% elif bareos_dir_pam_auth_method == "ldap" %}
auth required pam_ldap.so
account requisite pam_ldap.so
{% endif %}
account [default=ignore] pam_exec.so /usr/bin/python3 /usr/local/bin/pam_exec_add_bareos_user.py --name {{ bareos_dir_pam_auth_username | default('pam-adduser') }} --password {{ bareos_dir_pam_auth_password }} --profile {{ bareos_dir_pam_auth_profile | default("webui-admin") }}
4 changes: 4 additions & 0 deletions vars/Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ bareos_dir_debug_packages:
- gdb

bareos_dir_plugin_dir: "/usr/lib/bareos/plugins"

bareos_dir_pam_auth_requirements:
- libpam-modules
- python3-bareos
10 changes: 10 additions & 0 deletions vars/RedHat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---

bareos_dir_debug_packages:
- bareos-debuginfo
- gdb

bareos_dir_plugin_name: python3

bareos_dir_pam_auth_requirements:
- pam
2 changes: 2 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ bareos_dir_plugin_list:
- name: director-python
packages:
- bareos-director-python3-plugin

bareos_dir_pam_auth_requirements: []