Skip to content

Conversation

@SkyeYoung
Copy link
Member

@SkyeYoung SkyeYoung commented Sep 12, 2025

Description

This PR is a part of #12603 and is separated out due to breaking changes.

Currently, the jwt-auth plugin generates a random value for
conf.secret in the check_schema function when conf.algorithm ~= "RS256" and conf.algorithm ~= "ES256" and not conf.secret.

Modifying the user-provided configuration can easily lead to user
confusion, which is clearly not best practice.

This also affects the diff logic in the adc that the apisix ingress
controller depends on.

I believe this generation behavior should be removed. To solve this problem, This PR removed the corresponding code and
instead return an error message, requiring users to fill in the
corresponding configuration themselves.

Which issue(s) this PR fixes:

Fixes #

Checklist

@SkyeYoung SkyeYoung marked this pull request as ready for review September 12, 2025 02:16
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Sep 12, 2025
@SkyeYoung SkyeYoung changed the title feat(jwt-auth): when algorithm is not RS256 or ES256, require the user to fill in secret feat(jwt-auth): when algorithm is not RS256 or ES256, require the user to fill in secret Sep 12, 2025

if conf.algorithm ~= "RS256" and conf.algorithm ~= "ES256" and not conf.secret then
conf.secret = ngx_encode_base64(resty_random.bytes(32, true))
if (conf.algorithm == "HS256" or conf.algorithm == "HS512") and not conf.secret then
Copy link
Member Author

Choose a reason for hiding this comment

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

@SkyeYoung SkyeYoung requested a review from nic-6443 September 12, 2025 03:46
nic-6443
nic-6443 previously approved these changes Sep 12, 2025
Comment on lines 1238 to 1242
if not ok then
ngx.say(err)
else
ngx.say("done")
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a suggestion: using assert is enough.

assert(ok, "HS256 but secret is not required")

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Copy link
Contributor

@bzp2010 bzp2010 left a comment

Choose a reason for hiding this comment

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

Maybe this PR should be called change(jwt-auth): xxx 🤔

@SkyeYoung
Copy link
Member Author

change

@bzp2010 This is not very common. I usually refer to https://github.com/TrigenSoftware/simple-release/blob/main/GUIDE.md

Since this feature did not exist before, it should be feat 🤔

@SkyeYoung SkyeYoung requested a review from nic-6443 September 12, 2025 09:26
@bzp2010
Copy link
Contributor

bzp2010 commented Sep 12, 2025

If the change prefix is not used, special attention must be paid to these changes during release and they must be marked as non-backward-compatible modifications.
This may cause trouble in the next release process.

@SkyeYoung SkyeYoung changed the title feat(jwt-auth): when algorithm is not RS256 or ES256, require the user to fill in secret change(jwt-auth): when algorithm is not RS256 or ES256, require the user to fill in secret Sep 12, 2025
@SkyeYoung SkyeYoung merged commit 78a5512 into apache:master Sep 12, 2025
34 of 35 checks passed
@SkyeYoung SkyeYoung deleted the young/feat/jwt-auth/error-msg-instead-of-gen-secret branch September 12, 2025 10:33
jizhuozhi pushed a commit to jizhuozhi/apisix that referenced this pull request Oct 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants