-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
fix(*): expose Bazel INSTALL_DESTDIR to Lua code and fix admin_gui in dev [KM-117] #12774
base: master
Are you sure you want to change the base?
Conversation
kong/cmd/utils/prefix_handler.lua
Outdated
@@ -828,7 +828,8 @@ local function prepare_prefix(kong_config, nginx_custom_template_path, skip_writ | |||
end | |||
|
|||
if kong_config.admin_gui_listeners then | |||
prepare_prefixed_interface_dir("/usr/local/kong", "gui", kong_config) | |||
-- use LIBRARY_PREFIX as an alternative to /usr/local/kong in the Bazel dev environment | |||
prepare_prefixed_interface_dir(os.getenv("LIBRARY_PREFIX") or "/usr/local/kong", "gui", kong_config) |
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.
I'm slightly worried about the use of LIBRARY_PREFIX
here as it's currently only used by dev scripts but now it could has effect in production as well. Some idea to improve it:
- Prefix it with
KONG_
to avoid surprises. We will then need to set the new env var in our dev script too. - Use a hardcoded path when a env var indicating we are in dev env, instead using directly from the value of LIBRARY_PREFIX. This could help us prevent path traversal even if malicious user injected this env var in production.
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.
@fffonion I agree with you. I'm converting this PR into a draft and will refactor it. Meanwhile, do we have best practices (e.g., env vars, helpers) to tell if we are in the dev env?
Update: It appears that we cannot hardcode the venv path as it is subject to user overrides on BUILD_NAME
.
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.
We can use BUILD_NAME
and use that to construct path. Or it just occurs to me that we can also produce a lua file to populate the prefix, and require that from the file that you change in this PR. So you don't need to rely on the
fact that BUILD_NAME
or some other vars are populated, which is done by the venv scripts/may not work in other tooling.
It can be a simple genrule that produce a lua file, something like
genrule(
name = "kong_path_config",
outs = ["path/to/the/kong_path_config.lua"],
cmd = "echo 'return \"%s/kong\"' >$@" % KONG_VAR["INSTALL_DESTDIR"],
)
then in lua we can just
local the_path = require "path.to.the.kong_path_config"
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.
Or to take a completely different path, that to start using of datafile
to ship admin_gui assets, like the saml
plugin did for xml
assets would also be a good idea.
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 suggestion. I've appended the echo
command to the kong
target which would be more straightforward.
29fb13a
to
adee7e0
Compare
adee7e0
to
92dec88
Compare
f9fc2cf
to
beca877
Compare
beca877
to
fcb3888
Compare
Summary
Exposing
INSTALL_DESTDIR
in Bazel build via an auto-generated Lua modulekong.kong_usr_path
.This fixes an issue where Admin GUI is not correctly prepared for the configured prefix while developing with Bazel's vdev environment.
Checklist
changelog/unreleased/kong
orskip-changelog
label added on PR if changelog is unnecessary. README.mdKM-117