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

cert-request: match names against principal aliases #227

Conversation

frasertweedale
Copy link
Contributor

@frasertweedale frasertweedale commented Nov 10, 2016

Currently we do not check Kerberos principal aliases when validating
a CSR. Enhance cert-request to accept the following scenarios:

  • for hosts and services: CN and SAN dnsNames match a principal
    alias (realm and service name must be same as nominated principal)

  • for all principal types: UPN or KRB5PrincipalName othername match
    any principal alias.

Fixes: https://fedorahosted.org/freeipa/ticket/6295

@frasertweedale frasertweedale force-pushed the feature/6432-cert-request-san-princ-alias branch 2 times, most recently from 8fb85f2 to 6156cf7 Compare November 14, 2016 01:15
@frasertweedale frasertweedale changed the title cert-request: match names against principal alises cert-request: match names against principal aliases Nov 14, 2016
@martbab martbab self-assigned this Nov 14, 2016
@martbab
Copy link
Contributor

martbab commented Nov 14, 2016

@frasertweedale What is the intended semantics of the checks against principal aliases in SAN? If the requestor can use only the aliases belonging to the entry of the recieving principal, then it should be enough to retrieve the entry by searching for the 'krbprincipalname' from --principal option, retrieve it, and then checking whether all values of dnsName/KRB5PrincipalName are a subset of Kerberos principal aliases.

@martbab
Copy link
Contributor

martbab commented Nov 14, 2016

Also, the current execution flow of the command is very confusing (retrieving objects based on intended principal types etc.). As a part of the ticket I was planning to do a sneaky refactoring of the flow which IMHO should look like this:

1.) you search entries by krbprincipalname extracted from 'principal' option (or from bind principal)

2.) If not found, you error out that such entry could not be found

3.) due to syntax overrides in ipaldap, all returned principals will be converted to Principal objects so after you retrieve the entry and ensure that it exists you can test whether it is service, user, etc.

4.) for values in SAN, you check whether the value is already container in the entries principals (as you do in this PR). If the principal is not there, you can try to retrieve the entry from ldap and either error out if not found, or check CA ACLs against it when present.

5.) if all is OK, forward the request to RA backend and issue the certificate.

Do you think that this would extend the scope of the ticket too much? If yes, I can open a separate ticket for this cleanup and do it on top of your work.

@martbab
Copy link
Contributor

martbab commented Nov 14, 2016

Also one of the tests in caacl_profile_enforcement suite fails:
https://paste.fedoraproject.org/481011/12920714/

@frasertweedale
Copy link
Contributor Author

@martbab thanks for review; I will revisit this some time in next week (hopefully)

@frasertweedale
Copy link
Contributor Author

@martbab

Semantics:

  1. Subject principal is looked up by --principal option, via {PRINCIPAL_TYPE}_show command. If you think this should be extended to allow --principal to use an alias, I am cool with that.
  2. For host and service principals, CN must match[dns](described below) a principal alias.
  3. For host and service principals, SAN dnsNames must match[dns] a principal alias, or match an alternative principal.
  4. For all principals, SAN KRB5PrincipalName and UPN values must match[exact] a principal alias.

match[dns]: iterate principal aliases. Matches if: alias has same realm as --principal and alias has same service name as --principal and alias hostname equals (case insensitively) the SAN dnsName value. (If we generalise --principal to search all aliases then I would recommend restricting the search to principals with same realm and service name as the krbcanonicalname of the returned principal).


w.r.t. test failure, I cannot reproduce with this patch rebased on latest master.

@frasertweedale
Copy link
Contributor Author

@martbab I agree with doing the refactor you propose, but I deem it out of scope for this ticket.

Doing that refactor entails a cleanup of how we handle the LDAP ;binary transfer encoding option, because this is currently not consistent across user, host and service plugins.

So... do we want to look at getting this merged soon?

@martbab
Copy link
Contributor

martbab commented Dec 2, 2016

I agree that it is out of scope of this work and will open a separate ticket for the cert-request refactoring.


# ignore aliases with different realm or service name from
# subject principal
if alias.realm != principal.realm:
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: we (currently) do not support aliases w/ realm that is different than IPA realm (*-add-principal will error out loudly) so I am not sure whether we require this check.

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'm going to leave it in anyway. It does no harm and is one less potential bug if we do ever support aliases with different realms, somehow.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok


"""
aliases = set(principal_obj.get('krbprincipalname', []))
for alias in principal_obj.get('krbcanonicalname', []):
Copy link
Contributor

Choose a reason for hiding this comment

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

As per http://www.freeipa.org/page/V4/Kerberos_principal_aliases the canonical name MUST be listed among the values of 'krbprincipalname' attribute so there is no need to explicitly add it here (results in a no-op all the time).

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, thanks. I've removed function _collect_princpial_aliases() and just replaced with principal_obj.get('krbprincipalname', []) at call sites.


@pytest.mark.tier1
class TestPrincipalAliasForSubjectAltNameDnsName(SubjectAltNameOneServiceBase):
"""Sign certificate request with an invalid SAN dnsName.
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy-paste error in the docstring here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, thanks. Corrected in updated patch.

self, santest_service_host_1):
api.Command.service_add_principal(
santest_service_host_1.name,
'srv/santest-host-2.ipa.local')
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 santest_host_2 fixture here and use santest_1_host_2.attrs['krbcanonicalname'][0] to construct the alias instead of hard-coding the alias name as string. This test fails due to adding principal name for srv/santest-host-2.ipa.local while the service name in fixture is srv/santest-host-2.ipa.*test*

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for clarifying. I was wonder how the test was failing. It is obvious now thanks to your explanation :)

@martbab
Copy link
Contributor

martbab commented Dec 2, 2016

There are small issues I found in the patch. Please address those.

@apophys can quickly you review the new test cases? they pass (except for one pointed out in review) so they should be valid and OK.

@frasertweedale frasertweedale force-pushed the feature/6432-cert-request-san-princ-alias branch from 6156cf7 to b84e266 Compare December 5, 2016 11:26
except ValueError:
return False

return principal in principal_obj.get('krbprincpialname', [])
Copy link
Contributor

Choose a reason for hiding this comment

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

Please fix typo in attribute name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hah, silly fat fingers. push incoming

Currently we do not check Kerberos principal aliases when validating
a CSR.  Enhance cert-request to accept the following scenarios:

- for hosts and services: CN and SAN dnsNames match a principal
  alias (realm and service name must be same as nominated principal)

- for all principal types: UPN or KRB5PrincipalName othername match
  any principal alias.

Fixes: https://fedorahosted.org/freeipa/ticket/6295
@frasertweedale frasertweedale force-pushed the feature/6432-cert-request-san-princ-alias branch from b84e266 to c347ff8 Compare December 5, 2016 11:31
@apophys
Copy link
Contributor

apophys commented Dec 5, 2016

The tests look good to me.

@martbab martbab added the ack Pull Request approved, can be merged label Dec 5, 2016
@martbab martbab added the pushed Pull Request has already been pushed label Dec 6, 2016
@martbab
Copy link
Contributor

martbab commented Dec 6, 2016

@martbab martbab closed this Dec 6, 2016
@frasertweedale frasertweedale deleted the feature/6432-cert-request-san-princ-alias branch December 7, 2016 00:18
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