moonming opened a new pull request, #1052: URL: https://github.com/apache/apisix-helm-chart/pull/1052
## What this changes APISIX encrypts SSL private keys and sensitive plugin fields, such as the credentials of authentication plugins, before it stores them in etcd. The chart could set the keyring until [apache/apisix-helm-chart#738](https://github.com/apache/apisix-helm-chart/pull/738) dropped the option. Installations using the default generated configuration therefore retain APISIX's built-in keyring. Those keys are published in the APISIX source code, so they do not protect the stored values from someone who can read etcd. This PR adds `apisix.dataEncryption` in chart 2.20.0, retaining the current master's APISIX 3.20.0 default image: ```yaml apisix: dataEncryption: enableEncryptFields: true # rendered as data_encryption.enable_encrypt_fields keyring: [] # keys in the values, the first one encrypts secretName: "" # or an existing Secret that holds the keys secretKeys: # keys of that Secret, in keyring order - key1 ``` - With `keyring`, the keys are rendered quoted into `config.yaml`. - With `secretName`, the chart passes each key as an environment variable, `APISIX_DATA_ENCRYPTION_KEY_1` and so on, and `config.yaml` refers to them as `${{APISIX_DATA_ENCRYPTION_KEY_1}}`. The keys stay out of the ConfigMap and the release history. - When neither is set, nothing changes: APISIX keeps its built-in keyring, and NOTES warns about it. The warning appears only when APISIX reads its configuration from etcd. The new name is camelCase like the other `apisix.*` values. It also avoids a trap: values files written for the old chart may still contain `apisix.data_encryption`, which has had no effect since [apache/apisix-helm-chart#738](https://github.com/apache/apisix-helm-chart/pull/738). Reusing that name would switch such releases to a keyring that cannot decrypt the data stored since then. If `apisix.data_encryption` is set, NOTES says that it is not read. ### Values that fail to render - The first key is one of the built-in keys. Built-in keys are allowed after it, which is how an existing release moves off the built-in keyring without losing its data. - A `keyring` that is not a list, an entry that is not a string (for example an unquoted number, which YAML would change), or a key that is not 16 or 32 bytes long. The errors do not print the key. - Both `keyring` and `secretName`, `secretName` without `secretKeys`, or `keyring` with `apisix.fullCustomConfig`, which ignores it. The chart cannot inspect the values in an existing Secret. APISIX 3.20.0 validates those values after resolving the environment variables and rejects invalid key lengths during startup. The README now reflects this behavior rather than the older behavior of ignoring unusable keys. ### Existing releases Nothing changes for a release that does not set the new values. The README gets a "Data encryption" section, with steps to move an existing release off the built-in keyring or to rotate a key: 1. Back up etcd. 2. Before changing the keyring, GET each resource with encrypted plugin fields and keep the bodies, without `create_time` and `update_time`. 3. Upgrade with the new key first and the current keys after it, without Admin API changes during the rollout. 4. PUT the saved bodies, not the result of a new GET. 5. Keep the old keys: SSL private keys and upstream client keys stay encrypted with them, because the Admin API does not return those keys. The order matters because APISIX tries the keys in turn without an integrity check: a wrong key passes the AES-CBC padding check for about one value in 256, and APISIX then uses the garbage it decrypts. A GET after the keyring change can therefore return garbage, which a PUT would store for good. ### apisix-dashboard The deprecated `apisix-dashboard` chart signs login tokens with `secret` and creates `admin`/`admin` by default. Its README now warns about that (chart 0.8.4). ## Tests - The source and tests at `6d9409e` passed all four jobs in [fork CI run 43653338993](https://github.com/moonming/apisix-helm-chart/actions/runs/43653338993). The two data-encryption jobs each passed 42 render checks and 44 real kind E2E checks, with Helm 3.22.1 and Helm 4.2.4. The jobs use the chart's default APISIX 3.20.0 image configuration; their logs do not print the running image version or digest, so this is not separate runtime-image verification. - The subsequent change only corrects `README.md.gotmpl` and its generated README. Helm 3.22.1 and Helm 4.2.4 each passed 42/42 render checks for that documentation update. The APISIX and dashboard charts passed `ct lint` in chart-testing v3.13.0 with local version-increment, maintainer and dependency-download checks disabled; no product code, test behavior, chart version or image configuration changed. The local documentation update did not rerun kind E2E. - `test/render/data-encryption.sh`: 42 checks, run with Helm 3.22.1 and Helm 4.2.4 without a cluster. The checks of the new behavior fail on master; the others check that nothing is rendered or warned when it should not be. - `test/e2e/data-encryption.sh` runs on kind with real APISIX and etcd pods. It reads what APISIX stored in etcd and decrypts it with openssl, to check which key encrypted it: - keyring from a Secret: the data is encrypted with that key, not with the built-in key, and the gateway accepts the consumer's key; - rotation: with the new key first and the old one after it, the old data still works and new data uses the new key; - moving off the built-in keyring: the consumer body saved before the change holds the decrypted key; after the upgrade, the old data still works; after a PUT of the saved body, it is encrypted with the new key; once the built-in keys are removed, re-saved data works and data that was not re-saved cannot be read; - SSL migration: re-uploading an SSL object with its original PEM private key encrypts it with the new key. After removing the old key, HTTPS works for the re-uploaded object and fails for the object that was not migrated. - A new CI job, `data-encryption`, runs both on Helm 3 and Helm 4. ## Review The version-update delta at `6d9409e` received an independent review with no HIGH or MEDIUM findings. Its LOW finding about invalid Secret key lengths is fixed in this PR. A fresh independent review will follow publication of the current head. Earlier independent reviews ran on this branch: Codex and a reviewer agent with no prior context. Findings and how they were handled: | Finding | Severity | Resolution | |---|---|---| | The README's re-encryption step said to PUT the resource that a GET returns, but a PUT rejects its `create_time` and `update_time` fields | MEDIUM | Fixed: the README gives the exact command, checked on APISIX 3.19 with etcd, and the end-to-end test re-saves a consumer the same way. | | `${{APISIX_DATA_ENCRYPTION_KEY_<n>}}` is rendered without quotes, so a key made of digits becomes a number | MEDIUM | Not changed: `config.yaml` substitutes variables after parsing, so a quoted reference becomes a number too (checked on 3.19.0: both forms fail with a digit-only key, and both work with the fix for [apache/apisix#14178](https://github.com/apache/apisix/issues/14178)). The README says to use keys that do not look like a number until that fix is released. | | Checks that expect no output could pass when the render itself failed | LOW | Fixed: each render is a check of its own. | | The NOTES checks used `helm install --dry-run=client`, which needs a reachable cluster with Helm 3 | found by CI | Fixed: NOTES.txt is rendered with `helm template`. | | APISIX also encrypts SSL private keys and upstream `tls.client_key` with the keyring, the Admin API does not return them, and so the documented "save again, then remove the built-in keys" breaks HTTPS | HIGH | Fixed: the README covers these keys and says to keep the old keys after the new one, or to upload the SSL objects again before removing them. | | A wrong key passes the AES-CBC padding check for about one value in 256, so with a new key first APISIX decrypts some old values to garbage, and saving them from a new GET stores the garbage | HIGH | Fixed in the README: GET the bodies before the keyring change and PUT those. The underlying decryption without an integrity check is an APISIX issue, outside this chart. | | Pods without the new key cannot read what pods with it write | MEDIUM | Documented: avoid Admin API changes until the rollout has finished, upgrade data planes first, or add a new own key in two steps. | | A keyring given as one string printed the key in the render error | MEDIUM | Fixed: fails with a message without the key; render test added. | | The end-to-end test failed in about 1% of runs, through the same padding effect on its random keys | MEDIUM | Fixed: the test draws keys that do not misread its values. | | `accepts()` evaluated the request once and retried a fixed result | MEDIUM | Fixed. | | A rollback past a keyring change removes the new key | MEDIUM | Documented in the README. | | The `fullCustomConfig` example in the README did not render, because the chart renders that config as a template | MEDIUM | Fixed: the example escapes the braces; checked with Helm 3 and Helm 4. | | Keys in the values are stored in plain text in the ConfigMap; an inline keyring was ignored with `fullCustomConfig`; key length was not checked; NOTES were silent with `enableEncryptFields: false`; a changed Secret value needs a pod restart; an unchecked `mktemp` in the render test | LOW | Fixed or documented. | Fixes https://github.com/apache/apisix-helm-chart/issues/1033 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
