Skip to content

Commit 46c047e

Browse files
JolienTrogjrauh01TheSyscall
committed
Document password policy configuration and extension
Adds a new section to the authentication chapter covering the built-in policies and their configuration under Configuration > Application > General, and a worked example of a custom policy module with the full hook implementation, `module.info`, and `run.php` registration. Co-authored-by: Johannes Rauh <johannes.rauh@icinga.com> Co-authored-by: Alexander Rieß <alexander.riess@icinga.com>
1 parent 950ab21 commit 46c047e

1 file changed

Lines changed: 111 additions & 0 deletions

File tree

doc/05-Authentication.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,117 @@ resource = icingaweb-mysql
158158
Please read [this chapter](20-Advanced-Topics.md#advanced-topics-authentication-tips-manual-user-database-auth)
159159
in order to manually create users directly inside the database.
160160

161+
### Password Policy <a id="authentication-password-policy"></a>
162+
163+
Icinga Web supports password policies when using database authentication. You can configure this under
164+
**Configuration > Application > General**.
165+
166+
By default, no password policy is enforced (`None`). Icinga Web provides a built-in policy called `Common` with the
167+
following requirements:
168+
169+
* Minimum length of 12 characters
170+
* At least one number
171+
* At least one special character
172+
* At least one lowercase letter
173+
* At least one uppercase letter
174+
175+
#### Custom Password Policy <a id="authentication-custom-password-policy"></a>
176+
177+
You can create custom password policies by developing a module with a provided hook.
178+
179+
**Create Module Structure**
180+
181+
```bash
182+
mkdir -p /usr/share/icingaweb2/modules/mypasswordpolicy/library/Mypasswordpolicy/ProvidedHook
183+
cd /usr/share/icingaweb2/modules/mypasswordpolicy
184+
```
185+
186+
Create `module.info`:
187+
188+
```ini
189+
Module: mypasswordpolicy
190+
Name: My Password Policy
191+
Version: 1.0.0
192+
Description: Custom password policy implementation
193+
```
194+
195+
**Implement the Hook**
196+
197+
Icinga Web provides the `PasswordPolicyHook` with predefined methods that simplify the extension of custom password
198+
policies.
199+
200+
Create `library/Mypasswordpolicy/ProvidedHook/PasswordPolicy.php`:
201+
202+
```php
203+
<?php
204+
205+
namespace Icinga\Module\Mypasswordpolicy\ProvidedHook;
206+
207+
use Icinga\Application\Hook\PasswordPolicyHook;
208+
use ipl\Html\Text;
209+
use ipl\Html\ValidHtml;
210+
use ipl\I18n\Translation;
211+
212+
class MyPasswordPolicy extends PasswordPolicyHook
213+
{
214+
use Translation;
215+
216+
public function getDisplayName(): string
217+
{
218+
return $this->translate('My Custom Policy');
219+
}
220+
221+
public function getName(): string
222+
{
223+
return 'my-custom-policy';
224+
}
225+
226+
public function getDescription(): ?ValidHtml
227+
{
228+
return new Text(
229+
$this->translate('More than 8 chars, at least 1 number, and must differ from the last password'),
230+
);
231+
}
232+
233+
public function validate(string $newPassword, ?string $oldPassword = null): array
234+
{
235+
$violations = [];
236+
237+
if (strlen($newPassword) < 8) {
238+
$violations[] = 'Password must be at least 8 characters';
239+
}
240+
241+
if (! preg_match('/[0-9]/', $newPassword)) {
242+
$violations[] = 'Password must contain at least one number';
243+
}
244+
245+
if ($oldPassword !== null && hash_equals($oldPassword, $newPassword)) {
246+
$violations[] = 'New password must be different from the old password';
247+
}
248+
249+
return $violations;
250+
}
251+
}
252+
```
253+
254+
**Register the Hook**
255+
256+
Create `run.php`:
257+
258+
```php
259+
<?php
260+
261+
use Icinga\Module\Mypasswordpolicy\ProvidedHook\MyPasswordPolicy;
262+
MyPasswordPolicy::register();
263+
```
264+
265+
266+
Enable the module:
267+
```shell
268+
icingacli module enable mypasswordpolicy
269+
```
270+
271+
The custom policy will now appear in **Configuration > Application > General** under Password Policy.
161272

162273
## Groups <a id="authentication-configuration-groups"></a>
163274

0 commit comments

Comments
 (0)