Skip to content
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(cmd): lack of necessary nginx directives in kong cli nginx.conf #11127

Merged
merged 49 commits into from
Jul 24, 2023

Conversation

catbro666
Copy link
Contributor

@catbro666 catbro666 commented Jun 27, 2023

Summary

This is an alternative of #10675. The primary logic keeps the same, but the inject logic is further moved forward from kong/cmd/init.lua to bin/kong so that the execution flow won't enter kong/cmd/init.lua twice.

We still keep the bin/kong a resty script because many files such as kong.conf_loader, kong.cmd.utils.process_secrets rely on ngx. If we change bin/kong into a pure lua or other language script, we need to rewrite the conf_loader and compile part logic.

FTI-4937

Checklist

  • The Pull Request has tests
  • There's an entry in the CHANGELOG

@catbro666 catbro666 changed the base branch from FTI-4937-kong-cli-vault-caveats to master June 27, 2023 08:25
@catbro666 catbro666 added this to the 3.4.0 milestone Jun 27, 2023
bungle
bungle previously requested changes Jun 27, 2023
spec/01-unit/03-conf_loader_spec.lua Outdated Show resolved Hide resolved
@catbro666 catbro666 force-pushed the bin-kong-to-lua-script branch 2 times, most recently from 89b530f to 16526fb Compare June 29, 2023 03:35
@github-actions github-actions bot added core/db and removed core/db labels Jun 29, 2023
@catbro666 catbro666 force-pushed the bin-kong-to-lua-script branch 2 times, most recently from 0f74d8c to 533c329 Compare July 5, 2023 08:22
@github-actions github-actions bot removed the core/db label Jul 5, 2023
@catbro666
Copy link
Contributor Author

detach the "drop luasocket in cli" part to a separate PR so that this PR is easier to review. Also because these two PRs are relatively logically independent.

bin/kong Show resolved Hide resolved
@kikito
Copy link
Member

kikito commented Jul 11, 2023

