Skip to content

Commit f04f512

Browse files
Merge pull request #12 from adfinis/sssd-auth
feat: add support for PAM authentication
2 parents a660eaf + 6ce8348 commit f04f512

File tree

11 files changed

+234
-6
lines changed

11 files changed

+234
-6
lines changed

defaults/main.yml

+3
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,6 @@ bareos_dir_schedules: []
7777

7878
# A list of storages to configure.
7979
bareos_dir_storages: []
80+
81+
# Enable PAM authentication
82+
bareos_dir_pam_auth_enable: false

meta/argument_specs.yml

+75-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,44 @@ argument_specs:
7979
bareos_dir_consoles:
8080
type: "list"
8181
default: []
82-
description: "A list of consoled to configure."
82+
description: "A list of consoles to configure."
83+
elements: "dict"
84+
options:
85+
name:
86+
type: "str"
87+
required: true
88+
description: >
89+
The name of the console.
90+
This name must match the name specified at the Console client.
91+
description:
92+
type: "str"
93+
password:
94+
type: "str"
95+
required: true
96+
description: >
97+
Specifies the password that must be supplied for a named Bareos Console to be authorized.
98+
commandacl:
99+
type: "list"
100+
elements: "str"
101+
jobacl:
102+
type: "list"
103+
elements: "str"
104+
profile:
105+
type: "str"
106+
description: >
107+
See https://docs.bareos.org/Configuration/Director.html#directorresourceprofile
108+
tls_enable:
109+
type: "bool"
110+
default: true
111+
description: "Enable TLS support."
112+
use_pam_authentication:
113+
type: "bool"
114+
default: false
115+
description: >
116+
Use PAM authentication for this console.
117+
Cannot be used in combination with the option `profile` or `commandacl`!
118+
See: https://github.com/bareos/bareos/tree/master/contrib/misc/bareos_pam_integration#pam-configuration
119+
83120
bareos_dir_counters:
84121
type: "list"
85122
default: []
@@ -130,3 +167,40 @@ argument_specs:
130167
elements: "str"
131168
required: false
132169
version_added: v1.1.0
170+
bareos_dir_pam_auth_enable:
171+
type: "bool"
172+
default: false
173+
description: >
174+
Setup Bareos Director to use PAM authentication via Unix socket or LDAP socket.
175+
Follows the setup guide at
176+
https://github.com/bareos/bareos/tree/master/contrib/misc/bareos_pam_integration#pam-configuration
177+
bareos_dir_pam_auth_method:
178+
type: "str"
179+
default: "unix"
180+
choices:
181+
- "ldap"
182+
- "unix"
183+
description: "Decide if Unix or LDAP socket should be used for PAM authentication"
184+
bareos_dir_pam_auth_profile:
185+
type: "str"
186+
default: "webui-admin"
187+
description: "The Bareos profile to use for the user, after a successful login attempt"
188+
bareos_dir_pam_auth_username:
189+
type: "str"
190+
default: "pam-adduser"
191+
description: >
192+
Technical user account for the Bareos Console connection.
193+
Required to be able to add the user resources in Bareos, after a successful PAM authentication.
194+
bareos_dir_pam_auth_password:
195+
type: "str"
196+
default: "lookup('ansible.builtin.password', '/dev/null', seed=inventory_hostname')"
197+
description: >-
198+
Password for technical user account for the Bareos Console connection.
199+
Randomized, but idempotent password will be generated if variable is unset.
200+
bareos_dir_pam_auth_tls_enable:
201+
type: "bool"
202+
default: false
203+
description: >
204+
If TLS should be used for the Bareos Console
205+
WebUI does not support pre-shared keys (PSK), so if this is desired,
206+
an actual CA and certificates need to be in place.

molecule/default/converge.yml

+10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
- .status
2525
jobacl:
2626
- "*all"
27+
tls_enable: true
28+
- name: pam-console
29+
description: "Console uses PAM authentication"
30+
password: "MySecretPAMPassword"
31+
tls_enable: true
32+
use_pam_authentication: true
2733
bareos_dir_clients:
2834
- name: bareos-fd
2935
address: 127.0.0.1
@@ -282,6 +288,10 @@
282288
283289
284290
291+
bareos_dir_pam_auth_enable: true
292+
bareos_dir_pam_auth_method: unix
293+
bareos_dir_pam_auth_tls_enable: true
294+
285295
- role: adfinis.bareos_console
286296
bareos_console_directors:
287297
- name: bareos-dir

tasks/assert.yml

+29-1
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,20 @@
124124
- bareos_dir_storages is iterable
125125
quiet: true
126126

127+
- name: assert | Test bareos_dir_packages
128+
ansible.builtin.assert:
129+
that:
130+
- bareos_dir_packages is defined
131+
- bareos_dir_packages is iterable
132+
quiet: true
133+
127134
- name: assert | Test bareos_dir_install_debug_packages
128135
ansible.builtin.assert:
129136
that:
130137
- bareos_dir_install_debug_packages is defined
131138
- bareos_dir_install_debug_packages is boolean
132139
quiet: true
133140

134-
135141
- name: assert | Test bareos_dir_catalogs
136142
ansible.builtin.assert:
137143
that:
@@ -185,3 +191,25 @@
185191
ansible.builtin.assert:
186192
that:
187193
- bareos_dir_messages is defined
194+
quiet: true
195+
196+
- name: assert | Test bareos_dir_pam_auth_enable
197+
ansible.builtin.assert:
198+
that:
199+
- bareos_dir_pam_auth_enable is defined
200+
- bareos_dir_pam_auth_enable is boolean
201+
quiet: true
202+
203+
- name: assert | Test bareos_dir_pam_auth_requirements
204+
ansible.builtin.assert:
205+
that:
206+
- bareos_dir_pam_auth_requirements is defined
207+
- bareos_dir_pam_auth_requirements is iterable
208+
quiet: true
209+
210+
- name: assert | Test bareos_dir_plugin_list
211+
ansible.builtin.assert:
212+
that:
213+
- bareos_dir_plugin_list is defined
214+
- bareos_dir_plugin_list is iterable
215+
quiet: true

tasks/main.yml

+9
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,15 @@
277277
- bareos_dir_plugins is defined
278278
- bareos_dir_plugins is iterable
279279

280+
- name: Import PAM authentication tasklist
281+
ansible.builtin.import_tasks:
282+
file: pam_auth.yml
283+
when:
284+
- bareos_dir_pam_auth_enable
285+
- bareos_dir_pam_auth_method is defined
286+
- bareos_dir_pam_auth_method == "ldap" or
287+
bareos_dir_pam_auth_method == "unix"
288+
280289
- name: Start bareos-dir
281290
ansible.builtin.service:
282291
name: bareos-dir

