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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: always check authn_http's header and ssl_option #10449

Merged
merged 5 commits into from Apr 21, 2023

Conversation

zhongwencool
Copy link
Member

@zhongwencool zhongwencool commented Apr 19, 2023

Fixes EMQX-9631

If the ssl_options and header configurations are set incorrectly when creating authn_http, it could result in the entire authn being unusable.

Before

we can create an authn_http with {ssl_options.enable=false, url = "https://xxx"}, but https must enable ssl_options.enable.

After

image

Summary

馃 Generated by Copilot at dfb7bbf

Added and improved validation functions and tests for the http authentication backend in emqx_authn. Fixed some minor issues and updated the version number.

PR Checklist

Please convert it to a draft if any of the following conditions are not met. Reviewers may skip over until all the items are checked:

  • Added tests for the changes
  • Changed lines covered in coverage report
  • Change log has been added to changes/{ce,ee}/(feat|perf|fix)-<PR-id>.en.md files
  • For internal contributor: there is a jira ticket to track this change
  • If there should be document changes, a PR to emqx-docs.git is sent, or a jira ticket is created to follow up
  • Schema changes are backward compatible

Checklist for CI (.github/workflows) changes

  • If changed package build workflow, pass this action (manual trigger)
  • Change log has been added to changes/ dir for user-facing artifacts update

@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 4741588951

  • 25 of 26 (96.15%) changed or added relevant lines in 2 files are covered.
  • 47 unchanged lines in 18 files lost coverage.
  • Overall coverage decreased (-0.06%) to 81.227%

Changes Missing Coverage Covered Lines Changed/Added Lines %
apps/emqx_authn/src/simple_authn/emqx_authn_http.erl 14 15 93.33%
Files with Coverage Reduction New Missed Lines %
apps/emqx_bridge/src/emqx_bridge.erl 1 91.27%
apps/emqx_dashboard/src/emqx_dashboard_monitor.erl 1 65.97%
apps/emqx_gateway_mqttsn/src/emqx_mqttsn_frame.erl 1 64.04%
apps/emqx/src/emqx_cm.erl 1 91.44%
apps/emqx/src/emqx_flapping.erl 1 87.27%
apps/emqx/src/emqx_limiter/src/emqx_limiter_server.erl 1 88.62%
apps/emqx/src/emqx_listeners.erl 1 87.18%
apps/emqx/src/emqx_quic_data_stream.erl 1 75.21%
apps/emqx/src/emqx_stats.erl 1 91.67%
apps/emqx_connector/src/emqx_connector_jwt_worker.erl 2 92.54%
Totals Coverage Status
Change from base Build 4738782761: -0.06%
Covered Lines: 25598
Relevant Lines: 31514

馃挍 - Coveralls

@@ -207,3 +209,27 @@ array(Name) ->

array(Name, DescId) ->
{Name, ?HOCON(?R_REF(Name), #{desc => ?DESC(DescId)})}.

validations() ->
Copy link
Contributor

Choose a reason for hiding this comment

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

Will these validations be called for listener-specific authentications?

Copy link
Member Author

Choose a reason for hiding this comment

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

No.
Right now, hocon can't do that.

Copy link
Member Author

Choose a reason for hiding this comment

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

But we will deprecated listener-specific authentications in the future.

apps/emqx_authn/src/simple_authn/emqx_authn_http.erl Outdated Show resolved Hide resolved
@@ -46,6 +46,103 @@ array_nodes_test() ->
),
ok.

authn_validations_test() ->
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to put the unit tests of authn in emqx_conf instead of the authn application?

apps/emqx_conf/test/emqx_conf_schema_tests.erl Outdated Show resolved Hide resolved
"",
Conf = <<BaseConf/binary, (list_to_binary(DisableSSLWithHttps))/binary>>,
{ok, ConfMap} = hocon:binary(Conf, #{format => richmap}),
?assertThrow(
Copy link
Member

Choose a reason for hiding this comment

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

We also need a test to cover all cases where the checks have passed.

changes/ce/fix-10449.en.md Outdated Show resolved Hide resolved
@zhongwencool zhongwencool force-pushed the authn-http-validation branch 2 times, most recently from e5314ad to d288327 Compare April 21, 2023 04:04
@zhongwencool zhongwencool merged commit 451934d into emqx:master Apr 21, 2023
123 of 124 checks passed
@zhongwencool zhongwencool deleted the authn-http-validation branch April 21, 2023 06:27
@zhongwencool zhongwencool mentioned this pull request Apr 21, 2023
8 tasks
<<"get">> ->
case maps:is_key(<<"content-type">>, Headers) of
false -> ok;
true -> <<"HTTP GET requests cannot include content-type header.">>
Copy link
Member

Choose a reason for hiding this comment

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

if we add this restriction, i guess Kjell fixed an issue for nothing in ehttpc ?

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.

None yet

5 participants