-
-
Notifications
You must be signed in to change notification settings - Fork 517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[v2] Faulty creation of env file #1720
Comments
This is the intended and documented behavior. We're using the same format as Docker Compose: https://www.getambassador.io/docs/telepresence/latest/reference/environment/ Also see https://docs.docker.com/compose/env-file/ where you'll find the following text: "There is no special handling of quotation marks. This means that they are part of the VAL." How are you using the env file? |
Hi, Quotation marks have nothing to do with that, they don't appear in the value as it reaches the pod, I just had to use them when defining the secrets it gets the value from. In env files, to be able to read the $ correctly, it just needs to be escaped. The var file is sourced into the environment where my local application runs. |
The Docker Compose format knows nothing about escaping so If you need a file that you can source into your environment, then you will need to create a proper shell script that contains the variables. I.e. you need to perform the escaping so that the intended shell reads the values correctly. Here's an example in python that does that. It assumes
|
Hello, I'm not sure to what extend Docker Compose "knows nothing about escaping". Docker Compose doesn't use any particular formatting of .env files that's different than regular .env. A .env file is just a set of key/value pairs that can be sourced. But Docker Compose clearly doesn't just source a .env file plainly because any $ in a .env value will get correctly loaded in a container environment as opposed to simply sourcing the same .env file - so Docker Compose does escape the values in practice. I'm not sure why your snippet uses json though? The files that telepresence creates are not json files and it's not a matter of quoting, it's a matter of escaping eg: MY_PASS=12345$678 should become MY_PASS=12345\$678 in order for it to be sourced correctly into an environment. Any plain shell which does a |
Docker treats what's right of the equal sign verbatim, e.g.
is to Docker what
is to a shell. The reason I used json in the example is that a) json has a canonical way of representing the strings (no discussion around Docker or shell syntax), and b) it is extremely easy to parse into a dictionary. And yes, telepresence will create a json file if you use |
I found this blog entry which might bring some more clarity: https://dev.to/tvanantwerp/don-t-quote-environment-variables-in-docker-268h |
Ah, I see the point now - thanks for your patience. My 2 cents are that if I'm expected to use the dumped .env file with a locally running service, then it would be most useful to fully support the use case (as a service running on localhost will read/source by default the file as in a shell). I respect that t2 may not want to presume how those values will be loaded but if the advertised use case is to be able to run your code locally then this would be a touch of usability that could be optional. |
I agree. Perhaps we should add a I'm actually tempted to also rename |
|
Maybe something has changed in the meantime, but the Docker docs clearly say that the env file does escaping and so on. Am I missing something? |
@alnr something has indeed changed for docker run -e 'MY_PASS="123$678"' busybox env | grep MY_PASS You can note that the output here is echoed verbatim, quotes, dollar sign and all. Putting the declaration in a file and using A better solution to the problem than what I proposed before (with --env-shell) is probably to add an |
A new `--env-syntax <syntax>` was introduced to allow control over the syntax of the file created when using the flag `--env-file <file>`. Valid syntaxes are "docker", "compose", "sh", "csh", "cmd", and "ps"; where "sh", "csh", and "ps" can be suffixed with ":export". Closes #1720 Signed-off-by: Thomas Hallgren <thomas@tada.se>
A new `--env-syntax <syntax>` was introduced to allow control over the syntax of the file created when using the flag `--env-file <file>`. Valid syntaxes are "docker", "compose", "sh", "csh", "cmd", and "ps"; where "sh", "csh", and "ps" can be suffixed with ":export". Closes #1720 Signed-off-by: Thomas Hallgren <thomas@tada.se> Signed-off-by: Thomas Hallgren <thomas@datawire.io>
I am intercepting a service as such
which also dumps the env of the pods serviced by that service.
However, in my case I have a value as follows
RABBITMQ_PASS=9HKCNJY8$cGSanrbJLD7X!ky
In the pod, the value is set as follows
RABBITMQ_PASS="9HKCNJY8$cGSanrbJLD7X!ky"
since the $ is a special shell character. However Telepresence dumps it as-is, without quotes and without escaping it which results in incorrect value passed on to the local service.
I know it may not seem like a big deal, but I've spent a fair amount of time debugging why my services were failing locally.
The text was updated successfully, but these errors were encountered: