gamalan / caddy-tlsredis

Redis Storage using for Caddy TLS Data
Apache License 2.0
95 stars 31 forks source link

Runtime env variables {env.VARIABLE_NAME} are not loaded #21

Closed crysper closed 1 year ago

crysper commented 3 years ago

Hey,

If I'm putting something like this on the JSON config file instead of using Caddyfile the variables are not parsed even though in other parts of the config are parsed ok.

I get this error: `"logger":"caddy.storage.redis","msg":"TLS Storage are using Redis, on {env.REDIS_HOST}:6379"}

I'm using Caddy version 2.2.2 Running on systemctl service with: ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/caddyfile.json `

gamalan commented 3 years ago

Can you elaborate more? Do you use JSON Configuration, Caddyfile, or ENV variables? How do you write it?

On Sat, Dec 12, 2020 at 5:53 PM crysper notifications@github.com wrote:

Hey,

If I'm putting something like this on the JSON config file instead of using Caddyfile and the variables are not parsed even though in other parts of the config are parsed ok.

I get this error: `"logger":"caddy.storage.redis","msg":"TLS Storage are using Redis, on {env.REDIS_HOST}:6379"}

I'm using Caddy version 2.2.2 `

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/gamalan/caddy-tlsredis/issues/21, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAIYFE4OLBMTL6C4BMSOQR3SUNDS7ANCNFSM4UX74STQ .

TekVanDo commented 2 years ago

Same on my side, I use json configuration, and {env.VAR_NAME}, caddy support this syntax to pass ENV variables to config. But it don`t work in storage part of config

mholt commented 2 years ago

@gamalan Supporting placeholders in provisioning is pretty easy fortunately! You just need to call caddy.NewReplacer() and then call one of the Replace* methods, like ReplaceAll(), ReplaceKnown(), or ReplaceOrErr(), for example:

https://github.com/caddyserver/caddy/blob/186fdba916a128fc2a837852d2ab04ac2efba413/modules/logging/filewriter.go#L75-L77

Then users can specify environment variables (or other placeholders) in your config values. :)

gamalan commented 2 years ago

@TekVanDo can you post your config and logs?

TekVanDo commented 2 years ago

Config { "apps": { "http": { "servers": { "myserver": { "listen": [ ":8080" ], "logs": {}, "routes": [ { "handle": [ { "handler": "reverse_proxy", "upstreams": [ { "dial": "{env.REDIRECT_ADDRESS}" } ] } ] } ] } } }, "tls": { "automation": { "on_demand": { "ask": "{env.SITE_ADDRESS}/proxyCheck" }, "policies": [ { "issuers": [ { "module": "acme", "email": "${env.EMAIL}" } ], "on_demand": true } ] } } }, "storage": { "address": "{env.REDIS_ADDRESS}", "db": 0, "host": "redis", "key_prefix": "{env.REDIS_KEY_PREFIX}", "module": "redis", "password": "", "port": "{env.REDIS_PORT}", "value_prefix": "{env.REDIS_VALUE_PREFIX}" } } And i got an error is - "run: loading initial config: loading new config: loading storage module: loading module 'redis': provision caddy.storage.redis: dial tcp: address {env.REDIS_ADDRESS}: missing port in address"

if I change {env.REDIS_ADDRESS} to ENV variable value (ip + port) all works fine.

gamalan commented 2 years ago

@TekVanDo @crysper can you test the new release (v0.2.9)?

TekVanDo commented 2 years ago

@gamalan. Sorry i just double checked it. I steel got an error

run: loading initial config: loading new config: loading storage module: loading module 'redis': provision caddy.storage.redis: dial tcp: address {env.REDIS_ADDRESS}: missing port in address

TekVanDo commented 2 years ago

@gamalan seems fix don`t helped(

gamalan commented 2 years ago

@TekVanDo you shouldn't use address, but split it in host and port