-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add etcd auth support #1769
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
Merged
Merged
Add etcd auth support #1769
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
275eaa4
Add etcd auth support
shenal 7332542
[BUILD]
shenal ad3ffb3
Added etcd endpoints
shenal 2593134
Updated travis xenial->bionic
shenal 3f99d76
Fixed port number
shenal 82dde2e
Wait for etcd to start
shenal 3bebb61
Switch dist
shenal 21f1223
Start etcd manually
shenal 5485803
Fix perl path for Bionic
shenal ae258ea
Make Bionic default OS
shenal 11d1642
Rename test case
shenal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| BEGIN { | ||
| $ENV{"ETCD_ENABLE_AUTH"} = "false" | ||
| } | ||
|
|
||
| use t::APISIX 'no_plan'; | ||
|
|
||
| repeat_each(1); | ||
| no_long_string(); | ||
| no_root_location(); | ||
| log_level("info"); | ||
|
|
||
| # Authentication is enabled at etcd and credentials are set | ||
| system('etcdctl --endpoints="http://127.0.0.1:2376" -u root:5tHkHhYkjr6cQY user add root:5tHkHhYkjr6cQY'); | ||
| system('etcdctl --endpoints="http://127.0.0.1:2376" -u root:5tHkHhYkjr6cQY auth enable'); | ||
| system('etcdctl --endpoints="http://127.0.0.1:2376" -u root:5tHkHhYkjr6cQY role revoke --path "/*" -rw guest'); | ||
|
|
||
| run_tests; | ||
|
|
||
| # Authentication is disabled at etcd & guest access is granted | ||
| system('etcdctl --endpoints="http://127.0.0.1:2376" -u root:5tHkHhYkjr6cQY auth disable'); | ||
| system('etcdctl --endpoints="http://127.0.0.1:2376" -u root:5tHkHhYkjr6cQY role grant --path "/*" -rw guest'); | ||
|
|
||
|
|
||
| __DATA__ | ||
|
|
||
| === TEST 1: Set and Get a value pass | ||
| --- config | ||
| location /t { | ||
| content_by_lua_block { | ||
| local core = require("apisix.core") | ||
| local key = "/test_key" | ||
| local val = "test_value" | ||
| local res, err = core.etcd.set(key, val) | ||
| ngx.say(err) | ||
| } | ||
| } | ||
| --- request | ||
| GET /t | ||
| --- response_body | ||
| insufficient credentials code: 401 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| # | ||
shenal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # Licensed to the Apache Software Foundation (ASF) under one or more | ||
| # contributor license agreements. See the NOTICE file distributed with | ||
| # this work for additional information regarding copyright ownership. | ||
| # The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| # (the "License"); you may not use this file except in compliance with | ||
| # the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # | ||
| BEGIN { | ||
| $ENV{"ETCD_ENABLE_AUTH"} = "true" | ||
| } | ||
|
|
||
| use t::APISIX 'no_plan'; | ||
|
|
||
| repeat_each(1); | ||
| no_long_string(); | ||
| no_root_location(); | ||
| log_level("info"); | ||
|
|
||
| # Authentication is enabled at etcd and credentials are set | ||
| system('etcdctl --endpoints="http://127.0.0.1:2376" -u root:5tHkHhYkjr6cQY user add root:5tHkHhYkjr6cQY'); | ||
| system('etcdctl --endpoints="http://127.0.0.1:2376" -u root:5tHkHhYkjr6cQY auth enable'); | ||
| system('etcdctl --endpoints="http://127.0.0.1:2376" -u root:5tHkHhYkjr6cQY role revoke --path "/*" -rw guest'); | ||
|
|
||
| run_tests; | ||
|
|
||
| # Authentication is disabled at etcd & guest access is granted | ||
| system('etcdctl --endpoints="http://127.0.0.1:2376" -u root:5tHkHhYkjr6cQY auth disable'); | ||
| system('etcdctl --endpoints="http://127.0.0.1:2376" -u root:5tHkHhYkjr6cQY role grant --path "/*" -rw guest'); | ||
|
|
||
| __DATA__ | ||
|
|
||
| === TEST 1: Set and Get a value pass with authentication | ||
| --- config | ||
| location /t { | ||
| content_by_lua_block { | ||
| local core = require("apisix.core") | ||
| local key = "/test_key" | ||
| local val = "test_value" | ||
| core.etcd.set(key, val) | ||
| local res, err = core.etcd.get(key) | ||
| ngx.say(res.body.node.value) | ||
| core.etcd.delete(val) | ||
| } | ||
| } | ||
| --- request | ||
| GET /t | ||
| --- response_body | ||
| test_value | ||
| --- no_error_log | ||
| [error] | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 APISIX node need install
etcdctlfirst and run this command, then can enable etcd auth?How about call etcd auth method in Lua land?
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.
Thanks for the pointer @moonming . When I tested this code in my local etcdctl was installed along with etcd. I will check your suggestion
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.
lua-resty-etcddoes not support the manager API now.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.
This issue has been resolved. Tests are passing now