rathole icon indicating copy to clipboard operation
rathole copied to clipboard

[Docker] Configure with env vars

Open williamhatcher opened this issue 2 years ago • 13 comments

Feature Proposed Is it possible to allow configuration via env vars in the docker image, or something other than a file?

Use Case Running rathole in a Portainer instance. Portainer doesn't allow you to attach files to a docker compose stack.

williamhatcher avatar Jan 22 '23 06:01 williamhatcher

This is a very interesting idea. But given the rathole configuration format is not trivial, how can you do that in env vars? Do you have any proposals? Maybe we can pass config string in a single env var but I wonder if there's a length limit for env var that renders many configurations unpractical.

I'm not familiar with Portainer. What does other software do? I think many software requires a configuration more than two lines of username and password to work.

rapiz1 avatar Mar 07 '23 15:03 rapiz1

A quick google search says that there is basically no length limit for this usecase. Some results say around 32k characters on Windows, while linux has over 256 MB per/for all? Environment variables. Basically, endless for this usecase.

I'd suggest that . is replaced by one _ and [header] and configBody seperated by two __:

[client]
remote_addr = "example.cm"
default_token = "xyz"

[client.transport]
type = "noise"

[client.transport.noise]
pattern = "Noise_KK_25519_ChaChaPoly_BLAKE2s"

[client.services.http]
local_addr = "ingress-nginx-public-controller:80"

[client.services.https]
local_addr = "ingress-nginx-public-controller:443"

CLIENT__REMOTE_ADDR = "example.cm"
CLIENT__DEFAULT_TOKEN = "xyz"

CLIENT_TRANSPORT__TYPE = "noise"

CLIENT_TRANSPORT_NOISE__PATTERN = "Noise_KK_25519_ChaChaPoly_BLAKE2s"

CLIENT_SERVICES_HTTP__LOCAL_ADDR = "ingress-nginx-public-controller:80"

CLIENT_SERVICES_HTTPS__LOCAL_ADDR = "ingress-nginx-public-controller:443"


Skaronator avatar May 29 '23 20:05 Skaronator

env var is a good idea, nice to have.

jingkang99 avatar May 31 '23 08:05 jingkang99

Just found this project. It is also written in rust and uses TOML as config file format but allows overwriting everything via environment variables. https://github.com/romanz/electrs/blob/master/doc/config.md#electrs-configuration

Skaronator avatar Jun 10 '23 20:06 Skaronator

A quick google search says that there is basically no length limit for this usecase. Some results say around 32k characters on Windows, while linux has over 256 MB per/for all?

In that case, can we have a single entry for the configuration? The format you propose looks very powerful and flexible but I'm afraid it can bother users

rapiz1 avatar Oct 01 '23 06:10 rapiz1

A single environment variable would be fine too. Gitlab Omnibus Image does that too and the config can get long as well.

Skaronator avatar Oct 01 '23 07:10 Skaronator

So we have a proposed solution here. Anyone is welcomed to implement this feature. I would like the env var is named as RATHOLE_CONFIG_STR or something alike

rapiz1 avatar Oct 01 '23 08:10 rapiz1

Can I pass keys and secret to .toml from .env file?

nemanjam avatar Jun 02 '24 09:06 nemanjam

Nope

Skaronator avatar Jun 02 '24 10:06 Skaronator

I believe the most versatile solution is to use some sort of template syntax to insert env variable values into the config file, similar to what is implemented by frp. This makes it possible to bind any env variable to any config field.

Example:

[client]
remote_addr = "{{ env:RH_REMOTE_ADDR }}"
default_token = "{{ env:RH_DEFAULT_TOKEN }}"
export RH_REMOTE_ADDR="x.x.x.x"
export RH_DEFAULT_TOKEN="token"

rathole --client config.toml

With docker-compose you can bind mount the config file and add env variables in the "environment" section.

As for Portainer, I think development should not be oriented towards overcoming limitations of a third-party software.

pauloromeira avatar Aug 19 '24 01:08 pauloromeira

I believe the most versatile solution is to use some sort of template syntax to insert env variable values into the config file, similar to what is implemented by frp. This makes it possible to bind any env variable to any config field.

Example:

[client]
remote_addr = "{{ env:RH_REMOTE_ADDR }}"
default_token = "{{ env:RH_DEFAULT_TOKEN }}"
export RH_REMOTE_ADDR="x.x.x.x"
export RH_DEFAULT_TOKEN="token"

rathole --client config.toml

With docker-compose you can bind mount the config file and add env variables in the "environment" section.

As for Portainer, I think development should not be oriented towards overcoming limitations of a third-party software.

This is also how vector (which also made with rust) implements it

rucciva avatar Aug 19 '24 23:08 rucciva