-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: allow to use environment variables for openid-connect plugin #11451
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
Baoyuantop
merged 31 commits into
apache:master
from
darkSheep404:feat-openid-connect-support-env
Aug 25, 2025
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
68d705c
feat: allow to use environment variables for openid-connect
2e7df95
feat: allow to use environment variables for openid-connect
5ab3f3e
feat: allow to use environment variables for openid-connect
dfd3005
feat: allow to use environment variables for openid-connect plugin
darkSheep404 cc39db4
feat: allow to use environment variables for openid-connect
980df99
feat: allow to use environment variables for openid-connect
a4b9e06
Merge branch 'master' into feat-openid-connect-support-env
3fe0e00
feat: allow to use environment variables for openid-connect
6c7a0b9
feat: allow to use environment variables for openid-connect
1f75535
Update apisix/plugins/openid-connect.lua
darkSheep404 0303851
Update openid-connect.lua
darkSheep404 db6bc80
Merge branch 'apache:master' into feat-openid-connect-support-env
darkSheep404 ea49a27
Merge branch 'apache:master' into feat-openid-connect-support-env
darkSheep404 9f88583
Merge remote-tracking branch 'origin/master' into feat-openid-connect…
d9e71c7
feat: allow to use environment variables for openid-connect#try to fi…
dd60660
feat: allow to use environment variables for openid-connect#try to fi…
179ec78
Merge branch 'apache:master' into feat-openid-connect-support-env
darkSheep404 0193368
Merge branch 'apache:master' into feat-openid-connect-support-env
darkSheep404 5f600a5
Merge branch 'apache:master' into feat-openid-connect-support-env
darkSheep404 9c84185
feat: allow to use environment variables for openid-connect#add reque…
7116d09
Merge remote-tracking branch 'origin/feat-openid-connect-support-env'…
505cc27
feat: allow to use environment variables for openid-connect#add Chine…
74ad5f1
feat: allow to use environment variables for openid-connect#fix lint
9fdbbd4
Merge branch 'master' into feat-openid-connect-support-env
darkSheep404 631cc1d
feat: allow to use environment variables for openid-connect#fix lint
207617f
Merge remote-tracking branch 'origin/feat-openid-connect-support-env'…
d5aabfd
feat: allow to use environment variables for openid-connect#fix lint
a840fdd
feat: allow to use environment variables for openid-connect#fix lint
e68e0cc
Update apisix/plugins/openid-connect.lua
darkSheep404 ec2974a
Merge branch 'apache:master' into feat-openid-connect-support-env
darkSheep404 463c47a
feat: clone openid-connect conf before fetch_secrets
darkSheep404 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
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,192 @@ | ||
| # | ||
| # 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'; | ||
|
|
||
| log_level('debug'); | ||
| repeat_each(1); | ||
| no_long_string(); | ||
| no_root_location(); | ||
| no_shuffle(); | ||
|
|
||
| add_block_preprocessor(sub { | ||
| my ($block) = @_; | ||
|
|
||
| if ((!defined $block->error_log) && (!defined $block->no_error_log)) { | ||
| $block->set_value("no_error_log", "[error]"); | ||
| } | ||
|
|
||
| if (!defined $block->request) { | ||
| $block->set_value("request", "GET /t"); | ||
| } | ||
| }); | ||
|
|
||
| BEGIN { | ||
| $ENV{CLIENT_SECRET_ENV} = "60Op4HFM0I8ajz0WdiStAbziZ-VFQttXuxixHHs2R7r7-CW8GR79l-mmLqMhc-Sa"; | ||
| $ENV{VAULT_TOKEN} = "root"; | ||
| } | ||
|
|
||
| run_tests(); | ||
|
|
||
| __DATA__ | ||
|
|
||
| === TEST 1: configure oidc plugin with small public key using environment variable | ||
| --- config | ||
| location /t { | ||
| content_by_lua_block { | ||
| local t = require("lib.test_admin").test | ||
| local code, body = t('/apisix/admin/routes/1', | ||
| ngx.HTTP_PUT, | ||
| [[{ "plugins": { | ||
| "openid-connect": { | ||
| "client_id": "kbyuFDidLLm280LIwVFiazOqjO3ty8KH", | ||
| "client_secret": "$ENV://CLIENT_SECRET_ENV", | ||
| "discovery": "https://samples.auth0.com/.well-known/openid-configuration", | ||
| "redirect_uri": "https://iresty.com", | ||
| "ssl_verify": false, | ||
| "timeout": 10, | ||
| "bearer_only": true, | ||
| "scope": "apisix", | ||
| "public_key": "-----BEGIN PUBLIC KEY-----\n]] .. | ||
| [[MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANW16kX5SMrMa2t7F2R1w6Bk/qpjS4QQ\n]] .. | ||
| [[hnrbED3Dpsl9JXAx90MYsIWp51hBxJSE/EPVK8WF/sjHK1xQbEuDfEECAwEAAQ==\n]] .. | ||
| [[-----END PUBLIC KEY-----", | ||
| "token_signing_alg_values_expected": "RS256" | ||
| } | ||
| }, | ||
| "upstream": { | ||
| "nodes": { | ||
| "127.0.0.1:1980": 1 | ||
| }, | ||
| "type": "roundrobin" | ||
| }, | ||
| "uri": "/hello" | ||
| }]] | ||
| ) | ||
|
|
||
| if code >= 300 then | ||
| ngx.status = code | ||
| end | ||
| ngx.say(body) | ||
| } | ||
| } | ||
| --- response_body | ||
| passed | ||
|
|
||
|
|
||
|
|
||
| === TEST 2: store secret into vault | ||
| --- exec | ||
| VAULT_TOKEN='root' VAULT_ADDR='http://0.0.0.0:8200' vault kv put kv/apisix/foo client_secret=60Op4HFM0I8ajz0WdiStAbziZ-VFQttXuxixHHs2R7r7-CW8GR79l-mmLqMhc-Sa | ||
| --- response_body | ||
| Success! Data written to: kv/apisix/foo | ||
|
|
||
|
|
||
|
|
||
| === TEST 3: configure oidc plugin with small public key using vault | ||
| --- config | ||
| location /t { | ||
| content_by_lua_block { | ||
| local t = require("lib.test_admin").test | ||
| local code, body = t('/apisix/admin/routes/1', | ||
| ngx.HTTP_PUT, | ||
| [[{ "plugins": { | ||
| "openid-connect": { | ||
| "client_id": "kbyuFDidLLm280LIwVFiazOqjO3ty8KH", | ||
| "client_secret": "$secret://vault/test1/foo/client_secret", | ||
| "discovery": "https://samples.auth0.com/.well-known/openid-configuration", | ||
| "redirect_uri": "https://iresty.com", | ||
| "ssl_verify": false, | ||
| "timeout": 10, | ||
| "bearer_only": true, | ||
| "scope": "apisix", | ||
| "public_key": "-----BEGIN PUBLIC KEY-----\n]] .. | ||
| [[MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANW16kX5SMrMa2t7F2R1w6Bk/qpjS4QQ\n]] .. | ||
| [[hnrbED3Dpsl9JXAx90MYsIWp51hBxJSE/EPVK8WF/sjHK1xQbEuDfEECAwEAAQ==\n]] .. | ||
| [[-----END PUBLIC KEY-----", | ||
| "token_signing_alg_values_expected": "RS256" | ||
| } | ||
| }, | ||
| "upstream": { | ||
| "nodes": { | ||
| "127.0.0.1:1980": 1 | ||
| }, | ||
| "type": "roundrobin" | ||
| }, | ||
| "uri": "/hello" | ||
| }]] | ||
| ) | ||
|
|
||
| if code >= 300 then | ||
| ngx.status = code | ||
| end | ||
| ngx.say(body) | ||
| } | ||
| } | ||
| --- response_body | ||
| passed | ||
Baoyuantop marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
|
|
||
| === TEST 4: configure oidc plugin with small public key using vault and request with token should success | ||
| --- config | ||
| location /hello { | ||
| content_by_lua_block { | ||
| ngx.say("success") | ||
| } | ||
| } | ||
|
|
||
| location /t { | ||
| content_by_lua_block { | ||
| local t = require("lib.test_admin").test | ||
| local code, body = t('/apisix/admin/routes/1', | ||
| ngx.HTTP_PUT, | ||
| [[{ | ||
| "plugins": { | ||
| "openid-connect": { | ||
| "client_id": "kbyuFDidLLm280LIwVFiazOqjO3ty8KH", | ||
| "client_secret": "$secret://vault/test1/foo/client_secret", | ||
| "discovery": "https://samples.auth0.com/.well-known/openid-configuration", | ||
| "redirect_uri": "https://iresty.com", | ||
| "ssl_verify": false, | ||
| "timeout": 10, | ||
| "bearer_only": true, | ||
| "scope": "apisix", | ||
| "public_key": "-----BEGIN PUBLIC KEY-----\n]] .. | ||
| [[MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBANW16kX5SMrMa2t7F2R1w6Bk/qpjS4QQ\n]] .. | ||
| [[hnrbED3Dpsl9JXAx90MYsIWp51hBxJSE/EPVK8WF/sjHK1xQbEuDfEECAwEAAQ==\n]] .. | ||
| [[-----END PUBLIC KEY-----", | ||
| "token_signing_alg_values_expected": "RS256" | ||
| } | ||
| }, | ||
| "upstream": { | ||
| "nodes": { | ||
| "127.0.0.1:1980": 1 | ||
| }, | ||
| "type": "roundrobin" | ||
| }, | ||
| "uri": "/hello" | ||
| }]] | ||
| ) | ||
| ngx.status = code | ||
| ngx.say(body) | ||
| } | ||
| } | ||
| --- request | ||
| GET /hello HTTP/1.1 | ||
| Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJodHRwczovL3NhbXBsZXMuYXV0aDAuY29tLyIsInN1YiI6InRlc3Qtc3ViamVjdCIsImF1ZCI6ImtieXVG RGlkTExtMjgwTEl3VkZpYXpPcWpPM3R5OEtIIiwic2NvcGUiOiJhcGlzaXgiLCJpYXQiOjEwMDAwMDAwLCJleHAiOjI1MDAwMDAwMDB9.bfcZsd4ABgo0GoLT8EwfnKgf AWbnJZbZ3kOtqyeSkXYqGlSmgMNW3q5Kx1SGjMNhEKVG_KrFfsPrQmcTljSPZA | ||
| --- response_body | ||
| success | ||
Oops, something went wrong.
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.
performance tips:
we can use a lrucache, avoid repeated rendering of plugin_conf configuration
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.
Thank you, but I don't fully understand your suggestion
The original way, I just used
fetch_secretwithout clone the config first , but with this suggestion, I addtable.clonebeforefetch_secretI think
fetch_secretitself will return a clone of conf, and if you want to optimize it, maybe can just keep using fetch_secret directly, instead of add another extra lrucacheThere 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.
apisix/apisix/plugins/basic-auth.lua
Line 116 in 0cb7d9a
here is an example in basic-auth plugin, it can help you