circus-tent / circus

A Process & Socket Manager built with zmq
http://circus.readthedocs.org/
Other
1.55k stars 257 forks source link

Copying environment variables with dollar sign + capital letters #1189

Open nmonterroso opened 2 years ago

nmonterroso commented 2 years ago

Hi, This is a very strange issue, but one we're running into with a 3rd party secret we are unable to change. With circus 0.17.1:

(circus-env-var) [16:32] ~/venv/circus-env-var env | grep TEST_VAR
TEST_VAR=foo$BAR

(circus-env-var) [16:32] ~/venv/circus-env-var cat test.py
import os
from time import sleep
import logging

def main():
  while True:
    logging.info(os.getenv('TEST_VAR'))
    sleep(5)

if __name__ == '__main__':
  logging.basicConfig(level=logging.INFO)
  main()

(circus-env-var) [16:32] ~/venv/circus-env-var cat circus.ini
[watcher:test]
cmd = python test.py
copy_env = true
stdout_stream.class = StdoutStream
stderr_stream.class = StdoutStream

If I run test.py directly with python test.py I get the expected output:

(circus-env-var) [16:33] ~/venv/circus-env-var python test.py
INFO:root:foo$BAR
INFO:root:foo$BAR
^CTraceback (most recent call last):
  File "test.py", line 14, in <module>
    main()
  File "test.py", line 9, in main
    sleep(5)
KeyboardInterrupt
(circus-env-var) [16:34] ~/venv/circus-env-var

However if I run with the circus watcher, the $ and everything after is stripped out:

(circus-env-var) [16:34] ~/venv/circus-env-var circusd circus.ini
2022-08-08 16:34:41 circus[89891] [INFO] Starting master on pid 89891
2022-08-08 16:34:41 circus[89891] [INFO] Arbiter now waiting for commands
2022-08-08 16:34:41 circus[89891] [INFO] test started
INFO:root:foo
INFO:root:foo
^C2022-08-08 16:34:48 circus[89891] [INFO] Got signal SIG_INT
2022-08-08 16:34:48 circus[89891] [INFO] Arbiter exiting
2022-08-08 16:34:48 circus[89891] [INFO] test stopped
(circus-env-var) [16:34] ~/venv/circus-env-var

Strangely enough, if I change my env var after the $ to be lower case (or numeric), it works as expected:

(circus-env-var) [16:34] ~/venv/circus-env-var export TEST_VAR='foo$bar'
(circus-env-var) [16:35] ~/venv/circus-env-var circusd circus.ini
2022-08-08 16:35:52 circus[89999] [INFO] Starting master on pid 89999
2022-08-08 16:35:52 circus[89999] [INFO] Arbiter now waiting for commands
2022-08-08 16:35:52 circus[89999] [INFO] test started
INFO:root:foo$bar
INFO:root:foo$bar
^C2022-08-08 16:35:58 circus[89999] [INFO] Got signal SIG_INT
2022-08-08 16:35:58 circus[89999] [INFO] Arbiter exiting
2022-08-08 16:35:58 circus[89999] [INFO] test stopped

It seems like the env var is being evaluated. If I set BAR to something:

(circus-env-var) [16:35] ~/venv/circus-env-var export BAR="fizz"
(circus-env-var) [16:37] ~/venv/circus-env-var export TEST_VAR='foo$BAR'
(circus-env-var) [16:37] ~/venv/circus-env-var env | ag "(BAR|TEST_VAR)"
TEST_VAR=foo$BAR
BAR=fizz

(circus-env-var) [16:37] ~/venv/circus-env-var circusd circus.ini
2022-08-08 16:37:50 circus[90206] [INFO] Starting master on pid 90206
2022-08-08 16:37:50 circus[90206] [INFO] Arbiter now waiting for commands
2022-08-08 16:37:50 circus[90206] [INFO] test started
INFO:root:foofizz
INFO:root:foofizz
^C2022-08-08 16:37:56 circus[90206] [INFO] Got signal SIG_INT
2022-08-08 16:37:56 circus[90206] [INFO] Arbiter exiting
2022-08-08 16:37:56 circus[90206] [INFO] test stopped

but I would expect the environment variables to be passed through exactly as they are, without being evaluated. In my case, getting foo$BAR in my output.

Let me know if there is anything else I can provide.