Replies: 3 comments 2 replies
-
I don't think you understand what You can put the variables in Your best bet would either be to use
Then run |
Beta Was this translation helpful? Give feedback.
-
Actually, that won't work because |
Beta Was this translation helpful? Give feedback.
-
This discussion has been automatically locked since there has not been any recent activity after it was closed. |
Beta Was this translation helpful? Give feedback.
-
I'm looking for a way to forward environment variables in a current shell to new detatched sessions. The environment variables in question are secret, so I want to avoid any logging of their values. The names of the sensitive environment variables are known and are not secret, so they can appear in command history logs.
Context
I'm writing a Python module called cmd-queue, which executes DAGs of bash commands. It currently has 3 backends. 1. A no-dependency serial mode where all commands are executed in-order in the current shell. 2. A slurm backend for heavyweight scheduling jobs - if you have the patience to set it up, and 3. a custom tmux backend which has become my goto-backend due to its simplicity and ease of use. In this case I use
tmux new-session
to create a new session for each "worker" andtmux send
to send each worker their list of tasks, which comes down to sourcing a bash script that has all of the tasks written out. In some cases users will have secrets in their main shell's environment, and I need to securely pass those to new sessions without writing them to the bash scripts (this is the current workaround that I'm doing, but I'd really like to avoid logging secrets) or using the values of environment variables in the bash commands I'm using to drive tmux (because these commands get logged).Previous Research
Based on references I found:
https://unix.stackexchange.com/questions/743817/how-to-start-tmux-in-a-way-that-it-inherits-all-environment-variables-from-the-c
https://stackoverflow.com/questions/20701757/tmux-setting-environment-variables-for-sessions
I've been able to get close to what I need, but not exactly.
Partial Solution 1
I can use the -L command to forward an environment variable - importantly without specifying its value.
Then in the new attached session the environment variables are available.
However, the problem with this option is that I immediately attatch to the session. I need to be able to start a new session without attaching to it, so I can keep executing commands in my current shell to create more new sessions and drive them.
Partial Solution 2
It is possible to specify environment variables to
tmux new-session
with the-e
flag, however, it requires that you also specify the value.As previously stated, the text of each command is logged, and I don't want the secret value to appear in the logs, so this wont work either.
Summary
Did I understand what functionality currently exists correctly? Or did I miss something? Is there an existing way to specify which enviornment variables from the current shell should be forwarded to a new tmux session without writing the values of those variables to disk or using them in the command itself (forwarding the entire environment would also be acceptable)? If not, is that a feature that could be implemented?
Also, is
tmux -L MYVAR
doing what I think and not writing the value$MYVAR
directly to disk? If that is true, is there any reason the same feature can't be ported to thenew-session
command?Beta Was this translation helpful? Give feedback.
All reactions