tasks/pam_auth.yml

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
# Follows the setup process according to
3+
# https://github.com/bareos/bareos/tree/master/contrib/misc/bareos_pam_integration#pam-configuration
4+
5+
- name: pam_auth | Install PAM dependencies
6+
ansible.builtin.package:
7+
name: "{{ bareos_dir_pam_auth_requirements }}"
8+
state: present
9+
10+
- name: pam_auth | Create bconsole password if bareos_dir_pam_auth_password unset
11+
ansible.builtin.set_fact:
12+
bareos_dir_pam_auth_password: "{{ lookup('ansible.builtin.password', '/dev/null', seed=inventory_hostname) }}"
13+
when:
14+
- bareos_dir_pam_auth_password is not defined or
15+
bareos_dir_pam_auth_password == ""
16+
17+
- name: pam_auth | Create bareos conf in /etc/pam.d/
18+
ansible.builtin.template:
19+
src: templates/pam.d/bareos.j2
20+
dest: /etc/pam.d/bareos
21+
owner: root
22+
group: bareos
23+
mode: "0644"
24+
25+
# required for unix.socket auth to read /etc/shadow
26+
- name: pam_auth | Add bareos user to group shadow
27+
ansible.builtin.user:
28+
name: bareos
29+
groups: shadow
30+
append: true
31+
when:
32+
- bareos_dir_pam_auth_method == "unix"
33+
- ansible_facts.os_family == "Debian"
34+
35+
# required for unix.socket auth to read /etc/shadow
36+
- name: pam_auth | Change permissions for /etc/shadow
37+
ansible.builtin.file:
38+
path: "/etc/shadow"
39+
owner: root
40+
group: bareos
41+
mode: "0040"
42+
when:
43+
- bareos_dir_pam_auth_method == "unix"
44+
- ansible_facts.os_family == "RedHat"
45+
46+
- name: pam_auth | Download pam_exec_add_bareos_user.py from bareos Github
47+
ansible.builtin.get_url:
48+
url: https://github.com/bareos/bareos/blob/master/contrib/misc/bareos_pam_integration/pam_exec_add_bareos_user.py
49+
dest: "/usr/local/bin/pam_exec_add_bareos_user.py"
50+
owner: bareos
51+
group: bareos
52+
mode: "0744"
53+
54+
- name: pam_auth | Create PAM specific Bareos Console
55+
ansible.builtin.template:
56+
src: console.conf.j2
57+
dest: "/etc/bareos/bareos-dir.d/console/{{ item.name }}.conf"
58+
owner: bareos
59+
group: bareos
60+
mode: "0644"
61+
backup: "{{ bareos_dir_backup_configurations }}"
62+
loop:
63+
- name: "{{ bareos_dir_pam_auth_username | default('pam-adduser') }}"
64+
description: >-
65+
Dedicated Console for PAM authentication.
66+
Using this, a user who successfully authenticates against LDAP,
67+
will be created as Bareos user with ACLs as defined in profile {{ bareos_dir_pam_auth_profile | default('webui-admin') }}.
68+
password: "{{ bareos_dir_pam_auth_password }}"
69+
tls_enable: "{{ bareos_dir_pam_auth_tls_enable | default(false) }}"
70+
commandacl:
71+
- ".api"
72+
- ".profiles"
73+
- ".users"
74+
- "configure"
75+
- "version"
76+
notify:
77+
- Check configuration
78+
- Reload bareos-dir

templates/console.conf.j2

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,18 @@ Console {
77
Description = "{{ item.description }}"
88
{% endif %}
99
Password = "{{ item.password }}"
10+
TLS Enable = {{ item.tls_enable | default(true) | ternary('Yes', 'No') }}
1011
{% if item.commandacl is defined %}
11-
CommandACL = {{ item.commandacl | join(', ') }}
12+
Command ACL = {{ item.commandacl | join(', ') }}
1213
{% endif %}
1314
{% if item.jobacl is defined %}
14-
JobACL = {{ item.jobacl | join(', ') }}
15+
Job ACL = {{ item.jobacl | join(', ') }}
1516
{% endif %}
1617
{% if item.profile is defined %}
1718
Profile = "{{ item.profile }}"
1819
{% endif %}
19-
{% if item.tlsenable is defined %}
20-
TlsEnable = {{ item.tlsenable | ternary('Yes', 'No') }}
20+
{% if item.use_pam_authentication is defined %}
21+
UsePamAuthentication = {{ item.use_pam_authentication | ternary('Yes', 'No') }}
2122
{% endif %}
2223
}
2324
{% else %}

templates/pam.d/bareos.j2

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{{ ansible_managed | comment }}
2+
{% if bareos_dir_pam_auth_method | default("unix") == "unix" %}
3+
auth required pam_unix.so
4+
account requisite pam_unix.so
5+
{% elif bareos_dir_pam_auth_method == "ldap" %}
6+
auth required pam_ldap.so
7+
account requisite pam_ldap.so
8+
{% endif %}
9+
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") }}

vars/Debian.yml

+4
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ bareos_dir_debug_packages:
88
- gdb
99

1010
bareos_dir_plugin_dir: "/usr/lib/bareos/plugins"
11+
12+
bareos_dir_pam_auth_requirements:
13+
- libpam-modules
14+
- python3-bareos

vars/RedHat.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
3+
bareos_dir_debug_packages:
4+
- bareos-debuginfo
5+
- gdb
6+
7+
bareos_dir_plugin_name: python3
8+
9+
bareos_dir_pam_auth_requirements:
10+
- pam

vars/main.yml

+2
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ bareos_dir_plugin_list:
2727
- name: director-python
2828
packages:
2929
- bareos-director-python3-plugin
30+
31+
bareos_dir_pam_auth_requirements: []

0 commit comments

Comments
 (0)