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

Placeholders such as ${cert_subject} in JWT AuthN do not work #13256

Open
tigercl opened this issue Jun 14, 2024 · 4 comments
Open

Placeholders such as ${cert_subject} in JWT AuthN do not work #13256

tigercl opened this issue Jun 14, 2024 · 4 comments

Comments

@tigercl
Copy link
Contributor

tigercl commented Jun 14, 2024

What happened?

Now ${cert_subject} and ${cert_common_name} in JWT authentication are not replaced with actual values ​​at runtime.

The authn configuration is as follows:

image

What did you expect to happen?

Make placeholders work

How can we reproduce it (as minimally and precisely as possible)?

No response

Anything else we need to know?

No response

EMQX version

EMQX 5.7.0

OS version

macOS 13

Log files

@tigercl tigercl added the BUG label Jun 14, 2024
@tigercl
Copy link
Contributor Author

tigercl commented Jun 14, 2024

After this issue is fixed, there is still a risk of crash.

In function replace_placeholder of module emqx_authn_jwt.erl:

replace_placeholder(L, Variables) ->
    replace_placeholder(L, Variables, []).

replace_placeholder([], _Variables, Acc) ->
    Acc;
replace_placeholder([{Name, {placeholder, PL}} | More], Variables, Acc) ->
    Value = maps:get(PL, Variables),
    replace_placeholder(More, Variables, [{Name, Value} | Acc]);
replace_placeholder([{Name, Value} | More], Variables, Acc) ->
    replace_placeholder(More, Variables, [{Name, Value} | Acc]).

If there is no corresponding key in Variables, then maps:get(PL, Variables) will crash, as mentioned in Issue#13253, this is possible when fail_if_no_peer_cert is set to false.

@zmstone zmstone added Feature and removed BUG labels Jun 14, 2024
@zmstone
Copy link
Member

zmstone commented Jun 14, 2024

This is not a bug, but a feature request.
JWT authn only supports placeholders for clientid and username to check against the JWT claims.
A workaround for now is to use peer_cert_as_username or peer_cert_as_clientid.

@tigercl
Copy link
Contributor Author

tigercl commented Jun 14, 2024

@zmstone But EMQX documentation does not mention that the placeholders supported by JWT authn are different from other authn: authentication-placeholders

@tigercl
Copy link
Contributor Author

tigercl commented Jun 17, 2024

I found it: JWT AuthN

image

Maybe it's time to support it.

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

No branches or pull requests

3 participants