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

Multi tenancy auth #3063

Merged
merged 14 commits into from
Apr 7, 2021
Merged

Multi tenancy auth #3063

merged 14 commits into from
Apr 7, 2021

Conversation

DenysGonchar
Copy link
Collaborator

@DenysGonchar DenysGonchar commented Mar 30, 2021

This PR introduces the new callback supported_features/0 for auth backends:

  • for now there is the only one optional feature - dynamic_domains.
  • currently only ejabberd_auth_dummy supports dynamic_domains feature.
  • all other auth modules must be rechecked and adopted in order to
    support this feature.
  • the following things must be done per auth module:
    • recheck that ejabberd_auth set_opts and get_opt interfaces are
      used with host type, not domain name.
    • recheck that mongoose_scram interfaces are used with host type,
      not domain name.
    • recheck that ejabberd_config get_local_option interfaces are
      used with host type, not domain name.
    • create proper tests to ensure that auth module works correctly
      with dynamic domains.

In order to reduce the number of calls to mongoose_domain_api:get_host_type/1 HostType parameter is added to some callbacks of ejabberd_gen_auth behaviour.

to run test execute:
   test-runner.sh --skip-cover --skip-small-tests --preset pgsql_mnesia --db pgsql -- dynamic_domains_pm:can_authenticate
@DenysGonchar DenysGonchar changed the base branch from master to multi-tenancy-phase-1 March 30, 2021 23:46
@codecov
Copy link

codecov bot commented Mar 31, 2021

Codecov Report

Merging #3063 (b6df430) into multi-tenancy-phase-1 (f991ee2) will increase coverage by 0.61%.
The diff coverage is 89.01%.

Impacted file tree graph

@@                    Coverage Diff                    @@
##           multi-tenancy-phase-1    #3063      +/-   ##
=========================================================
+ Coverage                  78.09%   78.71%   +0.61%     
=========================================================
  Files                        374      386      +12     
  Lines                      31219    31643     +424     
=========================================================
+ Hits                       24382    24909     +527     
+ Misses                      6837     6734     -103     
Impacted Files Coverage Δ
src/admin_extra/service_admin_extra.erl 100.00% <ø> (ø)
src/ejabberd_gen_sm.erl 90.90% <ø> (ø)
src/ejabberd_local.erl 62.68% <0.00%> (-1.50%) ⬇️
src/ejabberd_users.erl 81.63% <ø> (ø)
src/muc_light/mod_muc_light_db_mnesia.erl 89.47% <ø> (+4.47%) ⬆️
src/offline/mod_offline_mnesia.erl 51.47% <0.00%> (ø)
src/pubsub/pubsub_form_utils.erl 56.60% <0.00%> (+1.04%) ⬆️
src/rdbms/rdbms_queries_mssql.erl 100.00% <ø> (ø)
src/auth/ejabberd_auth_pki.erl 17.64% <20.00%> (ø)
src/auth/ejabberd_auth_external.erl 29.12% <38.46%> (ø)
... and 108 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b5ad312...b6df430. Read the comment docs.

@DenysGonchar DenysGonchar force-pushed the multi-tenancy-auth branch 3 times, most recently from 46c4ef3 to 7d46418 Compare April 6, 2021 01:32
introducing the new callback supported_features/0:
  * for now there is the only one optional feature - dynamic_domains.
  * currently only ejabberd_auth_dummy supports dynamic_domains feature.
  * all other auth modules must be rechecked and adopted in order to
    support dynamic_domains feature.
  * the following things must be done per auth module:
       - recheck that ejabberd_auth set_opts and get_opt interfaces are
         used with host type, not domain name.
       - recheck that mongoose_scram interfaces are used with host type,
         not domain name.
       - recheck that ejabberd_config get_local_option interfaces are
         used with host type, not domain name.
       - create proper tests to ensure that auth module works correctly
         with dynamic domains.

commit verified with the following commands:
   test-runner.sh --skip-cover --skip-small-tests --preset pgsql_mnesia --db pgsql -- dynamic_domains_pm:can_authenticate
   ./rebar3 dialyzer
verified with commands:
   tools/setup-redis.sh
   ./rebar3 ct
tested with this command:
   ./rebar3 ct --suite auth_dummy_SUITE --case supports_dynamic_domains
tested with command:
   ./rebar3 ct --suite config_parser_SUITE --group host_types_group
it causes execution of meck:unload in parallel which results in spontaneous failuers.
tested with:
   ./rebar3 ct --suite config_parser_SUITE
Copy link
Member

@chrzaszcz chrzaszcz left a comment

Choose a reason for hiding this comment

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

Lots of good work! Just a few comments from me.

Also: please take care of the failing tests and update the description.

big_tests/tests/dynamic_domains_pm_SUITE.erl Outdated Show resolved Hide resolved
src/auth/ejabberd_auth_anonymous.erl Outdated Show resolved Hide resolved
test/auth_http_SUITE.erl Show resolved Hide resolved
test/commands_SUITE.erl Show resolved Hide resolved
test/config_parser_SUITE.erl Show resolved Hide resolved
src/config/mongoose_config_parser.erl Show resolved Hide resolved
@@ -29,6 +29,7 @@
tls_options = [],
tls_verify :: verify_none | verify_peer,
authenticated = false :: authenticated_state(),
host_type = <<>> :: binary(),
Copy link
Member

Choose a reason for hiding this comment

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

Is there any reason to set an empty host type?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

otherwise, dialyzer complains :)

Copy link
Member

Choose a reason for hiding this comment

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

Hm... maybe it has a reason to complain? What is the error? If it's in tests, then ok, but are you sure that we won't get an empty binary for an online user?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it complains that undefined is not binary() type. and nope - we won't have it empty for an online user.
we set a valid host_type at the very early stage of a session, actually authentication is impossible without it.

Copy link
Contributor

Choose a reason for hiding this comment

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

could be binary() | undefined type

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Then it will complain about usage of undefined type everywhere where only binary() is expected.
There is no problem with the current type definition, there is no problem with the default value either.

Copy link
Member

Choose a reason for hiding this comment

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

I like what @arcusfelis suggested. Dialyzer does not complain, I checked it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Dialyzer doesn't complain about it right now, because we don't really use that field yet. But we will start in the following PRs, I'm absolutely against this change. Dialyzer is not smart enough to understand FSM lifecycle and understand that in some state it cannot be undefined any more.
empty binary is the same illegal value for the host type as undefined, we cannot configure it in toml.

Copy link
Member

Choose a reason for hiding this comment

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

I still think Dialyzer would not complain because of how success typing works. However, it is a minor thing for me and I can merge the changes as they are now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

did some extra tests, looks you're right. will change it in the following PR.

src/auth/ejabberd_auth.erl Show resolved Hide resolved
Copy link
Member

@chrzaszcz chrzaszcz left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@chrzaszcz chrzaszcz merged commit 4171b6f into multi-tenancy-phase-1 Apr 7, 2021
@chrzaszcz chrzaszcz deleted the multi-tenancy-auth branch April 7, 2021 08:27
Copy link
Contributor

@arcusfelis arcusfelis left a comment

Choose a reason for hiding this comment

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

looks reasonable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants