Re: [PR] feat(openidc): support redis for session storage [apisix]
shreemaan-abhishek merged PR #12986: URL: https://github.com/apache/apisix/pull/12986 -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] feat(openidc): support redis for session storage [apisix]
shreemaan-abhishek commented on code in PR #12986: URL: https://github.com/apache/apisix/pull/12986#discussion_r2786966894 ## apisix/plugins/openid-connect.lua: ## Review Comment: yes, the underlying lua-resty-session library is very feature rich and mature. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] feat(openidc): support redis for session storage [apisix]
bzp2010 commented on code in PR #12986: URL: https://github.com/apache/apisix/pull/12986#discussion_r278720 ## apisix/plugins/openid-connect.lua: ## Review Comment: Essentially, this is just defining a new schema to expose features already supported by the library and add documentation? -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] feat(openidc): support redis for session storage [apisix]
shreemaan-abhishek commented on code in PR #12986:
URL: https://github.com/apache/apisix/pull/12986#discussion_r2781177383
##
apisix/plugins/openid-connect.lua:
##
@@ -84,6 +84,58 @@ local schema = {
description = "it holds the cookie lifetime in
seconds in the future",
}
}
+},
+storage = {
+type = "string",
+enum = {"cookie", "redis"},
+default = "cookie",
+},
+redis = {
+type = "object",
+properties = {
+host = {
+type = "string", minLength = 2, default =
"127.0.0.1"
+},
+port = {
+type = "integer", minimum = 1, default = 6379,
+},
+socket = {
+type = "string"
+},
Review Comment:
done
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Re: [PR] feat(openidc): support redis for session storage [apisix]
shreemaan-abhishek commented on code in PR #12986:
URL: https://github.com/apache/apisix/pull/12986#discussion_r2781168405
##
apisix/plugins/openid-connect.lua:
##
@@ -84,6 +84,58 @@ local schema = {
description = "it holds the cookie lifetime in
seconds in the future",
}
}
+},
+storage = {
+type = "string",
+enum = {"cookie", "redis"},
+default = "cookie",
+},
+redis = {
Review Comment:
fixed
##
apisix/plugins/openid-connect.lua:
##
@@ -84,6 +84,58 @@ local schema = {
description = "it holds the cookie lifetime in
seconds in the future",
}
}
+},
+storage = {
+type = "string",
+enum = {"cookie", "redis"},
+default = "cookie",
+},
+redis = {
+type = "object",
+properties = {
+host = {
+type = "string", minLength = 2, default =
"127.0.0.1"
+},
+port = {
+type = "integer", minimum = 1, default = 6379,
+},
+socket = {
+type = "string"
+},
+username = {
+type = "string", minLength = 1,
+},
+password = {
+type = "string", minLength = 0,
+},
+database = {
+type = "integer", minimum = 0, default = 0,
+},
+prefix = {
+type = "string", default = "sessions"
+},
Review Comment:
fixed
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Re: [PR] feat(openidc): support redis for session storage [apisix]
nic-6443 commented on code in PR #12986:
URL: https://github.com/apache/apisix/pull/12986#discussion_r2780805479
##
t/plugin/openid-connect-redis.t:
##
@@ -0,0 +1,382 @@
+#
+# 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.
+#
+
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_long_string();
+no_root_location();
+no_shuffle();
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: check schema with valid redis session configuration
+--- config
+location /t {
+content_by_lua_block {
+local plugin = require("apisix.plugins.openid-connect")
+local ok, err = plugin.check_schema({
+client_id = "a",
+client_secret = "b",
+discovery = "c",
+session = {
+secret = "jwcE5v3pM9VhqLxmxFOH9uZaLo8u7KQK",
+storage = "redis",
+redis = {
+host = "127.0.0.1",
+port = 6379,
+prefix = "mysessions",
+}
+}
+})
+if not ok then
+ngx.say(err)
+else
+ngx.say("done")
+end
+}
+}
+--- request
+GET /t
+--- response_body
+done
+
+
+
+=== TEST 2: check schema with invalid redis session configuration (port string)
+--- config
+location /t {
+content_by_lua_block {
+local plugin = require("apisix.plugins.openid-connect")
+local ok, err = plugin.check_schema({
+client_id = "a",
+client_secret = "b",
+discovery = "c",
+session = {
+secret = "jwcE5v3pM9VhqLxmxFOH9uZaLo8u7KQK",
+storage = "redis",
+redis = {
+port = "invalid",
+}
+}
+})
+if not ok then
+ngx.say(err)
+else
+ngx.say("done")
+end
+}
+}
+--- request
+GET /t
+--- response_body_like
+property "port" validation failed: wrong type: expected integer, got string
+
+
+
+=== TEST 3: verify session sharing across routes with Redis (Simulate Refresh
Scenario)
+--- http_config
+server {
+listen 11980;
+server_name localhost;
+
+location / {
+content_by_lua_block {
+ngx.say("lesgooo!!")
+}
+}
+}
+server {
+listen 16969;
+server_name localhost;
+
+location /.well-known/openid-configuration {
+content_by_lua_block {
+ngx.header.content_type = "application/json"
+ngx.say([[
+{
+"issuer": "http://127.0.0.1:16969";,
+"authorization_endpoint":
"http://127.0.0.1:16969/authorize";,
+"token_endpoint": "http://127.0.0.1:16969/token";,
+"userinfo_endpoint": "http://127.0.0.1:16969/userinfo";,
+"jwks_uri": "http://127.0.0.1:16969/jwks";
+}
+]])
+}
+}
+
+location /token {
+content_by_lua_block {
+local jwt = require("resty.jwt")
+local validators = require("resty.jwt-validators")
+local cjson = require("cjson")
+
+ngx.header.content_type = "application/json"
+ngx.req.read_body()
+local args = ngx.req.get_post_args()
+
+if args.grant_type == "authorization_code" then
+local claim_spec = {
+ sub = "user_123",
+ iss = "http://127.0.0.1:16969";,
+ aud = "test_client",
+ exp = ngx.time() + 60,
+ iat = ngx.time(),
+ name = "Test User"
+}
+
+local jwt_token = jwt:sign(
+ "test_secret",
+ {
+ header = {typ = "JWT", alg = "HS256"},
+ payload = claim_spec
+ }
+
Re: [PR] feat(openidc): support redis for session storage [apisix]
nic-6443 commented on code in PR #12986:
URL: https://github.com/apache/apisix/pull/12986#discussion_r2780804603
##
t/plugin/openid-connect-redis.t:
##
@@ -0,0 +1,382 @@
+#
+# 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.
+#
+
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_long_string();
+no_root_location();
+no_shuffle();
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: check schema with valid redis session configuration
+--- config
+location /t {
+content_by_lua_block {
+local plugin = require("apisix.plugins.openid-connect")
+local ok, err = plugin.check_schema({
+client_id = "a",
+client_secret = "b",
+discovery = "c",
+session = {
+secret = "jwcE5v3pM9VhqLxmxFOH9uZaLo8u7KQK",
+storage = "redis",
+redis = {
+host = "127.0.0.1",
+port = 6379,
+prefix = "mysessions",
+}
+}
+})
+if not ok then
+ngx.say(err)
+else
+ngx.say("done")
+end
+}
+}
+--- request
+GET /t
+--- response_body
+done
+
+
+
+=== TEST 2: check schema with invalid redis session configuration (port string)
+--- config
+location /t {
+content_by_lua_block {
+local plugin = require("apisix.plugins.openid-connect")
+local ok, err = plugin.check_schema({
+client_id = "a",
+client_secret = "b",
+discovery = "c",
+session = {
+secret = "jwcE5v3pM9VhqLxmxFOH9uZaLo8u7KQK",
+storage = "redis",
+redis = {
+port = "invalid",
+}
+}
+})
+if not ok then
+ngx.say(err)
+else
+ngx.say("done")
+end
+}
+}
+--- request
+GET /t
+--- response_body_like
+property "port" validation failed: wrong type: expected integer, got string
+
+
+
+=== TEST 3: verify session sharing across routes with Redis (Simulate Refresh
Scenario)
+--- http_config
+server {
+listen 11980;
+server_name localhost;
+
+location / {
+content_by_lua_block {
+ngx.say("lesgooo!!")
+}
+}
+}
+server {
+listen 16969;
+server_name localhost;
+
+location /.well-known/openid-configuration {
+content_by_lua_block {
+ngx.header.content_type = "application/json"
+ngx.say([[
+{
+"issuer": "http://127.0.0.1:16969";,
+"authorization_endpoint":
"http://127.0.0.1:16969/authorize";,
+"token_endpoint": "http://127.0.0.1:16969/token";,
+"userinfo_endpoint": "http://127.0.0.1:16969/userinfo";,
+"jwks_uri": "http://127.0.0.1:16969/jwks";
+}
+]])
+}
+}
+
+location /token {
+content_by_lua_block {
+local jwt = require("resty.jwt")
+local validators = require("resty.jwt-validators")
+local cjson = require("cjson")
+
+ngx.header.content_type = "application/json"
+ngx.req.read_body()
+local args = ngx.req.get_post_args()
+
+if args.grant_type == "authorization_code" then
+local claim_spec = {
+ sub = "user_123",
+ iss = "http://127.0.0.1:16969";,
+ aud = "test_client",
+ exp = ngx.time() + 60,
+ iat = ngx.time(),
+ name = "Test User"
+}
+
+local jwt_token = jwt:sign(
+ "test_secret",
+ {
+ header = {typ = "JWT", alg = "HS256"},
+ payload = claim_spec
+ }
+
Re: [PR] feat(openidc): support redis for session storage [apisix]
nic-6443 commented on code in PR #12986:
URL: https://github.com/apache/apisix/pull/12986#discussion_r2780803349
##
t/plugin/openid-connect-redis.t:
##
@@ -0,0 +1,382 @@
+#
+# 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.
+#
+
+use t::APISIX 'no_plan';
+
+repeat_each(1);
+no_long_string();
+no_root_location();
+no_shuffle();
+
+run_tests();
+
+__DATA__
+
+=== TEST 1: check schema with valid redis session configuration
+--- config
+location /t {
+content_by_lua_block {
+local plugin = require("apisix.plugins.openid-connect")
+local ok, err = plugin.check_schema({
+client_id = "a",
+client_secret = "b",
+discovery = "c",
+session = {
+secret = "jwcE5v3pM9VhqLxmxFOH9uZaLo8u7KQK",
+storage = "redis",
+redis = {
+host = "127.0.0.1",
+port = 6379,
+prefix = "mysessions",
+}
+}
+})
+if not ok then
+ngx.say(err)
+else
+ngx.say("done")
+end
+}
+}
+--- request
+GET /t
+--- response_body
+done
+
+
+
+=== TEST 2: check schema with invalid redis session configuration (port string)
+--- config
+location /t {
+content_by_lua_block {
+local plugin = require("apisix.plugins.openid-connect")
+local ok, err = plugin.check_schema({
+client_id = "a",
+client_secret = "b",
+discovery = "c",
+session = {
+secret = "jwcE5v3pM9VhqLxmxFOH9uZaLo8u7KQK",
+storage = "redis",
+redis = {
+port = "invalid",
+}
+}
+})
+if not ok then
+ngx.say(err)
+else
+ngx.say("done")
+end
+}
+}
+--- request
+GET /t
+--- response_body_like
+property "port" validation failed: wrong type: expected integer, got string
+
+
+
+=== TEST 3: verify session sharing across routes with Redis (Simulate Refresh
Scenario)
+--- http_config
+server {
+listen 11980;
+server_name localhost;
+
+location / {
+content_by_lua_block {
+ngx.say("lesgooo!!")
+}
+}
+}
+server {
+listen 16969;
+server_name localhost;
+
+location /.well-known/openid-configuration {
+content_by_lua_block {
+ngx.header.content_type = "application/json"
+ngx.say([[
+{
+"issuer": "http://127.0.0.1:16969";,
+"authorization_endpoint":
"http://127.0.0.1:16969/authorize";,
+"token_endpoint": "http://127.0.0.1:16969/token";,
+"userinfo_endpoint": "http://127.0.0.1:16969/userinfo";,
+"jwks_uri": "http://127.0.0.1:16969/jwks";
+}
+]])
+}
+}
+
+location /token {
+content_by_lua_block {
+local jwt = require("resty.jwt")
+local validators = require("resty.jwt-validators")
+local cjson = require("cjson")
+
+ngx.header.content_type = "application/json"
+ngx.req.read_body()
+local args = ngx.req.get_post_args()
+
+if args.grant_type == "authorization_code" then
+local claim_spec = {
+ sub = "user_123",
+ iss = "http://127.0.0.1:16969";,
+ aud = "test_client",
+ exp = ngx.time() + 60,
+ iat = ngx.time(),
+ name = "Test User"
+}
+
+local jwt_token = jwt:sign(
+ "test_secret",
+ {
+ header = {typ = "JWT", alg = "HS256"},
+ payload = claim_spec
+ }
+
Re: [PR] feat(openidc): support redis for session storage [apisix]
nic-6443 commented on code in PR #12986: URL: https://github.com/apache/apisix/pull/12986#discussion_r2780800197 ## docs/en/latest/plugins/openid-connect.md: ## @@ -67,6 +67,17 @@ The `openid-connect` Plugin supports the integration with [OpenID Connect (OIDC) | session.secret | string | True | | 16 or more characters | Key used for session encryption and HMAC operation when `bearer_only` is `false`. | | session.cookie | object | False| | | Cookie configurations.| | session.cookie.lifetime | integer | False| 3600 | | Cookie lifetime in seconds. | +| session.storage| string | False| cookie | ["cookie", "redis"] | Session storage method. | +| session.redis| object | False| | | Redis configuration when `storage` is `redis`.| +| session.redis.host | string | False| 127.0.0.1 | | Redis host.| +| session.redis.port | integer | False| 6379 | | Redis port.| +| session.redis.password | string | False| | | Redis password.| +| session.redis.username | string | False| | | Redis username.| +| session.redis.database | integer | False| 0 | | Redis database index.| +| session.redis.prefix | string | False| sessions | | Redis key prefix.| +| session.redis.ssl| boolean | False| false | | Enable SSL for Redis connection.| +| session.redis.server_name | string | False| | | Redis server name for SNI.| +| session.redis.auth | string | False| | | Alias for `session.redis.password`.| Review Comment: Some fields are missing in the document, such as `*_timeout` -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
Re: [PR] feat(openidc): support redis for session storage [apisix]
nic-6443 commented on code in PR #12986:
URL: https://github.com/apache/apisix/pull/12986#discussion_r2780798693
##
apisix/plugins/openid-connect.lua:
##
@@ -84,6 +84,58 @@ local schema = {
description = "it holds the cookie lifetime in
seconds in the future",
}
}
+},
+storage = {
+type = "string",
+enum = {"cookie", "redis"},
+default = "cookie",
+},
+redis = {
+type = "object",
+properties = {
+host = {
+type = "string", minLength = 2, default =
"127.0.0.1"
+},
+port = {
+type = "integer", minimum = 1, default = 6379,
+},
+socket = {
+type = "string"
+},
+username = {
+type = "string", minLength = 1,
+},
+password = {
+type = "string", minLength = 0,
+},
+database = {
+type = "integer", minimum = 0, default = 0,
+},
+prefix = {
+type = "string", default = "sessions"
+},
Review Comment:
Some fields need to have a `description` field; otherwise, their meanings
are hard to understand.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Re: [PR] feat(openidc): support redis for session storage [apisix]
nic-6443 commented on code in PR #12986:
URL: https://github.com/apache/apisix/pull/12986#discussion_r2780796096
##
apisix/plugins/openid-connect.lua:
##
@@ -84,6 +84,58 @@ local schema = {
description = "it holds the cookie lifetime in
seconds in the future",
}
}
+},
+storage = {
+type = "string",
+enum = {"cookie", "redis"},
+default = "cookie",
+},
+redis = {
Review Comment:
It is necessary to add a dependency relationship between the `storage` and
`redis` fields.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
Re: [PR] feat(openidc): support redis for session storage [apisix]
nic-6443 commented on code in PR #12986:
URL: https://github.com/apache/apisix/pull/12986#discussion_r2780792182
##
apisix/plugins/openid-connect.lua:
##
@@ -84,6 +84,58 @@ local schema = {
description = "it holds the cookie lifetime in
seconds in the future",
}
}
+},
+storage = {
+type = "string",
+enum = {"cookie", "redis"},
+default = "cookie",
+},
+redis = {
+type = "object",
+properties = {
+host = {
+type = "string", minLength = 2, default =
"127.0.0.1"
+},
+port = {
+type = "integer", minimum = 1, default = 6379,
+},
+socket = {
+type = "string"
+},
Review Comment:
Does this configuration mean connecting to redis via a linux domain socket?
If so, I think it can be removed because it won't be used in actual situations.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
[PR] feat(openidc): support redis for session storage [apisix]
shreemaan-abhishek opened a new pull request, #12986: URL: https://github.com/apache/apisix/pull/12986 ### Description Fixes #12495 ### 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) -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