Is this needed for 3.4 (it's in the milestone)?

@catbro666
Copy link
Contributor Author

catbro666 commented Jul 12, 2023

Is this needed for 3.4 (it's in the milestone)?

@kikito Yes, I think so. it was moved from 3.3 to 3.4 because of pursuing a more generic approach.

We, @kikito, @jschmid1, and @bungle, decided to move this to 3.4. This is a rather generic problem, and we would like to pursue different approaches before committing to this. Approaches that might work in more generic fashion are:

catbro666 and others added 2 commits July 24, 2023 15:39
Co-authored-by: Qirui(Keery) Nie <[email protected]>
the lua_ssl_trusted_certificate config may be updated
@windmgc windmgc dismissed bungle’s stale review July 24, 2023 09:49

Already addressed

@windmgc windmgc merged commit 8a1ebba into master Jul 24, 2023
@windmgc windmgc deleted the bin-kong-to-lua-script branch July 24, 2023 09:51
team-gateway-bot pushed a commit that referenced this pull request Jul 24, 2023
* fix(cmd): `kong vault get` doesn't work in dbless mode

The cli `kong vault get <reference>` doesn't work in DBless mode
if <reference> uses vaults entity. It doesn't affect the normal use of
vault in kong instance though.

The reason is in DBless mode the vaults entity is stored in LMDB
which is implemented by a Nginx C module. However Everytime `resty` cli
(which is relied on by `kong` cli) runs it creates a temporary `nginx.conf`
which doesn't contain the lmdb-related directives.

This PR is fixing this by starting another `resty` call with lmdb-related
directives inserted via the `--main-conf` option.

Note we only try this after detecting the `no LMDB environment defined`
error in order to avoid infinite loop. And because `resty` will create a
temmporary nginx instance so we need to convert the relative paths in
the nginx.conf to the absolute path under kong instance prefix.

[FTI-4937](https://konghq.atlassian.net/browse/FTI-4937)

* add CHANGELOG

* make it more robust

* update comment

* update comment

* test the existence of LMDB rather than Kong instance

* fixup

* make the fix more generic

* fix and add tests in 04-prefix_handler_spec

* add lua_ssl_protocols and fix tests

* rename the new configuration files to avoid conflict with the prefix of injected directives

* add and fix tests of 14-vault_spec

* fix test

* rename template files to consistent with configuration file names

* add unit tests for inject_directives.lua

* change to absolute path

* fixup

* fix path

* Update CHANGELOG.md

Co-authored-by: Hans Hübner <[email protected]>

* use return (...) syntax instead

* don't expose the option and use a better name

* pass paths instead of patterns and use better names

* correctly handle the stdout/stderr/exit code

* preserve original cli args for reusing

* use env variable to terminate recursion

* resty isn't necessarily in the position -1, so add it explicitly

* update the lmdb_map_size to 2048m

* fix(cmd): lack of necessary nginx directives in kong cli nginx.conf

This is an alternative of (#10675)[#10675].
The primary logic keeps the same. The inject logic is further moved forward
from `kong/cmd/init.lua` to `bin/kong` so that the execution flow won't enter
`kong/cmd/init.lua` twice.

We still keep the `bin/kong` a resty script because many files such as
`kong.conf_loader`, `kong.cmd.utils.process_secrets` rely on `ngx`. If we change
`bin/kong` into a pure lua or other language script, we need to rewrite
the conf_loader and compile part logic.

[FTI-4937](https://konghq.atlassian.net/browse/FTI-4937)

* fix lint

* fix test

* fix test

* use xpcall to catch exceptions and handle error message

* add health to skip_inject_cmds

* fix tests in 11-config_spec.lua

* add hybrid into skip_inject_cmds

* fix typo

* remove CHANGELOG entry to the right place ("Unreleased")

* extend load() to a subset of fields and these fields can't reference vault

* add field `database` to CONF_NO_VAULT

* fix test

* fix test

* keep `conf.nginx_http_lua_ssl_protocols` and
`conf.nginx_stream_lua_ssl_protocols` so that we don't change the previous
behavior

* fixup

* fix test

* fix test

* fix test

* update CHANGELOG

* Update CHANGELOG.md

Co-authored-by: Qirui(Keery) Nie <[email protected]>

* always call prepare_prefix as the prefix directory may not existed and
the lua_ssl_trusted_certificate config may be updated

---------

Co-authored-by: Hans Hübner <[email protected]>
Co-authored-by: Qirui(Keery) Nie <[email protected]>
(cherry picked from commit 8a1ebba)
catbro666 added a commit that referenced this pull request Jul 25, 2023
This is the follow-up PR of #11127

Changing the socket type from luasocket to openresty cosocket causes some test fail weirdly. After investigating, it's mainly because the cosocket support yield and setkeepalive. See the comments in tests.

https://konghq.atlassian.net/browse/FTI-4937
windmgc pushed a commit that referenced this pull request Jul 25, 2023
* fix(cmd): `kong vault get` doesn't work in dbless mode

The cli `kong vault get <reference>` doesn't work in DBless mode
if <reference> uses vaults entity. It doesn't affect the normal use of
vault in kong instance though.

The reason is in DBless mode the vaults entity is stored in LMDB
which is implemented by a Nginx C module. However Everytime `resty` cli
(which is relied on by `kong` cli) runs it creates a temporary `nginx.conf`
which doesn't contain the lmdb-related directives.

This PR is fixing this by starting another `resty` call with lmdb-related
directives inserted via the `--main-conf` option.

Note we only try this after detecting the `no LMDB environment defined`
error in order to avoid infinite loop. And because `resty` will create a
temmporary nginx instance so we need to convert the relative paths in
the nginx.conf to the absolute path under kong instance prefix.

[FTI-4937](https://konghq.atlassian.net/browse/FTI-4937)

* add CHANGELOG

* make it more robust

* update comment

* update comment

* test the existence of LMDB rather than Kong instance

* fixup

* make the fix more generic

* fix and add tests in 04-prefix_handler_spec

* add lua_ssl_protocols and fix tests

* rename the new configuration files to avoid conflict with the prefix of injected directives

* add and fix tests of 14-vault_spec

* fix test

* rename template files to consistent with configuration file names

* add unit tests for inject_directives.lua

* change to absolute path

* fixup

* fix path

* Update CHANGELOG.md

Co-authored-by: Hans Hübner <[email protected]>

* use return (...) syntax instead

* don't expose the option and use a better name

* pass paths instead of patterns and use better names

* correctly handle the stdout/stderr/exit code

* preserve original cli args for reusing

* use env variable to terminate recursion

* resty isn't necessarily in the position -1, so add it explicitly

* update the lmdb_map_size to 2048m

* fix(cmd): lack of necessary nginx directives in kong cli nginx.conf

This is an alternative of (#10675)[#10675].
The primary logic keeps the same. The inject logic is further moved forward
from `kong/cmd/init.lua` to `bin/kong` so that the execution flow won't enter
`kong/cmd/init.lua` twice.

We still keep the `bin/kong` a resty script because many files such as
`kong.conf_loader`, `kong.cmd.utils.process_secrets` rely on `ngx`. If we change
`bin/kong` into a pure lua or other language script, we need to rewrite
the conf_loader and compile part logic.

[FTI-4937](https://konghq.atlassian.net/browse/FTI-4937)

* fix lint

* fix test

* fix test

* use xpcall to catch exceptions and handle error message

* add health to skip_inject_cmds

* fix tests in 11-config_spec.lua

* add hybrid into skip_inject_cmds

* fix typo

* remove CHANGELOG entry to the right place ("Unreleased")

* extend load() to a subset of fields and these fields can't reference vault

* add field `database` to CONF_NO_VAULT

* fix test

* fix test

* keep `conf.nginx_http_lua_ssl_protocols` and
`conf.nginx_stream_lua_ssl_protocols` so that we don't change the previous
behavior

* fixup

* fix test

* fix test

* fix test

* update CHANGELOG

* Update CHANGELOG.md

Co-authored-by: Qirui(Keery) Nie <[email protected]>

* always call prepare_prefix as the prefix directory may not existed and
the lua_ssl_trusted_certificate config may be updated

---------

Co-authored-by: Hans Hübner <[email protected]>
Co-authored-by: Qirui(Keery) Nie <[email protected]>
(cherry picked from commit 8a1ebba)
windmgc pushed a commit that referenced this pull request Jul 26, 2023
…#11291)

This commit allows some configuration fields to be referenced by using vaults. The limitation is introduced by #11127, and this commit removes the limitation to keep the behaviour to be the same as before

[FTI-4937](https://konghq.atlassian.net/browse/FTI-4937)
team-gateway-bot pushed a commit that referenced this pull request Jul 26, 2023
…#11291)

This commit allows some configuration fields to be referenced by using vaults. The limitation is introduced by #11127, and this commit removes the limitation to keep the behaviour to be the same as before

[FTI-4937](https://konghq.atlassian.net/browse/FTI-4937)

(cherry picked from commit 522f554)
windmgc pushed a commit that referenced this pull request Jul 26, 2023
…#11291)

This commit allows some configuration fields to be referenced by using vaults. The limitation is introduced by #11127, and this commit removes the limitation to keep the behaviour to be the same as before

[FTI-4937](https://konghq.atlassian.net/browse/FTI-4937)

(cherry picked from commit 522f554)
catbro666 added a commit that referenced this pull request Aug 8, 2023
This is the follow-up PR of #11127

Changing the socket type from luasocket to openresty cosocket causes some test fail weirdly. After investigating, it's mainly because the cosocket support yield and setkeepalive. See the comments in tests.

https://konghq.atlassian.net/browse/FTI-4937
@kikito kikito mentioned this pull request Aug 9, 2023
fffonion pushed a commit that referenced this pull request Aug 11, 2023
This is the follow-up PR of #11127

Changing the socket type from luasocket to openresty cosocket causes some test fail weirdly. After investigating, it's mainly because the cosocket support yield and setkeepalive. See the comments in tests.

FTI-4937
@team-gateway-bot
Copy link
Collaborator

The backport to release/3.3.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-release/3.3.x release/3.3.x
# Navigate to the new working tree
cd .worktrees/backport-release/3.3.x
# Create a new branch
git switch --create backport-11127-to-release/3.3.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 8a1ebba055d28f940cc19774cf5edf35f71dd149
# Push it to GitHub
git push --set-upstream origin backport-11127-to-release/3.3.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-release/3.3.x

Then, create a pull request where the base branch is release/3.3.x and the compare/head branch is backport-11127-to-release/3.3.x.

@kikito
Copy link
Member

kikito commented Sep 25, 2023

Backporting this to 3.3 since it seems this is needed in #11210 (failing test complains about missing inject_confs file)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants