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 certificate mapping library #192

Closed
wants to merge 10 commits into from

Conversation

sumit-bose
Copy link
Contributor

This is the last major part related to https://pagure.io/SSSD/sssd/issue/3050.
With this users and certificates cannot only be mapped by adding the full
certificate to the user's LDAP entry but based on rules.

The library itself is in the third patch and the rules are described in the
included sss-certmap man page. I tried to cover most of the functionality by
unit tests.

@lslebodn
Copy link
Contributor

There are few missing files:

  • xml for man page sss-certmap.5

  • src/lib/certmap/sss_certmap_attr_names.c
    make[2]: *** No rule to make target 'src/lib/certmap/sss_certmap_attr_names.c', needed by 'src/lib/certmap/libsss_certmap_la-sss_certmap_attr_names.lo'. Stop.

  • src/lib/certmap/sss_certmap_krb5_match.c

  • src/lib/certmap/sss_certmap_ldap_mapping.c

@lslebodn
Copy link
Contributor

Which library/project will be an external consument of libsss_certmap.so ?

@sumit-bose
Copy link
Contributor Author

oops, I'm sorry, I'm really sure I did run 'make distcheck' before sending the PR.

The library be used by IPA freeipa/freeipa#575.

@lslebodn
Copy link
Contributor

lslebodn commented Mar 14, 2017 via email

@sumit-bose
Copy link
Contributor Author

Hi,

Lukas, thank you for the review. I fixed the invalid read the two NULL RETURNS, the PW.SET_BUT_NOT_USED and the CLANG WARNING.

It would be possible to save the result in a variable for the CHECKED_RETURN

1003|-> NSS_ShutdownContext(nss_ctx);

but there is nothing which can be done with the variable so it would just produce a different warning, so I would suggest to ignore it.

Same with the regexec warning, add an otherwise unused variable would just cause a different warning.

@sumit-bose
Copy link
Contributor Author

retest this please

1 similar comment
@sumit-bose
Copy link
Contributor Author

retest this please

DEBUG(SSSDBG_CRIT_FAILURE,
"Failed to read user name hint option, skipping.\n");
}
continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it expected that we continue on both success and failure 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.

Yes, I think the log messages is sufficient here and the issue is not important enough to cause an error which would terminate the whole request.

}

ret = sysdb_attrs_get_uint32_t(reply[c], IPA_CERTMAP_PRIORITY,
&m->priority);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking here -- won't reading a nonexistent attribute set some priority we don't want (iow, is the default value, I guess zero, what we expect if the priority is not there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch, fixed

goto done;
}

sss_certmap_free_ctx(sdap_opts->certmap_ctx);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this expected that we first free the context and then steal it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, this updates the context stored in sdap_opts by first freeing any existing one and then adding the new one.

return NULL;
}

