-
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
Changes from 12 commits
dc2570a
f0d6f6f
3845a27
db0c9e7
0cee869
79ca875
9a9565c
10d35fd
c642635
29d3077
1c42db0
7a663fa
6e8d684
ec3bec6
37076a7
484d05d
63aa704
210c9d5
cb53193
395ac1a
25602a7
41bb17e
49b7850
a1deeef
4fc743f
8440045
8531227
31af04d
ccc46b6
1b0ffe4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 = { | ||||||
type = "boolean", | ||||||
default = true, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Ditto There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||
} | ||||||
}, | ||||||
} | ||||||
|
||||||
local consumer_schema = { | ||||||
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||
type = "boolean", | ||||||
default = true, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Need to discuss it in maillist if use |
||||||
} | ||||||
}, | ||||||
required = {"username", "password"}, | ||||||
} | ||||||
|
@@ -161,6 +170,11 @@ function _M.rewrite(conf, ctx) | |||||
return 401, { message = "Password is error" } | ||||||
end | ||||||
|
||||||
-- 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Yes, use |
||||||
consumer.attach_consumer(ctx, cur_consumer, consumer_conf) | ||||||
|
||||||
core.log.info("hit basic-auth access") | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -39,10 +39,11 @@ For more information on Basic authentication, refer to [Wiki](https://en.wikiped | |||||||||||||||||||||
|
||||||||||||||||||||||
## Attributes | ||||||||||||||||||||||
|
||||||||||||||||||||||
| 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 | | ||||||||||||||||||||||
| 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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||||||||||||||||||
|
||||||||||||||||||||||
## How To Enable | ||||||||||||||||||||||
|
||||||||||||||||||||||
|
@@ -129,8 +130,8 @@ hello, world | |||||||||||||||||||||
## Disable Plugin | ||||||||||||||||||||||
|
||||||||||||||||||||||
When you want to disable the `basic-auth` plugin, it is very simple, | ||||||||||||||||||||||
you can delete the corresponding json configuration in the plugin configuration, | ||||||||||||||||||||||
no need to restart the service, it will take effect immediately: | ||||||||||||||||||||||
you can delete the corresponding json configuration in the plugin configuration, | ||||||||||||||||||||||
no need to restart the service, it will take effect immediately: | ||||||||||||||||||||||
|
||||||||||||||||||||||
```shell | ||||||||||||||||||||||
$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d ' | ||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
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.