Skip to content

Commit 3f7e4eb

Browse files
committed
run_sdk_container: Add -e option to pass through environment variables
This only supports passing through variables by name, not setting their values. While it could easily do this, it would encourage the inclusion of secrets on the command line, which is insecure. Docker's -e option doesn't allow separating multiple names with whitespace, but I thought it would be useful here so that you could do things like -e "${!RCLONE_S3_*}". Signed-off-by: James Le Cuirot <jlecuirot@microsoft.com>
1 parent d38518b commit 3f7e4eb

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- SDK: The .env and .sdkenv files are no longer used to pass environment variables into the SDK container as this is insecure. Use run_sdk_container's new -e option instead.

‎run_sdk_container‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ tty=()
1919
remove=""
2020
cleanup=""
2121
mounts=()
22+
envs=()
2223

2324
usage() {
2425
echo " Usage:"
@@ -49,6 +50,8 @@ usage() {
4950
echo " -U Do not update the versionfile. Instead, use the version from the versionfile as-is."
5051
echo " -m <src>:<dest> - Mount local file or directory inside the container."
5152
echo " Can be specified multiple times."
53+
echo " -e <vars> Space-separated list of environment variable names to pass through."
54+
echo " Can be specified multiple times."
5255
echo " -- Stop parsing options at this point, pass the rest as the container command."
5356
echo " -h Print this help."
5457
echo
@@ -73,6 +76,14 @@ while [[ $# -gt 0 ]] ; do
7376
update_versionfile=
7477
shift;;
7578
-m) mounts+=( -v "$2" ); shift; shift;;
79+
-e) if [[ $2 == *=* ]]; then
80+
echo "Do not pass environment variable values to -e, only names."
81+
exit 1
82+
fi
83+
for var in $2; do
84+
envs+=( --env "${var}" )
85+
done
86+
shift 2;;
7687
--) shift; break;;
7788
-*) echo "Unknown flag ${1@Q}, use '-h' or '--help' for usage"; exit 1;;
7889
*) break;;
@@ -176,6 +187,6 @@ EOF
176187

177188
call_docker exec \
178189
--env-file="sdk_lib/env_pass.txt" \
179-
"${tty[@]}" -i \
190+
"${envs[@]}" "${tty[@]}" -i \
180191
"${name}" \
181192
/mnt/host/source/src/scripts/sdk_lib/sdk_entry.sh "$@"

0 commit comments

Comments
 (0)