if (sd_ctx->ranges_search_bases == NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it needed to check the ranges_search_bases 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.

no, fixed

ret = ipa_subdomains_certmap_recv(subreq);
talloc_zfree(subreq);
if (ret != EOK) {
DEBUG(SSSDBG_CRIT_FAILURE, "Unable to get IPA ranges "
Copy link
Contributor

Choose a reason for hiding this comment

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

copy and paste error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -23,6 +23,7 @@
#ifndef IPA_HBAC_PRIVATE_H_
#define IPA_HBAC_PRIVATE_H_

#include "providers/ipa/ipa_config.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it needed to touch the HBAC header in this patch?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

}

static errno_t sysdb_certmap_add(struct sysdb_ctx *sysdb,
struct certmap_info *certmap)
Copy link
Contributor

Choose a reason for hiding this comment

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

If you end up changing this patch, please check the alignment 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.

fixed


done:
if (ret) {
DEBUG(SSSDBG_TRACE_FUNC, "Error: %d (%s)\n", ret, strerror(ret));
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 sss_strerror in new code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Makefile.am Outdated
$(NULL)
libsss_certmap_la_LDFLAGS = \
-Wl,--version-script,$(srcdir)/src/lib/certmap/sss_certmap.exports \
-version-info 0:0:0
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this a valid version or a placeholder until the API is stable? Would it make sense to add a ticket to increase the version info if it's supposed to be bumped later?

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 think 0:0:0 is ok for an initial version of a library. After we released it with a new version of SSSD we can follow the libtool version update rules when we add changes.

/**
* Typedef for external debug callback
*/
typedef void (sss_certmap_ext_debug)(void *private,
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a nitpick, but I would prefer a different argument name (pvt?) to avoid using a C++ keyword, because now my editor highlights the private word :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

* - ENOENT: certificate does not match
* - EINVAL: internal error
*/
int sss_certmap_get_search_filter(struct sss_certmap_ctx *ctx,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it expected that this call doesn't accept any talloc context and all the resulting filters are allocated atop the sss_certmap_ctx? I'm looking at get_filter for example. Is the expectation that the caller must free the filter by e.g. stealing it onto some private context?

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 sorry, I should have read the description of ss_certmap_free_filter_and_domains first :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I wanted to use talloc internally but thought the options we have in other libraries to allow to use different allocators make things just more complicates without a real benefit.

To free the data the caller should use sss_certmap_free_filter_and_domains(). I added a comment about it to the doctext for sss_certmap_get_search_filter.

@lslebodn
Copy link
Contributor

lslebodn commented Mar 21, 2017 via email

* @param[in] domains string array of domains returned by
* sss_certmap_get_search_filter
*/
void sss_certmap_free_filter_and_domains(char *filter, char **domains);
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see this function being called anywhere..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops, in the test it is not needed because I free the complete context there. But I added it to sss_cert_derb64_to_ldap_filter() where is was missing.

@jhrozek
Copy link
Contributor

jhrozek commented Mar 21, 2017

I won't pretend I read the certmap library code carefully, I more or less checked the API, ran the tests and scrolled through the library code. My only concern there is the memory allocations so that we don't grow the library memory context.

From functional side, the patches break D-Bus lookups by certificate for me. I didn't see any other issues against a (legacy, considering this functionality) IPA 4.4 server.

I don't have any other comments except those in this review and the D-Bus lookups.

@sumit-bose
Copy link
Contributor Author

Thank you for the review, the new versions also contains a fix for the default matching rule which we discussed on irc.

To be able to include split_on_separator() without additional
dependencies (only talloc), it is moved into a separate file.

Related to https://pagure.io/SSSD/sssd/issue/3050
To be able to include string_in_list() without additional
dependencies it is moved into a separate file.

Related to https://pagure.io/SSSD/sssd/issue/3050
With this library it would be possible to map certificates and users not
only by adding the full certificate to the user's LDAP object but by
adding e.g. only parts like the issuer and subject name. Additionally
the library is also able to flexible select/match certificates based on
values in the certificate.

Details about mapping and matching rules can be found in the included
man page.

Related to https://pagure.io/SSSD/sssd/issue/3050
@jhrozek
Copy link
Contributor

jhrozek commented Mar 23, 2017

Thank you, the patches now look good to me. I'm only waiting for the CI run before the final ACK, but it should be noted again that the review was mostly based on reading the code and checking for regressions. I didn't do a very thorough review of the cert mapping library, but given that it requires knowledge I don't have, it's well tested and the API looks OK, then I think the review is sufficient.

@jhrozek
Copy link
Contributor

jhrozek commented Mar 23, 2017

btw the bug with the D-Bus lookups is fixed with the new version.

@jhrozek jhrozek self-assigned this Mar 23, 2017
@lslebodn
Copy link
Contributor

There is an autoconf warning:

Makefile.am:1746: warning: libsss_certmap_la_DEPENDENCIES was already defined in condition TRUE, which includes condition !HAVE_NSS ...
Makefile.am:1722: ... 'libsss_certmap_la_DEPENDENCIES' previously defined here
Makefile.am: installing 'build/depcomp'

And there are libsss_certmap_openssl_la* flags even though libsss_certmap_openssl.so is not build.

and what about small lines de-duplication :-) Not tested.
https://paste.fedoraproject.org/paste/Vr2caTkNtn-cytVQyXPl1l5M1UNdIGYhyRLivL9gydE=/

@lslebodn lslebodn removed the Accepted label Mar 23, 2017
@lslebodn
Copy link
Contributor

lslebodn commented Mar 23, 2017

And there are few missing header files when compiling with libcrypto.

src/lib/certmap/sss_cert_content_crypto.c:22:26: error: unknown type name ‘TALLOC_CTX’
 int sss_cert_get_content(TALLOC_CTX *mem_ctx,
                          ^~~~~~~~~~
src/lib/certmap/sss_cert_content_crypto.c:23:32: error: unknown type name ‘uint8_t’
                          const uint8_t *der_blob, size_t der_size,
                                ^~~~~~~
src/lib/certmap/sss_cert_content_crypto.c:23:51: error: unknown type name ‘size_t’
                          const uint8_t *der_blob, size_t der_size,
                                                   ^~~~~~

diff:
https://paste.fedoraproject.org/paste/MlrGzY73CqDliU5zYUZOYV5M1UNdIGYhyRLivL9gydE=/

mapped_attrs can be a list of sysdb_attrs which are not available on
the server side but should be store with the cached user entry. This is
needed e.g. when the input to look up the user in LDAP is not an
attribute which is stored in LDAP but some data where LDAP attributes
are extracted from. The current use case is the certificate mapping
library which can create LDAP search filters based on content of the
certificate. To allow upcoming cache lookup to use the input directly it
is stored in the user object in the cache.

Related to https://pagure.io/SSSD/sssd/issue/3050
Store the certificate used to lookup a user as mapped attribute in the
cached user object.

Related to https://pagure.io/SSSD/sssd/issue/3050
Use certificate mapping library if available to lookup a user by
certificate in LDAP.

Related to https://pagure.io/SSSD/sssd/issue/3050
Add sysdb calls to write and read data for the certificate mapping
library to the cache.

Related to https://pagure.io/SSSD/sssd/issue/3050
Read certificate mapping data from the IPA server and configure the
certificate mapping library accordingly.

Related to https://pagure.io/SSSD/sssd/issue/3050
@sumit-bose
Copy link
Contributor Author

Hi Lukas, thank you for your patches, I included both of them in the latest versions.

@jhrozek
Copy link
Contributor

jhrozek commented Mar 23, 2017

@jhrozek jhrozek added Pushed and removed Accepted labels Mar 23, 2017
@jhrozek jhrozek closed this Mar 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants