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(vault): support array type config reference and multiple nginx subsystem #13855

Merged
merged 8 commits into from
Nov 29, 2024

Conversation

windmgc
Copy link
Member

@windmgc windmgc commented Nov 11, 2024

Summary

This is a superset of #12672

The PR includes the following fix for vault:

  • Fix the issue that array-type configuration's element cannot be referenced. conf_loader now supports iterate through array-like configuration field and deref the secrets one by one.
  • Enable the vault to dereference secrets using partial SSL configurations, for example, lua_ssl_trusted_certificate=system, {vault://abc/def}. This is implemented especially for resty environments that execute the actual kong command, with the opts pre_cmd = true. Vault related functionalities can work normally by using valid partial configuration generated in the pre_cmd environment. This change does not have a separate changelog entry because it is part of the previous "array-type config vault ref" fix and is more inline with user's intuition.
  • Fix the issue that vault reference cannot work well when multiple subsystems(http/stream) are enabled. The kong_processed_secrets environment variable/file are now generated by subsystems, so enabling multiple subsystem will generates multiple env var/secret file for storing vault deref result.

Checklist

  • The Pull Request has tests
  • A changelog file has been created under changelog/unreleased/kong or skip-changelog label added on PR if changelog is unnecessary. README.md
  • There is a user-facing docs PR against https://github.com/Kong/docs.konghq.com - PUT DOCS PR HERE

Issue reference

FTI-6163

@github-actions github-actions bot added core/cli core/pdk core/configuration cherry-pick kong-ee schedule this PR for cherry-picking to kong/kong-ee labels Nov 11, 2024
@windmgc windmgc marked this pull request as ready for review November 11, 2024 09:42
@windmgc windmgc force-pushed the fix/ssl-cert-vault-more-to-be-fixed branch from 4f5e62a to d81f0dc Compare November 18, 2024 05:48
@windmgc windmgc requested a review from bungle November 18, 2024 05:50
@windmgc windmgc force-pushed the fix/ssl-cert-vault-more-to-be-fixed branch from d81f0dc to 139bf1d Compare November 19, 2024 11:59
@windmgc windmgc added this to the 3.9.0 milestone Nov 19, 2024
bungle and others added 7 commits November 20, 2024 21:59
### Summary

Some properties, like `KONG_SSL_CERT` and `KONG_SSL_CERT_KEY` are
arrays and users can specify many. Vaults didn't work in this scenario:

For example below didn't work before:
```
CERT_1=$(<cert1.crt) \
KEY_1=$(<key1.key) \
CERT_2=$(<cert2.crt) \
KEY_2=$(<key2.key) \
KONG_SSL_CERT_KEY="{vault://env/key-1},{vault://env/key-2}" \
KONG_SSL_CERT="{vault://env/cert-1},{vault://env/cert-2}" \
kong prepare --vv
```

There were also erroneous warning in logs like because of bad array handling:

```
[warn] 680#0: [kong] vault.lua:1475 error caching secret reference {vault://env/cert-1}: bad value type
```

This fixes those.

Signed-off-by: Aapo Talvensaari <[email protected]>
@windmgc windmgc force-pushed the fix/ssl-cert-vault-more-to-be-fixed branch from 139bf1d to 9793830 Compare November 20, 2024 13:59
@windmgc windmgc merged commit bc0acea into master Nov 29, 2024
35 checks passed
@windmgc windmgc deleted the fix/ssl-cert-vault-more-to-be-fixed branch November 29, 2024 07:25
github-actions bot pushed a commit that referenced this pull request Nov 29, 2024
…bsystem (#13855)

* fix(vault): allow arrays in conf loader to be referenced

### Summary

The commit includes the following fix for vault:

Fix the issue that array-type configuration's element cannot be referenced. conf_loader now supports iterate through array-like configuration field and deref the secrets one by one.

Enable the vault to dereference secrets using partial SSL configurations, for example, lua_ssl_trusted_certificate=system, {vault://abc/def}. This is implemented especially for resty environments that execute the actual kong command, with the opts pre_cmd = true. Vault related functionalities can work normally by using valid partial configuration generated in the pre_cmd environment. This change does not have a separate changelog entry because it is part of the previous "array-type config vault ref" fix and is more inline with user's intuition.

Fix the issue that vault reference cannot work well when multiple subsystems(http/stream) are enabled. The kong_processed_secrets environment variable/file are now generated by subsystems, so enabling multiple subsystem will generates multiple env var/secret file for storing vault deref result.

* fix(vault): allow arrays in conf loader to be referenced (#12672)

* fix(*): special treatment for pre_cmd

* fix(cmd): fix vault refs when both http and stream are enabled

* tests(*): fix prepare cmd test

* tests(*): add vault related cmd tests

* docs(changelog): add changelog

* test(*): try to fix test

* fix(*): unsetenv unconditionally clean http/stream env

---------

Signed-off-by: Aapo Talvensaari <[email protected]>
Co-authored-by: Aapo Talvensaari <[email protected]>
(cherry picked from commit bc0acea)
@team-gateway-bot
Copy link
Collaborator

Cherry-pick failed for master, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally.

git remote add upstream https://github.com/kong/kong-ee
git fetch upstream master
git worktree add -d .worktree/cherry-pick-13855-to-master-to-upstream upstream/master
cd .worktree/cherry-pick-13855-to-master-to-upstream
git checkout -b cherry-pick-13855-to-master-to-upstream
ancref=$(git merge-base 7d2f2c1354453318b16f73fccd2c9b9cf0a7e7ae e302e263a420fed8f27702727cca4726570ff575)
git cherry-pick -x $ancref..e302e263a420fed8f27702727cca4726570ff575

@team-gateway-bot
Copy link
Collaborator

@github-actions github-actions bot added the incomplete-cherry-pick A cherry-pick was incomplete and needs manual intervention label Nov 29, 2024
windmgc added a commit that referenced this pull request Nov 29, 2024
…bsystem (#13855)

* fix(vault): allow arrays in conf loader to be referenced

### Summary

The commit includes the following fix for vault:

Fix the issue that array-type configuration's element cannot be referenced. conf_loader now supports iterate through array-like configuration field and deref the secrets one by one.

Enable the vault to dereference secrets using partial SSL configurations, for example, lua_ssl_trusted_certificate=system, {vault://abc/def}. This is implemented especially for resty environments that execute the actual kong command, with the opts pre_cmd = true. Vault related functionalities can work normally by using valid partial configuration generated in the pre_cmd environment. This change does not have a separate changelog entry because it is part of the previous "array-type config vault ref" fix and is more inline with user's intuition.

Fix the issue that vault reference cannot work well when multiple subsystems(http/stream) are enabled. The kong_processed_secrets environment variable/file are now generated by subsystems, so enabling multiple subsystem will generates multiple env var/secret file for storing vault deref result.

* fix(vault): allow arrays in conf loader to be referenced (#12672)

* fix(*): special treatment for pre_cmd

* fix(cmd): fix vault refs when both http and stream are enabled

* tests(*): fix prepare cmd test

* tests(*): add vault related cmd tests

* docs(changelog): add changelog

* test(*): try to fix test

* fix(*): unsetenv unconditionally clean http/stream env

---------

Signed-off-by: Aapo Talvensaari <[email protected]>
Co-authored-by: Aapo Talvensaari <[email protected]>
(cherry picked from commit bc0acea)
@kikito kikito removed the incomplete-cherry-pick A cherry-pick was incomplete and needs manual intervention label Dec 3, 2024
ProBrian pushed a commit that referenced this pull request Dec 13, 2024
…bsystem (#13855)

* fix(vault): allow arrays in conf loader to be referenced

### Summary

The commit includes the following fix for vault:

Fix the issue that array-type configuration's element cannot be referenced. conf_loader now supports iterate through array-like configuration field and deref the secrets one by one.

Enable the vault to dereference secrets using partial SSL configurations, for example, lua_ssl_trusted_certificate=system, {vault://abc/def}. This is implemented especially for resty environments that execute the actual kong command, with the opts pre_cmd = true. Vault related functionalities can work normally by using valid partial configuration generated in the pre_cmd environment. This change does not have a separate changelog entry because it is part of the previous "array-type config vault ref" fix and is more inline with user's intuition.

Fix the issue that vault reference cannot work well when multiple subsystems(http/stream) are enabled. The kong_processed_secrets environment variable/file are now generated by subsystems, so enabling multiple subsystem will generates multiple env var/secret file for storing vault deref result.

* fix(vault): allow arrays in conf loader to be referenced (#12672)

* fix(*): special treatment for pre_cmd

* fix(cmd): fix vault refs when both http and stream are enabled

* tests(*): fix prepare cmd test

* tests(*): add vault related cmd tests

* docs(changelog): add changelog

* test(*): try to fix test

* fix(*): unsetenv unconditionally clean http/stream env

---------

Signed-off-by: Aapo Talvensaari <[email protected]>
Co-authored-by: Aapo Talvensaari <[email protected]>
lhanjian pushed a commit that referenced this pull request Dec 23, 2024
…bsystem (#13855)

* fix(vault): allow arrays in conf loader to be referenced

The commit includes the following fix for vault:

Fix the issue that array-type configuration's element cannot be referenced. conf_loader now supports iterate through array-like configuration field and deref the secrets one by one.

Enable the vault to dereference secrets using partial SSL configurations, for example, lua_ssl_trusted_certificate=system, {vault://abc/def}. This is implemented especially for resty environments that execute the actual kong command, with the opts pre_cmd = true. Vault related functionalities can work normally by using valid partial configuration generated in the pre_cmd environment. This change does not have a separate changelog entry because it is part of the previous "array-type config vault ref" fix and is more inline with user's intuition.

Fix the issue that vault reference cannot work well when multiple subsystems(http/stream) are enabled. The kong_processed_secrets environment variable/file are now generated by subsystems, so enabling multiple subsystem will generates multiple env var/secret file for storing vault deref result.

* fix(vault): allow arrays in conf loader to be referenced (#12672)

* fix(*): special treatment for pre_cmd

* fix(cmd): fix vault refs when both http and stream are enabled

* tests(*): fix prepare cmd test

* tests(*): add vault related cmd tests

* docs(changelog): add changelog

* test(*): try to fix test

* fix(*): unsetenv unconditionally clean http/stream env

---------

Signed-off-by: Aapo Talvensaari <[email protected]>
Co-authored-by: Aapo Talvensaari <[email protected]>
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