fix(connectors): redact authorization headers when creating/updating connectors

Fixes https://emqx.atlassian.net/browse/EMQX-11895
This commit is contained in:
Thales Macedo Garitezi 2024-02-23 10:17:24 -03:00
parent a73fd07c49
commit b60b19a29a
3 changed files with 15 additions and 5 deletions

View File

@ -48,7 +48,7 @@
]). ]).
%% for other http-like connectors. %% for other http-like connectors.
-export([redact_request/1]). -export([redact_request/1, is_sensitive_key/1]).
-export([validate_method/1, join_paths/2]). -export([validate_method/1, join_paths/2]).

View File

@ -1,7 +1,7 @@
%% -*- mode: erlang -*- %% -*- mode: erlang -*-
{application, emqx_connector, [ {application, emqx_connector, [
{description, "EMQX Data Integration Connectors"}, {description, "EMQX Data Integration Connectors"},
{vsn, "0.1.38"}, {vsn, "0.1.39"},
{registered, []}, {registered, []},
{mod, {emqx_connector_app, []}}, {mod, {emqx_connector_app, []}},
{applications, [ {applications, [

View File

@ -137,7 +137,7 @@ create(Type, Name, Conf0, Opts) ->
msg => "create connector", msg => "create connector",
type => Type, type => Type,
name => Name, name => Name,
config => emqx_utils:redact(Conf0) config => redact(Conf0, Type)
}), }),
TypeBin = bin(Type), TypeBin = bin(Type),
ResourceId = resource_id(Type, Name), ResourceId = resource_id(Type, Name),
@ -174,7 +174,7 @@ update(Type, Name, {OldConf, Conf}, Opts) ->
msg => "update connector", msg => "update connector",
type => Type, type => Type,
name => Name, name => Name,
config => emqx_utils:redact(Conf) config => redact(Conf, Type)
}), }),
case recreate(Type, Name, Conf, Opts) of case recreate(Type, Name, Conf, Opts) of
{ok, _} -> {ok, _} ->
@ -184,7 +184,7 @@ update(Type, Name, {OldConf, Conf}, Opts) ->
msg => "updating_a_non_existing_connector", msg => "updating_a_non_existing_connector",
type => Type, type => Type,
name => Name, name => Name,
config => emqx_utils:redact(Conf) config => redact(Conf, Type)
}), }),
create(Type, Name, Conf, Opts); create(Type, Name, Conf, Opts);
{error, Reason} -> {error, Reason} ->
@ -378,3 +378,13 @@ override_start_after_created(Config, Opts) ->
set_no_buffer_workers(Opts) -> set_no_buffer_workers(Opts) ->
Opts#{spawn_buffer_workers => false}. Opts#{spawn_buffer_workers => false}.
%% TODO: introduce a formal callback?
redact(Conf, Type) when
Type =:= http;
Type =:= <<"http">>
->
%% CE bridge
emqx_utils:redact(Conf, fun emqx_bridge_http_connector:is_sensitive_key/1);
redact(Conf, _Type) ->
emqx_utils:redact(Conf).