jompu opened a new issue, #11121:
URL: https://github.com/apache/apisix/issues/11121
### Current Behavior
The proxy-rewrite plugin uses value from wrong environment variable, when
configured with standalone configuration.
### Expected Behavior
_No response_
### Error Logs
_No response_
### Steps to Reproduce
config.yaml
```yaml
apisix:
node_listen: 9999
enable_ipv6: false
enable_admin: false
ssl:
enable: false
deployment:
role: data_plane
role_data_plane:
config_provider: yaml
```
apisix.yaml
```yaml
upstreams:
- id: echoserver
pass_host: rewrite
upstream_host: echo.free.beeceptor.com
scheme: https
nodes:
- host: echo.free.beeceptor.com
port: 443
weight: 1
plugin_configs:
- id: validaterequest
plugins:
request-validation:
header_schema:
type: object
required:
- X-random-request-header
properties:
X-random-request-header:
type: string
pattern: '^${{SOME_STRING_VALUE}}$'
routes:
- name: test
uri: /test
plugin_config_id: validaterequest
plugins:
proxy-rewrite:
uri: /some/api/endpoint
headers:
set:
X-Some-String-Value-But-Different: "Different
${{SOME_STRING_VALUE_BUT_DIFFERENT}}"
X-Some-String-Value: ${{SOME_STRING_VALUE}}
upstream_id: echoserver
#END
```
The issue does not happen always, anyway try below steps multiple times and
it happens at some point. Quite often it happens at the first time though. The
apisix.yaml is just an example that I have used to reproduce the problem.
1. Run container
```sh
docker run --env SOME_STRING_VALUE_BUT_DIFFERENT=astringvaluebutdifferent \
--env SOME_STRING_VALUE=astringvalue \
-v $(pwd)/config.yaml:/usr/local/apisix/conf/config.yaml:ro \
-v $(pwd)/apisix.yaml:/usr/local/apisix/conf/apisix.yaml:ro \
-p 9999:9999/tcp apache/apisix:3.9.0-debian
```
2. Run curl: `curl -H "X-random-request-header: astringvalue"
http://localhost:9999/test`
- You should receive a json that shows headers set by the proxy-rewrite
plugin.
- Header values should be like this:
X-Some-String-Value: "astringvalue"
X-Some-String-Value-But-Different: "Different astringvaluebutdifferent"
- if this is the case, stop the container and go back to step 1
The problem is that some times the values at step 2 are like this (which is
wrong):
X-Some-String-Value: "astringvalue"
X-Some-String-Value-But-Different: "Different astringvalue"
Restarting the pod or just reloading the configuration (e.g. by editing
apisix.yaml file) will fix the problem.
A script to run steps repeatedly and stop when the issue happens:
```sh
#!/bin/bash
SOME_STRING_VALUE_BUT_DIFFERENT=astringvaluebutdifferent
SOME_STRING_VALUE=astringvalue
start_container () {
docker run -d --env
SOME_STRING_VALUE_BUT_DIFFERENT=$SOME_STRING_VALUE_BUT_DIFFERENT \
--env SOME_STRING_VALUE=$SOME_STRING_VALUE \
-v $(pwd)/config.yaml:/usr/local/apisix/conf/config.yaml:ro \
-v $(pwd)/apisix.yaml:/usr/local/apisix/conf/apisix.yaml:ro \
-p 9999:9999/tcp apache/apisix:3.9.0-debian
}
run_curl () {
curl -s -H "X-random-request-header: astringvalue"
http://localhost:9999/test
}
run_curl_get_header () {
run_curl | jq -r ".headers[\"$1\"]"
}
counter=1
while :; do
container_id=$(start_container)
sleep 5
butdifferentvalue=$(run_curl_get_header
"X-Some-String-Value-But-Different")
if [ "$butdifferentvalue" != "Different $SOME_STRING_VALUE_BUT_DIFFERENT"
]; then
echo
echo "X-Some-String-Value-But-Different header was set with value
'Different $SOME_STRING_VALUE', when it should be 'Different
$SOME_STRING_VALUE_BUT_DIFFERENT'."
echo "We had to repeate the test $counter times."
echo; echo
echo "Here is the wrong echoserver response:"
echo
run_curl
docker rm -f $container_id > /dev/null
break
fi
docker rm -f $container_id > /dev/null
echo "Test succeeded, let's try again!"
sleep 1
counter=$((counter+1))
done
```
### Environment
- Docker image: apache/apisix:3.9.0-debian
--
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]