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

Add password file to certutil calls in ipapython.certdb module #446

Closed
wants to merge 2 commits into from

Conversation

stlaz
Copy link
Contributor

@stlaz stlaz commented Feb 8, 2017

With this patchset, ipa-client-install should not ask for NSS database password.

Prerequisite for it to work in FIPS:
#367

edit: This was a part of a bigger branch and might be missing some parts.

@stlaz stlaz changed the title Certdb passwd No NSS database passwords in ipa-client-install Feb 8, 2017
@tkrizek tkrizek self-assigned this Feb 8, 2017
@@ -83,7 +83,8 @@ class NSSDatabase(object):
# got too tied to IPA server details, killing reusability.
# BaseCertDB is a class that knows nothing about IPA.
# Generic NSS DB code should be moved here.
def __init__(self, nssdir=None):
def __init__(self, nssdir=None, password_filename=None):
self.password_filename = password_filename
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we default to os.path.join(nssdir, 'pwdfile.txt')?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We might but password file does not need to exist in general. I think this assumption is made in CertDB instead.
I can add it nonetheless.

return ipautil.run(new_args, stdin, **kwargs)

def create_db(self, password_filename):
"""Create cert DB

:param password_filename: Name of file containing the database password
"""
self.run_certutil(["-N", "-f", password_filename])
# run_certutil will use self.password_filename to setup the db
self.password_filename = password_filename
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that the filename is specified via __init__() argument, I see very little point in keeping the argument in create_db() as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I started doing this I realized that this change actually has to be done along with the one proposed on line 87, will do both, then.

@@ -159,7 +159,7 @@ def __get_keys(self, ca_host, cacerts_file, cacerts_pwd, data):
'-w', pk12pwfile])

# Add CA certificates
tmpdb = CertDB(self.realm, nssdir=tmpnssdir)
tmpdb = NSSDatabase(tmpnssdir, password_filename=nsspwfile)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The path to CertDB password file in this case would be $tmpnssdir"/pwdfile.txt". This file would be then passed to CertDB's inner NSSDatabase - but there is no such file. As the author of custodiainstance creates the password file in $tmpnssdir"/pk12pwfile" it was my assumption that they never meant to use IPA-specific NSS database representation.

@stlaz stlaz force-pushed the certdb_passwd branch 3 times, most recently from c5547d4 to 5d7079f Compare February 10, 2017 13:22
db = certdb.NSSDatabase(paths.IPA_NSSDB_DIR)
pwdfile = os.path.join(db.secdir, 'pwdfile.txt')
db = certdb.NSSDatabase(paths.IPA_NSSDB_DIR,
os.path.join(paths.IPA_NSSDB_DIR, 'pwdfile.txt'))
Copy link
Contributor Author

@stlaz stlaz Feb 10, 2017

Choose a reason for hiding this comment

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

I could do this and according changes properly by replacing NSSDatabase with CertDB but that would mean having certs.py moved to ipalib/install so that it's in a reasonable spot which I am not sure is worth it.

@stlaz
Copy link
Contributor Author

stlaz commented Feb 14, 2017

NSSDatabase now defaults its .password_file to .sec_dir + 'pwdfile.txt'. It's necessary to create a pwdfile.txt in Dogtag cert store so that actions like CA renew function properly even with FIPS.

@@ -1521,6 +1521,11 @@ def upgrade_configuration():
api.env.realm, certs.NSS_DIR, host_name=api.env.host)
ca_running = ca.is_running()

# create passswd.txt file in PKI_TOMCAT_ALIAS_DIR if it does not exist
# this file will be required on most actions over this NSS DB in FIPS
if not os.path.exists(paths.PKI_TOMCAT_ALIAS_DIR, 'passwd.txt'):
Copy link
Contributor

Choose a reason for hiding this comment

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

It's pwdfile.txt.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like I got somehow obsessed with passwd.txt for some reason. Fixed.

@stlaz
Copy link
Contributor Author

stlaz commented Feb 15, 2017

This patchset seems more like a cleanup after the privilege separation one, although adding a password to certutil calls is still the main topic here.

@stlaz stlaz changed the title No NSS database passwords in ipa-client-install Add password file to certutil calls in ipapython.certdb module Feb 15, 2017
Copy link
Contributor

@tkrizek tkrizek left a comment

Choose a reason for hiding this comment

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

Everything except the server upgrade bit looks fine.

@@ -1543,6 +1543,11 @@ def upgrade_configuration():
api.env.realm, paths.IPA_RADB_DIR, host_name=api.env.host)
ca_running = ca.is_running()

# create passswd.txt file in PKI_TOMCAT_ALIAS_DIR if it does not exist
# this file will be required on most actions over this NSS DB in FIPS
if not os.path.exists(paths.PKI_TOMCAT_ALIAS_DIR, 'pwdfile.txt'):
Copy link
Contributor

Choose a reason for hiding this comment

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

os.path.exists takes only a single argument, the file path needs to be joined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was the original intention, thanks.

NSSDatabases should call certutil with a password. Also, removed
`password_filename` argument from `.create_db()`.

https://fedorahosted.org/freeipa/ticket/5695
Replaced CertDB with NSSDatabase.
@tkrizek tkrizek added the ack Pull Request approved, can be merged label Feb 17, 2017
@MartinBasti MartinBasti added the pushed Pull Request has already been pushed label Feb 17, 2017
@stlaz stlaz deleted the certdb_passwd branch September 11, 2017 10:48
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
4 participants