-
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: allow to use environment variables for openid-connect plugin #11451
base: master
Are you sure you want to change the base?
feat: allow to use environment variables for openid-connect plugin #11451
Conversation
hi good morning @shreemaan-abhishek clould you kindly review this PR for me ? |
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.
please write a test case that uses vault as well.
apisix/plugins/openid-connect.lua
Outdated
@@ -290,7 +291,8 @@ local _M = { | |||
} | |||
|
|||
|
|||
function _M.check_schema(conf) | |||
function _M.check_schema(plugin_conf) | |||
local conf = fetch_secrets(plugin_conf) |
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 is not needed.
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 is not needed.↳
This is needed when someone puts a non-string value such as a Boolean into env var, otherwise the type inconsistency will fail the check
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 line is giving me some issues after apisix reload.
If line fetch_secrets is done in check_schema, the route fails showing me the following error:
2024/11/12 17:12:51 [error] 240#240: *13728 lua entry thread aborted: runtime error: ...isix/custom-plugins/apisix/plugins/openid-connect.lua:478: attempt to compare nil with number
stack traceback:
coroutine 0:
...isix/custom-plugins/apisix/plugins/openid-connect.lua: in function 'phase_func'
/usr/local/apisix/apisix/plugin.lua:1166: in function 'run_plugin'
/usr/local/apisix/apisix/init.lua:689: in function 'http_access_phase'
access_by_lua(nginx.conf:310):2: in main chunk, client: 10.89.2.37, server: _, request: "GET /private/anything HTTP/2.0", host: "XXXX"
If I remove fetch_secrets from check_schema, the route work as expected but the following warning is shown at startup:
[warn] 187#187: *8391 [lua] utils.lua:418: find_and_log(): Using openid-connect discovery with no TLS is a security risk, context: init_worker_by_lua*
I assume that without the fetch_secrets the value of discovery
is not resolved and openid checks https for it.
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.
So should we remove fetch_secrets from check_schema to avoid this?
By contrast, putting a Boolean value in a secret is not a particularly common case in this plugin. Typically, only string urls and secret keys will be placed in valut
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.
pushed this change
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.
please write a test case that uses vault as well.
t/fips/openid-connect.t
Outdated
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.
please add new test cases in t/plugin/openid-connect
Co-authored-by: Shreemaan Abhishek <shreemaan.abhishek@gmail.com>
|
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 test cases for secret resource seems correct to me, please resolve the conflicts with master so that the tests can run
Great contribution!! I'm looking forward to this fix, as we are using AWS Secrets Manager as a secrets provider and we need to configure the secret as an environment variable. I hope this fix is merged and released soon 🙏 |
# Conflicts: # t/fips/openid-connect.t
hi @shreemaan-abhishek |
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 is exactly what I was looking for. I've tested this config on my local environment, and it works as expected.
client_id: "$env://APISIX_OIDC_CLIENT_ID"
client_secret: "$env://APISIX_OIDC_CLIENT_SECRET"
discovery: $env://APISIX_OIDC_DISCOVERY_URL
I hope this will be merged soon
Are there any updates on this? At the moment we have to keep a secret in our repo because of the bug that it is fixing this PR, and we need to move it to environment variables. So it would be awesome if we could have this fixed in a patch soon |
We need another good Samaritan to approve this change, then this PR will have three approve and be merged |
Could any of you help approve this PR at your convenience? It has been pending here for a long time and only needs the last approver |
hi @kayx23 @membphis @Revolyssup Could any of you help? |
I have left a comment: https://github.com/apache/apisix/pull/11451/files#r1896868940 |
clone conf before fetch_secrets to adopt issue apache#1956 Co-authored-by: Shreemaan Abhishek <shreemaan.abhishek@gmail.com>
clone conf before fetch_secrets to adopt issue apache#1956
i think |
@@ -471,7 +472,8 @@ local function required_scopes_present(required_scopes, http_scopes) | |||
end | |||
|
|||
function _M.rewrite(plugin_conf, ctx) | |||
local conf = core.table.clone(plugin_conf) | |||
local conf_clone = core.table.clone(plugin_conf) |
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.
performance tips:
we can use a lrucache, avoid repeated rendering of plugin_conf configuration
Thank you, but I don't fully understand your suggestion
The original way, I just used fetch_secret
without clone the config first , but with this suggestion, I add table.clone
before fetch_secret
I think fetch_secret
itself 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 lrucache
In addition, I noticed that two tests failed, but I don't know how to fix them. Is there anyone who is kind enough to help 😢 |
1th tip=====bad style=====
2th tipyou can merge the latest master branch |
merged latest master branch for 1th tip, cloud you kindly help to run reindex for me ? |
Description
feat: allow to use environment variables for openid-connect plugin
Checklist