-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Support _FILE
suffixed env vars in Docker entrypoint
#47573
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
Changes from 20 commits
05a0133
65974f9
2b90d97
1f03dad
7e361ff
64175d2
9b940cf
7ca020c
21c1104
e564576
6f1cf82
8562703
7f616bd
0162ef2
052d46f
ebce9ef
4054f2d
0a07f70
2a48087
3a778a7
4ac0a9e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,40 @@ if [[ "$1" != "eswrapper" ]]; then | |
fi | ||
fi | ||
|
||
# Allow environment variables to be set by creating a file with the | ||
# contents, and setting an environment variable with the suffix _FILE to | ||
# point to it. This can be used to provide secrets to a container, without | ||
# the values being specified explicitly when running the container. | ||
for VAR_NAME_FILE in $(env | cut -f1 -d= | grep '_FILE$'); do | ||
if [[ -n "$VAR_NAME_FILE" ]]; then | ||
VAR_NAME="${VAR_NAME_FILE%_FILE}" | ||
|
||
if env | grep "^${VAR_NAME}="; then | ||
echo "ERROR: Both $VAR_NAME_FILE and $VAR_NAME are set. These are mutually exclusive." >&2 | ||
exit 1 | ||
fi | ||
|
||
if [[ ! -e "${!VAR_NAME_FILE}" ]]; then | ||
echo "ERROR: File ${!VAR_NAME_FILE} from $VAR_NAME_FILE does not exist" >&2 | ||
exit 1 | ||
fi | ||
|
||
FILE_PERMS="$(stat -c '%a' ${!VAR_NAME_FILE})" | ||
|
||
if [[ "$FILE_PERMS" != "400" && "$FILE_PERMS" != 600 ]]; then | ||
echo "ERROR: File ${!VAR_NAME_FILE} from $VAR_NAME_FILE must have file permissions 400 or 600, but actually has: $FILE_PERMS" >&2 | ||
exit 1 | ||
fi | ||
|
||
echo "Setting $VAR_NAME from $VAR_NAME_FILE at ${!VAR_NAME_FILE}" >&2 | ||
export "$VAR_NAME"="$(cat ${!VAR_NAME_FILE})" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we be stripping a possible newline at the end of the file here ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The newline is already stripped thanks to |
||
|
||
unset VAR_NAME | ||
# Unset the suffixed environment variable | ||
unset "$VAR_NAME_FILE" | ||
fi | ||
done | ||
|
||
# Parse Docker env vars to customize Elasticsearch | ||
# | ||
# e.g. Setting the env var cluster.name=testcluster | ||
|
Uh oh!
There was an error while loading. Please reload this page.