Skip to content

Conversation

@JolienTrog
Copy link
Contributor

Ref #4401

@JolienTrog JolienTrog requested a review from Al2Klimov August 26, 2025 09:22
@cla-bot cla-bot bot added the cla/signed label Aug 26, 2025
Copy link
Member

@Al2Klimov Al2Klimov left a comment

Choose a reason for hiding this comment

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

Fix your code style as told by the failing Github actions.

Copy link
Member

@Al2Klimov Al2Klimov left a comment

Choose a reason for hiding this comment

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

Please push without -f for now. This eases it for me to keep track of your changes.

@JolienTrog JolienTrog requested a review from Al2Klimov August 26, 2025 15:21
@JolienTrog JolienTrog requested a review from Al2Klimov August 27, 2025 07:53
@JolienTrog JolienTrog requested a review from Al2Klimov August 28, 2025 08:35
@JolienTrog JolienTrog requested a review from Al2Klimov August 28, 2025 11:05
@JolienTrog JolienTrog requested a review from Al2Klimov August 28, 2025 13:15
@JolienTrog JolienTrog requested a review from Al2Klimov August 28, 2025 14:05
@JolienTrog JolienTrog requested a review from Al2Klimov August 28, 2025 15:26
Copy link
Member

@Al2Klimov Al2Klimov left a comment

Choose a reason for hiding this comment

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

During setup, the wizard prompts me for a username and password "to configure your first administrative account". This should enforce the chosen password policy.

@JolienTrog JolienTrog force-pushed the password-policy branch 2 times, most recently from 97e07ad to 39bbc53 Compare September 2, 2025 10:24
@JolienTrog JolienTrog requested a review from Al2Klimov October 14, 2025 09:38
Copy link
Member

@Al2Klimov Al2Klimov left a comment

Choose a reason for hiding this comment

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

Not done yet:

Also, regarding #5419 (review): Situations where you push -f anyway, such as #5419 (comment), are good opportunities to squash at least commits which address only reviews and/or GitHub action failures.

$instance = new $passwordPolicyClass;

if (class_exists($passwordPolicyClass) && ($instance instanceof PasswordPolicyHook)) {
$this->passwordPolicy = new $passwordPolicyClass();
Copy link
Member

Choose a reason for hiding this comment

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

So if $instance instanceof PasswordPolicyHook is false, will $this->passwordPolicy stay empty? What about the other methods in this class relying on that property being set?


namespace Icinga\Application\Hook;

interface PasswordPolicyHook
Copy link
Member

Choose a reason for hiding this comment

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

Given PHP has no multiple inheritance, I wanted to preventively avoid unnecessary base classes and instructed you to make an interface.

See how tables have turned: #5442 (comment) 🙈

Copy link
Member

Choose a reason for hiding this comment

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

This comment from Alex doesn't read like an instruction, so here's the explanation:

We use arbitrary strings such as PasswordPolicy to register and load hooks, which makes it difficult to actually find hook usages. I would suggest making PasswordPolicyHook an abstract class that also provides the methods all() and register() so that the string PasswordPolicy only appears in the hook itself. Please then also adjust the documentation.

Copy link
Member

Choose a reason for hiding this comment

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

I think I would also do the following to make it clean:

  • Rename PasswordPolicyHook to PasswordPolicy (and move it to the Authentication namespace).
  • Use the PasswordPolicy interface everywhere in the code where typing is required. This is better than using the hook as a type, since the hook is used to load the functionality.
  • Have the new abstract PasswordPolicyHook implement PasswordPolicy.

- Fix validator handeling
- Adjust hook registration name
@JolienTrog JolienTrog requested a review from Al2Klimov November 10, 2025 07:38
$helper = new PasswordPolicyHelper();
$validators[] = $helper->getPasswordValidator();
$helper->addPasswordPolicyDescription($this);
} catch (\Throwable $e) {
Copy link
Member

Choose a reason for hiding this comment

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

Please use Throwable;.

$validators[] = $helper->getPasswordValidator();
$helper->addPasswordPolicyDescription($this);
} catch (\Throwable $e) {
Logger::error($e);
Copy link
Member

Choose a reason for hiding this comment

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

I would adjust the log message so that it includes the topic, e.g., 'The configured password policy could not be loaded: %s', $e

$helper->addPasswordPolicyDescription($this);
} catch (\Throwable $e) {
Logger::error($e);
Notification::error("The configured password policy could not be loaded.");
Copy link
Member

Choose a reason for hiding this comment

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

I want this information to be displayed permanently, so Notification should be avoided. If styling is required, there is a form element called Note that can be used instead. You can search for 'note' in the Icinga web codebase to find examples of how it is used. addDescription() can also be used. The message could then be changed to something like this: There was a problem loading the configured password policy. Please contact your administrator.

@@ -0,0 +1,51 @@
<?php
Copy link
Member

Choose a reason for hiding this comment

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

License header missing.

Please read [this chapter](20-Advanced-Topics.md#advanced-topics-authentication-tips-manual-user-database-auth)
in order to manually create users directly inside the database.

### Password Policy <a id="authentication-password-policy"></a>
Copy link
Member

Choose a reason for hiding this comment

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

Please add newlines after headings and speak of Icinga Web not Icinga Web 2.

{
$message = $this->passwordPolicyObject->validatePassword($value);

if (!empty($message)) {
Copy link
Member

Choose a reason for hiding this comment

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

Space after ! missing.

use Icinga\Application\Hook\PasswordPolicyHook;
use Zend_Validate_Abstract;

class PasswordValidator extends Zend_Validate_Abstract
Copy link
Member

Choose a reason for hiding this comment

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

I would rename the class to PasswordPolicyValidator.

* @return string[] Returns an empty array if the password is valid,
* otherwise returns error messages describing the violations
*/
public function validatePassword(string $password): array;
Copy link
Member

Choose a reason for hiding this comment

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

validate() is sufficient.


namespace Icinga\Application\Hook;

interface PasswordPolicyHook
Copy link
Member

Choose a reason for hiding this comment

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

I think I would also do the following to make it clean:

  • Rename PasswordPolicyHook to PasswordPolicy (and move it to the Authentication namespace).
  • Use the PasswordPolicy interface everywhere in the code where typing is required. This is better than using the hook as a type, since the hook is used to load the functionality.
  • Have the new abstract PasswordPolicyHook implement PasswordPolicy.


public function testValidatePasswordTooShort(): void
{
$expectedResults = ['Password must be at least 12 characters long'];
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need those variables? The signature of assert*() is $expected, $actual, so having the following is perfectly fine:

$this->assertSame(
    expected,
    actual
);

And if you really need such variables, please use $expected and $actual.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants