fix(s3): mark S3 secrets as `sensitive` in schema

This commit is contained in:
Andrew Mayorov 2023-04-19 19:05:12 +03:00
parent 04523b3f81
commit f06300cbed
No known key found for this signature in database
GPG Key ID: 2837C62ACFBFED5D
2 changed files with 26 additions and 2 deletions

View File

@ -12,6 +12,7 @@
-export([roots/0, fields/1, namespace/0, tags/0, desc/1]).
-export([translate/1]).
-export([translate/2]).
roots() ->
[s3].
@ -36,7 +37,8 @@ fields(s3) ->
string(),
#{
desc => ?DESC("secret_access_key"),
required => false
required => false,
sensitive => true
}
)},
{bucket,
@ -142,7 +144,10 @@ desc(transport_options) ->
"Options for the HTTP transport layer used by the S3 client".
translate(Conf) ->
Options = #{atom_key => true},
translate(Conf, #{}).
translate(Conf, OptionsIn) ->
Options = maps:merge(#{atom_key => true}, OptionsIn),
#{s3 := TranslatedConf} = hocon_tconf:check_plain(
emqx_s3_schema, #{<<"s3">> => Conf}, Options, [s3]
),

View File

@ -108,6 +108,25 @@ t_full_config(_Config) ->
})
).
t_sensitive_config_hidden(_Config) ->
?assertMatch(
#{
access_key_id := "access_key_id",
secret_access_key := <<"******">>
},
emqx_s3_schema:translate(
#{
<<"bucket">> => <<"bucket">>,
<<"host">> => <<"s3.us-east-1.endpoint.com">>,
<<"port">> => 443,
<<"access_key_id">> => <<"access_key_id">>,
<<"secret_access_key">> => <<"secret_access_key">>
},
% NOTE: this is what Config API handler is doing
#{obfuscate_sensitive_values => true}
)
).
t_invalid_limits(_Config) ->
?assertException(
throw,