You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "sevensolutions (via GitHub)" <gi...@apache.org> on 2023/09/28 19:40:15 UTC
[GitHub] [apisix] sevensolutions opened a new pull request, #10278: feat: add token support for consul discovery (#9532)
sevensolutions opened a new pull request, #10278:
URL: https://github.com/apache/apisix/pull/10278
### Description
This PR adds support for ACL tokens when using consul service discovery as described in #9532.
Note: This PR does not yet add token support for consul_kv because i've never used consul_kv and don't know exactly how to test it.
### Checklist
- [x] I have explained the need for this PR and the problem it solves
- [x] I have explained the changes or the new features added to this PR
- [x] I have added tests corresponding to this change
- [x] I have updated the documentation to reflect this change
- [x] I have verified that this change is backward compatible (If not, please discuss on the [APISIX mailing list](https://github.com/apache/apisix/tree/master#community) first)
<!--
Note
1. Mark the PR as draft until it's ready to be reviewed.
2. Always add/update tests for any changes unless you have a good reason.
3. Always update the documentation to reflect the changes made in the PR.
4. Make a new commit to resolve conversations instead of `push -f`.
5. To resolve merge conflicts, merge master instead of rebasing.
6. Use "request review" to notify the reviewer after making changes.
7. Only a reviewer can mark a conversation as resolved.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add token support for consul discovery (#9532) [apisix]
Posted by "shreemaan-abhishek (via GitHub)" <gi...@apache.org>.
shreemaan-abhishek commented on code in PR #10278:
URL: https://github.com/apache/apisix/pull/10278#discussion_r1346767304
##########
apisix/discovery/consul/init.lua:
##########
@@ -197,21 +197,22 @@ local function get_opts(consul_server, is_catalog)
port = consul_server.port,
connect_timeout = consul_server.connect_timeout,
read_timeout = consul_server.read_timeout,
+ default_args = {
+ token = consul_server.token,
+ }
}
if not consul_server.keepalive then
return opts
end
if is_catalog then
- opts.default_args = {
- wait = consul_server.wait_timeout, --blocked wait!=0; unblocked by wait=0
- index = consul_server.catalog_index,
- }
+ opts.default_args.wait = consul_server.wait_timeout --blocked wait!=0; unblocked by wait=0
Review Comment:
this conditional can be simplified.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add token support for consul discovery (#9532) [apisix]
Posted by "monkeyDluffy6017 (via GitHub)" <gi...@apache.org>.
monkeyDluffy6017 commented on code in PR #10278:
URL: https://github.com/apache/apisix/pull/10278#discussion_r1349450629
##########
apisix/discovery/consul/init.lua:
##########
@@ -197,21 +197,22 @@ local function get_opts(consul_server, is_catalog)
port = consul_server.port,
connect_timeout = consul_server.connect_timeout,
read_timeout = consul_server.read_timeout,
+ default_args = {
+ token = consul_server.token,
+ }
}
if not consul_server.keepalive then
return opts
end
if is_catalog then
- opts.default_args = {
- wait = consul_server.wait_timeout, --blocked wait!=0; unblocked by wait=0
- index = consul_server.catalog_index,
- }
+ opts.default_args.wait = consul_server.wait_timeout --blocked wait!=0; unblocked by wait=0
+ opts.default_args.index = consul_server.catalog_index
+ opts.default_args.token = consul_server.token
Review Comment:
Why do you add `opts.default_args.token = consul_server.token` again, you have done this at line 200 ~ 202.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add token support for consul discovery (#9532) [apisix]
Posted by "shreemaan-abhishek (via GitHub)" <gi...@apache.org>.
shreemaan-abhishek commented on code in PR #10278:
URL: https://github.com/apache/apisix/pull/10278#discussion_r1346772543
##########
apisix/discovery/consul/init.lua:
##########
@@ -197,21 +197,22 @@ local function get_opts(consul_server, is_catalog)
port = consul_server.port,
connect_timeout = consul_server.connect_timeout,
read_timeout = consul_server.read_timeout,
+ default_args = {
+ token = consul_server.token,
+ }
}
if not consul_server.keepalive then
return opts
end
if is_catalog then
Review Comment:
this conditional can be simplified
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add token support for consul discovery (#9532) [apisix]
Posted by "monkeyDluffy6017 (via GitHub)" <gi...@apache.org>.
monkeyDluffy6017 merged PR #10278:
URL: https://github.com/apache/apisix/pull/10278
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add token support for consul discovery (#9532) [apisix]
Posted by "sevensolutions (via GitHub)" <gi...@apache.org>.
sevensolutions commented on code in PR #10278:
URL: https://github.com/apache/apisix/pull/10278#discussion_r1347781547
##########
apisix/discovery/consul/init.lua:
##########
@@ -197,21 +197,22 @@ local function get_opts(consul_server, is_catalog)
port = consul_server.port,
connect_timeout = consul_server.connect_timeout,
read_timeout = consul_server.read_timeout,
+ default_args = {
+ token = consul_server.token,
+ }
}
if not consul_server.keepalive then
return opts
end
if is_catalog then
Review Comment:
Thx, yes of course. I just wanted to change as less as possible. I'll change it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add token support for consul discovery (#9532) [apisix]
Posted by "shreemaan-abhishek (via GitHub)" <gi...@apache.org>.
shreemaan-abhishek commented on PR #10278:
URL: https://github.com/apache/apisix/pull/10278#issuecomment-1752040534
please fix the failing tests
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add token support for consul discovery (#9532) [apisix]
Posted by "monkeyDluffy6017 (via GitHub)" <gi...@apache.org>.
monkeyDluffy6017 commented on code in PR #10278:
URL: https://github.com/apache/apisix/pull/10278#discussion_r1349451023
##########
ci/pod/docker-compose.first.yml:
##########
@@ -46,6 +46,15 @@ services:
networks:
consul_net:
+ consul_3:
+ image: hashicorp/consul:1.16.2
Review Comment:
Why not use consul:1.7 like above example?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add token support for consul discovery (#9532) [apisix]
Posted by "sevensolutions (via GitHub)" <gi...@apache.org>.
sevensolutions commented on code in PR #10278:
URL: https://github.com/apache/apisix/pull/10278#discussion_r1349491678
##########
apisix/discovery/consul/init.lua:
##########
@@ -197,21 +197,22 @@ local function get_opts(consul_server, is_catalog)
port = consul_server.port,
connect_timeout = consul_server.connect_timeout,
read_timeout = consul_server.read_timeout,
+ default_args = {
+ token = consul_server.token,
+ }
}
if not consul_server.keepalive then
return opts
end
if is_catalog then
- opts.default_args = {
- wait = consul_server.wait_timeout, --blocked wait!=0; unblocked by wait=0
- index = consul_server.catalog_index,
- }
+ opts.default_args.wait = consul_server.wait_timeout --blocked wait!=0; unblocked by wait=0
+ opts.default_args.index = consul_server.catalog_index
+ opts.default_args.token = consul_server.token
Review Comment:
Yeah, that was a mistake sorry. I've fixed it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add token support for consul discovery (#9532) [apisix]
Posted by "shreemaan-abhishek (via GitHub)" <gi...@apache.org>.
shreemaan-abhishek commented on PR #10278:
URL: https://github.com/apache/apisix/pull/10278#issuecomment-1751694519
Is it okay to not consider the `re-run` case and expect `error_code: 200`? Because in the CI if during a re-run all systems start from scratch.
If you are testing manually in your machine consider restarting the docker container or something.
I hope I didn't get you wrong 😂
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add token support for consul discovery (#9532) [apisix]
Posted by "shreemaan-abhishek (via GitHub)" <gi...@apache.org>.
shreemaan-abhishek commented on code in PR #10278:
URL: https://github.com/apache/apisix/pull/10278#discussion_r1346767304
##########
apisix/discovery/consul/init.lua:
##########
@@ -197,21 +197,22 @@ local function get_opts(consul_server, is_catalog)
port = consul_server.port,
connect_timeout = consul_server.connect_timeout,
read_timeout = consul_server.read_timeout,
+ default_args = {
+ token = consul_server.token,
+ }
}
if not consul_server.keepalive then
return opts
end
if is_catalog then
- opts.default_args = {
- wait = consul_server.wait_timeout, --blocked wait!=0; unblocked by wait=0
- index = consul_server.catalog_index,
- }
+ opts.default_args.wait = consul_server.wait_timeout --blocked wait!=0; unblocked by wait=0
Review Comment:
this conditional can be simplified.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add token support for consul discovery (#9532) [apisix]
Posted by "monkeyDluffy6017 (via GitHub)" <gi...@apache.org>.
monkeyDluffy6017 commented on PR #10278:
URL: https://github.com/apache/apisix/pull/10278#issuecomment-1742591429
Good job!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add token support for consul discovery (#9532) [apisix]
Posted by "sevensolutions (via GitHub)" <gi...@apache.org>.
sevensolutions commented on PR #10278:
URL: https://github.com/apache/apisix/pull/10278#issuecomment-1751685603
This is the complete test:
```
=== TEST 13: bootstrap acl
--- config
location /v1/acl {
proxy_pass http://127.0.0.1:8502;
}
--- request eval
"PUT /v1/acl/bootstrap\n" . "{\"BootstrapSecret\": \"2b778dd9-f5f1-6f29-b4b4-9a5fa948757a\"}"
--- error_code eval
qr/200|403/
```
Yes the result alternates. It returns 200 the first time but every re-run will return 403 because the ACL system can only be bootstrapped once. And because testing the ACL bootstrap procedure of consul is not the case here, I would say both retrurn codes are fine.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add token support for consul discovery (#9532) [apisix]
Posted by "sevensolutions (via GitHub)" <gi...@apache.org>.
sevensolutions commented on code in PR #10278:
URL: https://github.com/apache/apisix/pull/10278#discussion_r1349493060
##########
ci/pod/docker-compose.first.yml:
##########
@@ -46,6 +46,15 @@ services:
networks:
consul_net:
+ consul_3:
+ image: hashicorp/consul:1.16.2
Review Comment:
Tests aren't passing using consul 1.7 because i think it has a bug. It doesn't bootstrap the ACL system using my predefined token and always creates a new random one. It's also not recommended anymore to use the docker images without the *hashicorp/* prefix.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add token support for consul discovery (#9532) [apisix]
Posted by "sevensolutions (via GitHub)" <gi...@apache.org>.
sevensolutions commented on PR #10278:
URL: https://github.com/apache/apisix/pull/10278#issuecomment-1752050098
> please fix the failing tests
I'am trying but i've no clue yet why they're failing...
What is needed to run `t/control/discovery.t` locally?
I've tried
```
sudo make ci-env-up project_compose_ci=ci/pod/docker-compose.common.yml
sudo make ci-env-up project_compose_ci=ci/pod/docker-compose.first.yml
TEST_NGINX_BINARY=/usr/bin/openresty prove -It/test-nginx/lib -I./ -r t/control/discovery.t
```
But i always get:
```
# Failed test 't/control/discovery.t TEST 6: dump consul_kv services - status code ok'
# at /usr/local/share/perl/5.34.0/Test/Nginx/Socket.pm line 936.
# got: '500'
# expected: '200'
# Failed test 't/control/discovery.t TEST 6: dump consul_kv services - response_body - response is expected (repeated req 0, req 0)'
# at /usr/local/share/perl/5.34.0/Test/Nginx/Socket.pm line 1660.
# got: '<html>
# <head><title>500 Internal Server Error</title></head>
# <body>
# <center><h1>500 Internal Server Error</h1></center>
# <hr><center>openresty/1.21.4.2</center>
# </body>
# </html>
# '
# expected: '{"http://127.0.0.1:8500/v1/kv/upstreams/webpages/":[{"host":"127.0.0.1","port":30511,"weight":1},{"host":"127.0.0.1","port":30512,"weight":1}],"http://127.0.0.1:8600/v1/kv/upstreams/webpages/":[{"host":"127.0.0.1","port":30513,"weight":1},{"host":"127.0.0.1","port":30514,"weight":1}]}
# '
# Failed test 't/control/discovery.t TEST 6: dump consul_kv services - pattern "[error]" should not match any line in error.log but matches line "2023/10/08 15:05:26 [error] 2546684#2546684: *3 lua entry thread aborted: runtime error: content_by_lua(nginx.conf:184):2: module 'toolkit.json' not found:" (req 0)
# no field package.preload['toolkit.json']
# no file '/home/daniel/apisix/toolkit/json.lua'
# no file '/home/daniel/apisix/toolkit/json/init.lua'
# no file '/home/daniel/apisix/deps/share/lua/5.1/toolkit/json/init.lua'
# no file '/home/daniel/apisix/deps/share/lua/5.1/toolkit/json.lua'
# no file '/home/daniel/apisix/apisix/toolkit/json.lua'
# no file '/home/daniel/apisix/t/toolkit/json.lua'
# no file '/home/daniel/apisix/t/xrpc/toolkit/json.lua'
# no file '/home/daniel/apisix/t/xrpc/toolkit/json/init.lua'
# '
# at /usr/local/share/perl/5.34.0/Test/Nginx/Socket.pm line 1351.
t/control/discovery.t .. 37/? # Looks like you failed 7 tests of 37.
t/control/discovery.t .. Dubious, test returned 7 (wstat 1792, 0x700)
Failed 7/37 subtests
```
even on the main branch.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add token support for consul discovery (#9532) [apisix]
Posted by "shreemaan-abhishek (via GitHub)" <gi...@apache.org>.
shreemaan-abhishek commented on PR #10278:
URL: https://github.com/apache/apisix/pull/10278#issuecomment-1751678975
Could you please share the complete test case?
> The reason is, that bootstrapping the ACL twice is not allowed which returns 403 which is totally fine.
Do the test case results alternate between 200 and 403? If it returns 403 every time you can just check for the 403 error code 🤔
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add token support for consul discovery (#9532) [apisix]
Posted by "sevensolutions (via GitHub)" <gi...@apache.org>.
sevensolutions commented on PR #10278:
URL: https://github.com/apache/apisix/pull/10278#issuecomment-1751703656
> Is it okay to not consider the `re-run` case and expect `error_code: 200`? Because in the CI if during a re-run all systems start from scratch.
>
> If you are testing manually in your machine consider restarting the docker container or something.
>
> I hope I didn't get you wrong 😂
The thing is that i'am sharing the consul docker instance between the test files consul.t and consul_kv.t.
My idea was to add this test to both files because it's needed for the following tests to be executed.
Or is there a guaranteed order in which the test files are beeing executed?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add token support for consul discovery (#9532) [apisix]
Posted by "sevensolutions (via GitHub)" <gi...@apache.org>.
sevensolutions commented on PR #10278:
URL: https://github.com/apache/apisix/pull/10278#issuecomment-1752331883
@monkeyDluffy6017 can you please re-run the failed chaos-test workflow? It couldnt install helm for some reason.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add token support for consul discovery (#9532) [apisix]
Posted by "monkeyDluffy6017 (via GitHub)" <gi...@apache.org>.
monkeyDluffy6017 commented on PR #10278:
URL: https://github.com/apache/apisix/pull/10278#issuecomment-1751583449
Good job! please resolve the review comments, thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] feat: add token support for consul discovery (#9532) [apisix]
Posted by "sevensolutions (via GitHub)" <gi...@apache.org>.
sevensolutions commented on PR #10278:
URL: https://github.com/apache/apisix/pull/10278#issuecomment-1751668362
> please support `consul_kv` as well.
@shreemaan-abhishek I'am working on that.
Can anyone please tell me how to write an assert for accepting one of two error codes?
I tried:
```
--- error_code eval
qr/200|403/
```
but this doesn't seem to work. It doesn't match but according to Regex101 it should.
The error is:
```
got: '403'
expected: '(?^:200|403)'
```
The reason is, that bootstrapping the ACL twice is not allowed which returns 403 which is totally fine.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org