apache / apisix

The Cloud-Native API Gateway
https://apisix.apache.org/blog/
Apache License 2.0
13.93k stars 2.44k forks source link

feat: support env var for secret config of plugins like kafka-logger, elasticsearch-logger #11366

Open Zeeeeta opened 1 week ago

Zeeeeta commented 1 week ago

Description

I am using helm to deploy a set of APISIX, Dashboard and etcd. I defined the extraEnvVars in the values.yaml and set K8s secret, and able to print the ENV VAR key/value in the apisix-gateway pod.

However, when I set the plugin config json following this guide, it is not able to use the ENV VAR value. https://apisix.apache.org/docs/apisix/terminology/secret/#use-environment-variables-to-manage-secrets

Sample of simplied config as below:

{
    "plugins": {
        "kafka-logger": {
            "brokers": [
                {
                    "sasl_config": {
                        "mechanism": "PLAIN",
                        "password": "$ENV://KAFKA_LOGGER_PW",
                        "user": "user"
                    }
                }
            ]
        },
        "elasticsearch-logger": {
            "auth": {
                "password": "$ENV://ELASTICSEARCH_LOGGER_PW",
                "username": "user"
            }
        }
    }
}

I also tried with the mocking plugin but with no luck, is the ENV VAR mechanism not working on every plugin?

Environment

Kubernetes Version: v1.27.12 +rke2r1 APISIX Helm Charts Version: 2.8.0 APISIX version: 3.9.1 Operating system: Linux apisix-797b96d476-vtkg2 5.14.0-362.8.1.el9_3.x86_64 OpenResty / Nginx version: openresty/1.25.3.1 etcd version: 3.5.10

hanqingwu commented 1 week ago

Can you try to use lowcase $env:// like #11141 ?

Zeeeeta commented 1 week ago

Can you try to use lowcase $env:// like #11141 ?

Thanks for reply. Tested and worked on kafka-logger, but not work for elasticsearch-logger and openid-connect

Edit: not work on kafka-logger as well, it worked maybe due to cache