-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat: support hide the authentication header in basic-auth with a config #6039
feat: support hide the authentication header in basic-auth with a config #6039
Conversation
…to unzip received response data" This reverts commit dc2570a
Signed-off-by: mango <xu.weiKyrie@foxmail.com>
Signed-off-by: mango <xu.weiKyrie@foxmail.com>
Signed-off-by: mango <xu.weiKyrie@foxmail.com>
Signed-off-by: mango <xu.weiKyrie@foxmail.com>
feat: support hide the authentication header in basic-auth
apisix/plugins/basic-auth.lua
Outdated
@@ -161,6 +170,11 @@ function _M.rewrite(conf, ctx) | |||
return 401, { message = "Password is error" } | |||
end | |||
|
|||
-- 5. hide `Authentication` header if `hide_auth_header` is `true` | |||
if conf.hide_auth_header == true then | |||
core.response.set_header("Authentication", "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems you misunderstand the original issue. We want to hide the request header.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My fault. Done.
Signed-off-by: mango <xu.weiKyrie@foxmail.com>
apisix/plugins/basic-auth.lua
Outdated
properties = { | ||
hide_auth_header = { | ||
type = "boolean", | ||
default = true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the default value should be false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
docs/zh/latest/plugins/basic-auth.md
Outdated
@@ -43,6 +43,7 @@ title: basic-auth | |||
| -------- | ------ | ------ | ------ | ------ | ------------------------------------------------------------------------------------------------------------------ | | |||
| username | string | 必须 | | | 不同的 `consumer` 对象应有不同的值,它应当是唯一的。不同 consumer 使用了相同的 `username` ,将会出现请求匹配异常。 | | |||
| password | string | 必须 | | | 用户的密码 | | |||
| hide_auth_header | boolean | 可选 | true | | 是否将 Authentication 请求头返回给客户端. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| hide_auth_header | boolean | 可选 | true | | 是否将 Authentication 请求头返回给客户端. | | |
| hide_auth_header | boolean | 可选 | false | | 是否将 Authentication 请求头传递给 upstream。 | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
docs/en/latest/plugins/basic-auth.md
Outdated
| Name | Type | Requirement | Default | Valid | Description | | ||
| -------- | ------ | ----------- | ------- | ----- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| username | string | required | | | Different `consumer` should have different value which is unique. When different `consumer` use a same `username`, a request matching exception would be raised. | | ||
| password | string | required | | | the user's password | | ||
| hide_auth_header | boolean | optional | true | | Whether to return the Authentication request headers to the client. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Name | Type | Requirement | Default | Valid | Description | | |
| -------- | ------ | ----------- | ------- | ----- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | | |
| username | string | required | | | Different `consumer` should have different value which is unique. When different `consumer` use a same `username`, a request matching exception would be raised. | | |
| password | string | required | | | the user's password | | |
| hide_auth_header | boolean | optional | true | | Whether to return the Authentication request headers to the client. | | |
| Name | Type | Requirement | Default | Valid | Description | | |
| -------- | ------ | ----------- | ------- | ----- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | | |
| username | string | required | | | Different `consumer` should have different value which is unique. When different `consumer` use a same `username`, a request matching exception would be raised. | | |
| password | string | required | | | the user's password | | |
| hide_auth_header | boolean | optional | true | | Whether to return the Authentication request headers to the upstream. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
apisix/plugins/basic-auth.lua
Outdated
@@ -39,6 +44,10 @@ local consumer_schema = { | |||
properties = { | |||
username = { type = "string" }, | |||
password = { type = "string" }, | |||
hide_auth_header = { | |||
type = "boolean", | |||
default = true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default = true, | |
default = false, |
Need to discuss it in maillist if use true
as default value
apisix/plugins/basic-auth.lua
Outdated
-- 5. hide `Authentication` request header if `hide_auth_header` is `true` | ||
if conf.hide_auth_header == true then | ||
core.request.set_header(ctx, "Authentication", "") | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original issue seems to avoid to send the header to upstream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, use core.request.set_header(ctx, "Authentication", nil)
can avoid.
apisix/plugins/basic-auth.lua
Outdated
properties = { | ||
hide_auth_header = { | ||
type = "boolean", | ||
default = true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default = true, | |
default = true, |
Ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Signed-off-by: mango <xu.weiKyrie@foxmail.com>
apisix/plugins/basic-auth.lua
Outdated
@@ -30,7 +30,12 @@ local consumers_lrucache = core.lrucache.new({ | |||
local schema = { | |||
type = "object", | |||
title = "work with route or service object", | |||
properties = {}, | |||
properties = { | |||
hide_auth_header = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hide_credentials
would be better? Kong uses this field in their basic-auth.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
apisix/plugins/basic-auth.lua
Outdated
@@ -39,6 +44,10 @@ local consumer_schema = { | |||
properties = { | |||
username = { type = "string" }, | |||
password = { type = "string" }, | |||
hide_auth_header = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need to configure it in the consumer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
docs/en/latest/plugins/basic-auth.md
Outdated
| -------- | ------ | ----------- | ------- | ----- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| username | string | required | | | Different `consumer` should have different value which is unique. When different `consumer` use a same `username`, a request matching exception would be raised. | | ||
| password | string | required | | | the user's password | | ||
| hide_auth_header | boolean | optional | false | | Whether to return the Authentication request headers to the upstream. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's distinguish route conf from the consumer's like this one: https://github.com/apache/apisix/blob/master/docs/en/latest/plugins/ldap-auth.md#attributes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
…e docs Signed-off-by: mango <xu.weiKyrie@foxmail.com>
…e docs Signed-off-by: mango <xu.weiKyrie@foxmail.com>
apisix/plugins/basic-auth.lua
Outdated
@@ -161,6 +166,11 @@ function _M.rewrite(conf, ctx) | |||
return 401, { message = "Password is error" } | |||
end | |||
|
|||
-- 5. hide `Authentication` request header if `hide_credentials` is `true` | |||
if conf.hide_credentials == true then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if conf.hide_credentials == true then | |
if conf.hide_credentials then |
is ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
and need to add test cases to cover this. I see that you have test cases in your previous submission records…… |
docs/en/latest/plugins/basic-auth.md
Outdated
|
||
| Name | Type | Requirement | Default | Valid | Description | | ||
| -------- | ------ | ----------- | ------- | ----- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| hide_credentials | boolean | optional | false | | Whether to return the Authentication request headers to the upstream. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| hide_credentials | boolean | optional | false | | Whether to return the Authentication request headers to the upstream. | | |
| hide_credentials | boolean | optional | false | | Whether to pass the Authentication request headers to the upstream. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Signed-off-by: mango <xu.weiKyrie@foxmail.com>
docs/en/latest/plugins/basic-auth.md
Outdated
For consumer side: | ||
|
||
| Name | Type | Requirement | Default | Valid | Description | | ||
| -------- | ------ | ----------- | ------- | ----- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| username | string | required | | | Different `consumer` should have different value which is unique. When different `consumer` use a same `username`, a request matching exception would be raised. | | ||
| password | string | required | | | the user's password | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mangoGoForward IMHO there's no need to change this. How about revert it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mangoGoForward Please revert some changes in English docs, others look good to me. Thanks.
Signed-off-by: mango <xu.weiKyrie@foxmail.com>
t/plugin/basic-auth.t
Outdated
@@ -20,6 +20,7 @@ repeat_each(2); | |||
no_long_string(); | |||
no_root_location(); | |||
no_shuffle(); | |||
log_level('info'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mangoGoForward please take a check whether this change is needed. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems unnecessary, removed.
Signed-off-by: mango <xu.weiKyrie@foxmail.com>
@mangoGoForward |
That's strange, it's good when I run I will test again on ubuntu later, If you know the error's location, please help me to improve, Thanks. |
Strange, I had no problem checking the format of this test case. |
…header revert: "feat: support hide the authentication header in basic-auth"
…-auth"" This reverts commit a1deeef Signed-off-by: mango <xu.weiKyrie@foxmail.com>
Signed-off-by: mango <xu.weiKyrie@foxmail.com>
Signed-off-by: mango <xu.weiKyrie@foxmail.com>
@mangoGoForward The changes look good to me. Could you explain why you committed several other commits after Zexuan's approval? Thanks. |
I want to trigger the actions of my forked repo, so I commit a PR to my repo's master branch, and got file conflict when merged from master, so i commit 8440045 to resolved. but the master branch's code is polluted, so I revert the commit to 49b7850, and I also checked those file changes, it is same as 49b7850, I'm sorry about troubled your review work. |
@mangoGoForward Got it and thanks. Let's wait for the CI. :-) |
@spacewander @mangoGoForward The CI job failure of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes look good to me.
Hi @mangoGoForward , thank you for your contribution! Here is the Contributor T-shirt form[1], if you're interested, kindly take a look :) [1] https://github.com/apache/apisix/blob/master/CONTRIBUTING.md#contributor-t-shirt |
Thanks. |
What this PR does / why we need it:
Resolves #5900
Pre-submission checklist: