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

ca, kra install: validate DM password #757

Closed

Conversation

nicki-krizek
Copy link
Contributor

@nicki-krizek nicki-krizek commented May 3, 2017

Prevent CA and KRA installation from proceeding if provided DM password is invalid to avoid broken installations with no possibility to uninstall CA or KRA.

https://pagure.io/freeipa/issue/6892

"Directory Manager (existing master)", confirm=False,
validate=False)
except KeyboardInterrupt:
sys.exit(0)
Copy link
Member

Choose a reason for hiding this comment

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

keyboard interrupt should not result in exit code 0. A common exit code is 130 (128 + SIGINT).

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm afraid that this is inconsistent with other parts of code. The rest will return error code 1 in case of SIGINT.

If you want to keep new error code, then manpage should be updated as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or even better, don't catch that exception and let installutils.run_script() to handle it in the same way for every script.

try:
client.simple_bind(DIRMAN_DN, password)
except errors.ACIError:
raise ValueError("Invalid Directory Manager password")
Copy link
Contributor

@MartinBasti MartinBasti May 3, 2017

Choose a reason for hiding this comment

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

I'm sorry but I think you may miss following code there:

else:
    client.unbind()

Copy link
Contributor

Choose a reason for hiding this comment

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

Also I would rather use verbs to name functions/methods, like validate_dm_password (but I have a suspicion that one is already taken).

try:
installutils.dm_password_validator(password)
except ValueError:
sys.exit("Directory Manager password is invalid")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please don't use sys.exit() explicitly here, either let the exception propagate up the stack to the caller or re-raise RuntimeError as you do in ipa-kra-install

@stlaz
Copy link
Contributor

stlaz commented May 4, 2017

There will be no more sys.exits. This patchset shall not be ACKed until all have been removed.

Copy link
Contributor

@stlaz stlaz left a comment

Choose a reason for hiding this comment

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

Don't use sys.exits

Tomas Krizek added 2 commits May 5, 2017 15:22
Extract copy-pasted code to a single function.

Related https://pagure.io/freeipa/issue/6892

Signed-off-by: Tomas Krizek <tkrizek@redhat.com>
Add a validator that checks whether provided Directory Manager
is valid by attempting to connect to LDAP.

Related https://pagure.io/freeipa/issue/6892

Signed-off-by: Tomas Krizek <tkrizek@redhat.com>
@nicki-krizek
Copy link
Contributor Author

Thanks for the feedback, hopefully I addressed all the issues.

Copy link
Contributor

@MartinBasti MartinBasti left a comment

Choose a reason for hiding this comment

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

Please fix nitpicks, and ehm..ehm maybe add a CI test? Works for me otherwise

def _get_dirman_password(password=None, unattended=False):
if not password:
if unattended:
raise RuntimeError('Directory Manager password required')
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use script error to be consistent

ipaserver/install/server/install.py:            raise ScriptError("Directory Manager password required")

try:
installutils.validate_dm_password_ldap(password)
except ValueError:
raise RuntimeError("Directory Manager password is invalid")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use ScriptError here as well.

try:
installutils.validate_dm_password_ldap(self.options.password)
except ValueError:
raise RuntimeError("Directory Manager password is invalid")
Copy link
Contributor

Choose a reason for hiding this comment

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

ScriptError please :)

@nicki-krizek nicki-krizek force-pushed the validate-dm-password branch 2 times, most recently from 4677428 to 8d13f2a Compare May 10, 2017 15:04
@nicki-krizek
Copy link
Contributor Author

Implementing the tests shouldn't block us from pushing this fix. I opened a ticket for it: https://pagure.io/freeipa/issue/6941

@MartinBasti
Copy link
Contributor

We have to use sys.exit() in this case, because I forgot that CA still uses old style installer. Without sys.exit() ti will always suggest user to uninstall server:

Your system may be partly configured.
Run /usr/sbin/ipa-server-install --uninstall to clean up.

We don't want to uninstall server due typo in password

@nicki-krizek nicki-krizek force-pushed the validate-dm-password branch 2 times, most recently from 6eef190 to fa43013 Compare May 11, 2017 14:50
@stlaz
Copy link
Contributor

stlaz commented May 12, 2017

You forgot an import in ipa-ca-install:

************* Module ipa-ca-install

install/tools/ipa-ca-install:37: [W0611(unused-import), ] Unused ScriptError imported from ipapython.admintool)

Before proceeding with installation, validate DM password. If the
provided DM password is invalid, abort the installation.

Fixes https://pagure.io/freeipa/issue/6892

Signed-off-by: Tomas Krizek <tkrizek@redhat.com>
@nicki-krizek nicki-krizek added the prioritized Pull Request has higher priority for PR-CI label May 17, 2017
@MartinBasti MartinBasti added ack Pull Request approved, can be merged and removed prioritized Pull Request has higher priority for PR-CI labels May 17, 2017
@MartinBasti
Copy link
Contributor

master:

  • 80d61c2 ca install: merge duplicated code for DM password
  • 7a4a368 installutils: add DM password validator
  • 1b1bace ca, kra install: validate DM password

ipa-4-5:

  • 282fc0c ca install: merge duplicated code for DM password
  • 4c12b71 installutils: add DM password validator
  • b8bcaa6 ca, kra install: validate DM password

@MartinBasti MartinBasti added the pushed Pull Request has already been pushed label May 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ack Pull Request approved, can be merged pushed Pull Request has already been pushed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants