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

[Py3] ipa-server-install #428

Closed
wants to merge 11 commits into from
Closed

[Py3] ipa-server-install #428

wants to merge 11 commits into from

Conversation

MartinBasti
Copy link
Contributor

@MartinBasti MartinBasti commented Jan 31, 2017

This PR allows to install ipa server using PY3 (CA, no DNS, no KRA, no CA-less, no external CA) and uninstall it (ipa-server-install --uninstall)

Functionality depends on #427

os.close(dmpwdfd)
NTF = tempfile.NamedTemporaryFile
dir = paths.VAR_LIB_IPA
with NTF("w", dir=dir) as dmpwdfile, NTF("w", dir=dir) as admpwdfile:
Copy link
Member

@tiran tiran Jan 31, 2017

Choose a reason for hiding this comment

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

urks, the code is getting even less readable. dir shadows a builtin, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to avoid extra indentation, I can use full form with backlashes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can be this?

        dir_ipa = paths.VAR_LIB_IPA
        with tempfile.NamedTemporaryFile("w", dir=dir_ipa) as dmpwdfile, \
                tempfile.NamedTemporaryFile("w", dir=dir_ipa) as admpwdfile:
            dmpwdfile.write(self.dm_password)
            dmpwdfile.flush()

Copy link
Contributor

Choose a reason for hiding this comment

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

How about

        ...
        def tempf():
            return tempfile.NamedTemporaryFile('w', dir=paths.VAR_LIB_IPA)
        with tempf() as dmpwdfile, tempf() as admpwdfile:
            ...

?

delval = unicode(base64.b64encode(delval))
raise errors.AttrValueNotFound(attr=attr, value=delval)
delval = base64.b64encode(delval).decode('ascii')
raise errors.AttrValueNotFound(attr=attr, value=delval)
Copy link
Member

Choose a reason for hiding this comment

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

Same issue as in PR #427

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will rebase it, half of this PR is PR #427 , thats why it is WIP

configparser.get() changed in python3 and `raw` is now a keyword attribute.

Also it must be set to True, otherwise InterpolationSyntaxError is raised

'''
InterpolationSyntaxError: '%' must be followed by '%' or '(', found:
'%2fvar%2frun%2fslapd-EXAMPLE-COM.socket'
'''

https://fedorahosted.org/freeipa/ticket/4985
basedn in custodia related modules has type bytes, that causes issues in
Py3 when strings were concatenated with bytes

```
malformed RDN string = "cn=custodia,cn=ipa,cn=etc,b'dc=example,dc=com'"
```

https://fedorahosted.org/freeipa/ticket/4985
Exception is too brod and may hide various issues that show up later. If
the code expects that entry may exist, then ldap.ALREADY_EXISTS
exception should be used
ldap ldif parser requires to have input file opened in textual mode

https://fedorahosted.org/freeipa/ticket/4985
...and vice versa
backup requires string not bytes, but ldap provide bytes thus data must
be decoded and encoded from restore

https://fedorahosted.org/freeipa/ticket/4985
Also code was rewritten to use NamedTemporaryFile with context

https://fedorahosted.org/freeipa/ticket/4985
Convert function to NamedTemporaryFile with textual mode, because
passwords are text. Using `with` and NamedTemporaryFile gives more
security agains leaking password from tempfiles.

https://fedorahosted.org/freeipa/ticket/4985
@MartinBasti MartinBasti changed the title [WIP] [Py3] ipa-server-install [Py3] ipa-server-install Feb 8, 2017
@@ -859,7 +859,7 @@ def ipa_generate_password(entropy_bits=256, uppercase=1, lowercase=1, digits=1,
# NSS function sftk_newPinCheck() in nss/lib/softoken/fipstokn.c.
for charclass_name in ['digits', 'uppercase', 'lowercase', 'special']:
charclass = pwd_charsets[charclass_name]
todo_characters = req_classes[charclass_name]
todo_characters = req_classes[charclass_name] or 0
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? req_classes is constructed from integer arguments, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it can contain None, None == character class will not be used

b'groupOfPrincipals']),
('cn', name.encode('utf-8')),
('ipaKeyUsage', RFC5280_USAGE_MAP[usage].encode('utf-8')),
('memberPrincipal', principal.encode('utf-8')),
Copy link
Contributor

Choose a reason for hiding this comment

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

How hard would it be to refactor this to use ipaldap (which handles encoding for you)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I saw that custodia related modules are not using ipalib, so I'm not sure if this is on purpose or just NIH, so I don't know. I'm afraid I dont have enough time to refactor it.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK.

@@ -181,7 +180,7 @@ def __init__(self, config=None, ipaconf=paths.IPA_DEFAULT_CONF):
self.realm = conf.get('global', 'realm')
self.ldap_uri = config.get('ldap_uri', None)
if self.ldap_uri is None:
self.ldap_uri = conf.get('global', 'ldap_uri', None)
self.ldap_uri = conf.get('global', 'ldap_uri', raw=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

How hard would it be to refactor this to use ipalib.config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or why not to use API when this is in ldap context? We have to find first why custodia related modules is not using api, ipalib

Copy link
Contributor

Choose a reason for hiding this comment

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

OK.

The one cannot compare None and Int in Py3
"""
unorderable types: NoneType() > int()
"""

Continue when class is disabled with None value

https://fedorahosted.org/freeipa/ticket/4985
@HonzaCholasta HonzaCholasta added the ack Pull Request approved, can be merged label Feb 10, 2017
@HonzaCholasta HonzaCholasta added the pushed Pull Request has already been pushed label Feb 10, 2017
@MartinBasti MartinBasti deleted the py3-server branch February 10, 2017 14:16
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
3 participants