ChuanFF opened a new issue, #13055:
URL: https://github.com/apache/apisix/issues/13055
### Current Behavior
**Description:**
When reading environment variables in the `init_by_lua` phase, if two
variables share a common prefix (e.g., `KUBERNETES_CLIENT_TOKEN` and
`KUBERNETES_CLIENT_TOKEN_FILE`), the value of the shorter-named variable may be
erroneously returned when the longer-named one is requested. The issue appears
to be sensitive to the order in which the variables are defined in the
configuration.
### Expected Behavior
**Expected behavior:**
`os.getenv("KUBERNETES_CLIENT_TOKEN_FILE")` should always return the value
of the environment variable named exactly `KUBERNETES_CLIENT_TOKEN_FILE`,
regardless of the definition order of the `env` directives.
### Error Logs
_No response_
### Steps to Reproduce
**Steps to reproduce:**
1. Create a test configuration similar to
`t/kubernetes/discovery/kubernetes2.t` that defines two environment variables
with a common prefix, e.g.:
```
env KUBERNETES_CLIENT_TOKEN=some-token;
env KUBERNETES_CLIENT_TOKEN_FILE=/path/to/token;
```
2. In `init_by_lua`, attempt to read `KUBERNETES_CLIENT_TOKEN_FILE` using
`os.getenv("KUBERNETES_CLIENT_TOKEN_FILE")`.
3. Observe that the returned value is `some-token` (the value of the shorter
variable) instead of `/path/to/token`.
4. Swap the order of the two `env` directives so that the longer name
(`KUBERNETES_CLIENT_TOKEN_FILE`) appears first:
```
env KUBERNETES_CLIENT_TOKEN_FILE=/path/to/token;
env KUBERNETES_CLIENT_TOKEN=some-token;
```
5. In `init_by_lua`, again read `KUBERNETES_CLIENT_TOKEN_FILE` – this time
it returns the correct value `/path/to/token`.
### Environment
master branch
--
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]