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 initial Domains REST API endpoint #17

Merged
merged 5 commits into from
Mar 23, 2023
Merged

Conversation

f-trivino
Copy link
Collaborator

This PR implements an API endpoint that allows making GET, POST, PUT, and PATCH requests to read, create, and update Domain objects.

This implementation includes helper functions in utils.py responsible for configuring SSSD service accordingly.

@f-trivino f-trivino force-pushed the domains branch 3 times, most recently from ecd6d02 to a5d33f9 Compare January 13, 2023 12:25
@f-trivino f-trivino changed the title WIP Add initial Domains REST API endpoint Add initial Domains REST API endpoint Jan 13, 2023
Copy link
Collaborator

@flo-renaud flo-renaud left a comment

Choose a reason for hiding this comment

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

Hi @f-trivino
please find some inline comments.
I didn't manage to run the delete domain part, or get domain. Not sure what is missing, though...

src/ipa-tuura/domains/models.py Outdated Show resolved Hide resolved
src/ipa-tuura/domains/models.py Outdated Show resolved Hide resolved
src/install/requirements.txt Outdated Show resolved Hide resolved
src/ipa-tuura/domains/views.py Outdated Show resolved Hide resolved
src/ipa-tuura/domains/utils.py Outdated Show resolved Hide resolved
src/ipa-tuura/domains/utils.py Outdated Show resolved Hide resolved
@f-trivino f-trivino force-pushed the domains branch 9 times, most recently from 36db1d8 to dfcc725 Compare February 16, 2023 17:46
This commit is also adding packages to requirements.txt for the Domains REST API

Based on: https://www.django-rest-framework.org/#installation

Signed-off-by: Francisco Trivino <[email protected]>
@flo-renaud
Copy link
Collaborator

Hi @f-trivino
When I add or remove a domain I see the following errors in the django console:

Internal Server Error: /domains/v1/domain/
Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/ipalib/rpc.py", line 644, in get_auth_info
    response = self._sec_context.step()
  File "/usr/lib/python3.10/site-packages/decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "/usr/lib64/python3.10/site-packages/gssapi/_utils.py", line 155, in check_last_err
    return func(self, *args, **kwargs)
  File "/usr/lib/python3.10/site-packages/decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "/usr/lib64/python3.10/site-packages/gssapi/_utils.py", line 128, in catch_and_return_token
    return func(self, *args, **kwargs)
  File "/usr/lib64/python3.10/site-packages/gssapi/sec_contexts.py", line 523, in step
    return self._initiator_step(token=token)
  File "/usr/lib64/python3.10/site-packages/gssapi/sec_contexts.py", line 539, in _initiator_step
    res = rsec_contexts.init_sec_context(self._target_name, self._creds,
  File "gssapi/raw/sec_contexts.pyx", line 246, in gssapi.raw.sec_contexts.init_sec_context
gssapi.raw.exceptions.MissingCredentialsError: Major (458752): No credentials were supplied, or the credentials were unavailable or inaccessible, Minor (2529639053): No Kerberos credentials available (default cache: KCM:)

The code is probably missing a step after ipa-client-install in order to create the admin keytab.

Copy link
Collaborator

@flo-renaud flo-renaud left a comment

Choose a reason for hiding this comment

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

Hi @f-trivino
please find my first comments

src/ipa-tuura/domains/views.py Outdated Show resolved Hide resolved
src/ipa-tuura/domains/views.py Outdated Show resolved Hide resolved
description = models.TextField(blank=True)

# The connection URL to the identity server
integration_domain_url = models.CharField(max_length=255)
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the provider is IPA, is this field optional? With the autodiscovery mechanism it is not required.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good catch, it is mandatory always. Would it be ok to fix this in next PRs?

Copy link
Collaborator

Choose a reason for hiding this comment

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

sure


# container image should contain the user and group
# groupadd scim
args = ['groupadd', 'scim']
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is the purpose of this local user "scim"? Is it only to store the keytab for ipatuura->ipa communication?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yep, that's right, folder: /var/lib/ipa/ipatuura/

@f-trivino f-trivino force-pushed the domains branch 4 times, most recently from bbbfa08 to 6651045 Compare March 15, 2023 07:51
Copy link
Collaborator

@flo-renaud flo-renaud left a comment

Choose a reason for hiding this comment

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

Hi @f-trivino

I tested mainly the ipa provider and will continue tomorrow with ad and ldap providers. First comments:

  • right now, the Domains rest api does not require any authentication but it should be protected and restricted to the django admin user.
  • a call to delete a domain with a wrong id does not return any error, IMO it should mention something like "No such domain".
  • if a wrong client id/password is provided, ipa-client-install fails but this error is not well handled
  • if 2 calls are done to add the same domain, the rest api does not complain but we end up with 2 domains in the sql db and only one in sssd.conf. Removing any of these domains results in an inconsistency (one remaining domain in sql, but no domain in sssd.conf).

description = models.TextField(blank=True)

# The connection URL to the identity server
integration_domain_url = models.CharField(max_length=255)
Copy link
Collaborator

Choose a reason for hiding this comment

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

sure

Copy link
Collaborator

@flo-renaud flo-renaud left a comment

Choose a reason for hiding this comment

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

Hi @f-trivino
please find additional comments for LDAP and AD providers

else:
if domain['id_provider'] == 'ad':
join_ad_realm(domain)
config_default_sssd(domain)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Calling realm join already creates sssd.conf, with different settings:

[sssd]
config_file_version = 2
domains = ad.test
services = nss, pam, ifp

[nss]
timeout = 60

[pam]
timeout = 60

[ifp]
user_attributes = +sn, +givenname, +lock, +mail


[domain/ad.test]
default_shell = /bin/bash
krb5_store_password_if_offline = True
cache_credentials = True
krb5_realm = AD.TEST
realmd_tags = manages-system joined-with-adcli 
id_provider = ad
fallback_homedir = /home/%u@%d
ad_domain = ad.test
use_fully_qualified_names = True
ldap_id_mapping = True
access_provider = ad

Not sure that this call to config_default_sssd is needed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

For the ldap provider, which authentication method is used? it's possible to set ldap_krb5_keytab or ldap_default_bind_dn but I didn't find if ipatuura is configuring any.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The code right now is performing a simple bind with password. This needs to be improved, following issue ticket #28 talks about enabling TLS support.

I fixed sssd.conf and now ldap_default_bind_dn is added. I'm re-using client_id content for the bind_dn for now.

@f-trivino
Copy link
Collaborator Author

Hi @f-trivino

I tested mainly the ipa provider and will continue tomorrow with ad and ldap providers. First comments:

* right now, the Domains rest api does not require any authentication but it should be protected and restricted to the django admin user.

* a call to delete a domain with a wrong id does not return any error, IMO it should mention something like "No such domain".

* if a wrong client id/password is provided, ipa-client-install fails but this error is not well handled

* if 2 calls are done to add the same domain, the rest api does not complain but we end up with 2 domains in the sql db and only one in sssd.conf. Removing any of these domains results in an inconsistency (one remaining domain in sql, but no domain in sssd.conf).

Thanks @flo-renaud , I've filed tickets to address these issues:
#23
#24
#25

@f-trivino f-trivino force-pushed the domains branch 2 times, most recently from 4d7b310 to f454a30 Compare March 22, 2023 21:53
This commit implements an API endpoint that allows making GET, POST, PUT, and PATCH
requests to read, create, and update Domain objects.

This implementation includes helper functions in utils.py responsible for configuring
sssd service accordingly.

Signed-off-by: Francisco Trivino <[email protected]>
This commit adds the migrations based on the Domains model.

Signed-off-by: Francisco Trivino <[email protected]>
This commit adds swagger as a documentation generator for REST framework as well as
an easy way to test the domains administrative end-points.

Signed-off-by: Francisco Trivino <[email protected]>
This commit adds missing code to extend writable interface to write
back user modifications for attributes defined in AD integration
domain.

Signed-off-by: Francisco Trivino <[email protected]>
Copy link
Collaborator

@flo-renaud flo-renaud left a comment

Choose a reason for hiding this comment

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

Ok for merging, will open tickets for any discovered issue

@f-trivino f-trivino merged commit 7c4d682 into freeipa:main Mar 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants