2017-04-08 04:43:40 -04:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
|
2017-05-04 03:48:13 -04:00
|
|
|
# If command starts with an option, prepend minio.
|
2017-04-08 04:43:40 -04:00
|
|
|
if [ "${1}" != "minio" ]; then
|
|
|
|
if [ -n "${1}" ]; then
|
|
|
|
set -- minio "$@"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-04-29 13:55:05 -04:00
|
|
|
## Look for docker secrets at given absolute path or in default documented location.
|
|
|
|
docker_secrets_env_old() {
|
|
|
|
if [ -f "$MINIO_ACCESS_KEY_FILE" ]; then
|
|
|
|
ACCESS_KEY_FILE="$MINIO_ACCESS_KEY_FILE"
|
|
|
|
else
|
|
|
|
ACCESS_KEY_FILE="/run/secrets/$MINIO_ACCESS_KEY_FILE"
|
|
|
|
fi
|
|
|
|
if [ -f "$MINIO_SECRET_KEY_FILE" ]; then
|
|
|
|
SECRET_KEY_FILE="$MINIO_SECRET_KEY_FILE"
|
|
|
|
else
|
|
|
|
SECRET_KEY_FILE="/run/secrets/$MINIO_SECRET_KEY_FILE"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "$ACCESS_KEY_FILE" ] && [ -f "$SECRET_KEY_FILE" ]; then
|
|
|
|
if [ -f "$ACCESS_KEY_FILE" ]; then
|
|
|
|
MINIO_ACCESS_KEY="$(cat "$ACCESS_KEY_FILE")"
|
|
|
|
export MINIO_ACCESS_KEY
|
|
|
|
fi
|
|
|
|
if [ -f "$SECRET_KEY_FILE" ]; then
|
|
|
|
MINIO_SECRET_KEY="$(cat "$SECRET_KEY_FILE")"
|
|
|
|
export MINIO_SECRET_KEY
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-01-05 13:22:57 -05:00
|
|
|
docker_secrets_env() {
|
|
|
|
if [ -f "$MINIO_ROOT_USER_FILE" ]; then
|
|
|
|
ROOT_USER_FILE="$MINIO_ROOT_USER_FILE"
|
|
|
|
else
|
|
|
|
ROOT_USER_FILE="/run/secrets/$MINIO_ROOT_USER_FILE"
|
|
|
|
fi
|
|
|
|
if [ -f "$MINIO_ROOT_PASSWORD_FILE" ]; then
|
|
|
|
SECRET_KEY_FILE="$MINIO_ROOT_PASSWORD_FILE"
|
|
|
|
else
|
|
|
|
SECRET_KEY_FILE="/run/secrets/$MINIO_ROOT_PASSWORD_FILE"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "$ROOT_USER_FILE" ] && [ -f "$SECRET_KEY_FILE" ]; then
|
|
|
|
if [ -f "$ROOT_USER_FILE" ]; then
|
|
|
|
MINIO_ROOT_USER="$(cat "$ROOT_USER_FILE")"
|
|
|
|
export MINIO_ROOT_USER
|
|
|
|
fi
|
|
|
|
if [ -f "$SECRET_KEY_FILE" ]; then
|
|
|
|
MINIO_ROOT_PASSWORD="$(cat "$SECRET_KEY_FILE")"
|
|
|
|
export MINIO_ROOT_PASSWORD
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-05-05 18:20:02 -04:00
|
|
|
## Set KMS_SECRET_KEY from docker secrets if provided
|
|
|
|
docker_kms_secret_encryption_env() {
|
2021-04-22 11:45:30 -04:00
|
|
|
if [ -f "$MINIO_KMS_SECRET_KEY_FILE" ]; then
|
|
|
|
KMS_SECRET_KEY_FILE="$MINIO_KMS_SECRET_KEY_FILE"
|
2020-08-28 17:04:29 -04:00
|
|
|
else
|
2021-04-22 11:45:30 -04:00
|
|
|
KMS_SECRET_KEY_FILE="/run/secrets/$MINIO_KMS_SECRET_KEY_FILE"
|
2020-08-28 17:04:29 -04:00
|
|
|
fi
|
2019-10-23 01:59:13 -04:00
|
|
|
|
2021-04-22 11:45:30 -04:00
|
|
|
if [ -f "$KMS_SECRET_KEY_FILE" ]; then
|
|
|
|
MINIO_KMS_SECRET_KEY="$(cat "$KMS_SECRET_KEY_FILE")"
|
|
|
|
export MINIO_KMS_SECRET_KEY
|
2019-10-23 01:59:13 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
## Legacy
|
2021-05-05 18:20:02 -04:00
|
|
|
## Set KMS_MASTER_KEY from docker secrets if provided
|
|
|
|
docker_kms_master_encryption_env() {
|
|
|
|
KMS_MASTER_KEY_FILE="/run/secrets/$MINIO_KMS_MASTER_KEY_FILE"
|
2019-07-17 15:55:26 -04:00
|
|
|
|
2021-05-05 18:20:02 -04:00
|
|
|
if [ -f "$KMS_MASTER_KEY_FILE" ]; then
|
|
|
|
MINIO_KMS_MASTER_KEY="$(cat "$KMS_MASTER_KEY_FILE")"
|
|
|
|
export MINIO_KMS_MASTER_KEY
|
2019-07-17 15:55:26 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-07-17 14:20:55 -04:00
|
|
|
# su-exec to requested user, if service cannot run exec will fail.
|
2019-06-10 10:57:42 -04:00
|
|
|
docker_switch_user() {
|
2019-07-18 12:19:50 -04:00
|
|
|
if [ ! -z "${MINIO_USERNAME}" ] && [ ! -z "${MINIO_GROUPNAME}" ]; then
|
2020-12-08 14:14:06 -05:00
|
|
|
if [ ! -z "${MINIO_UID}" ] && [ ! -z "${MINIO_GID}" ]; then
|
|
|
|
groupadd -g "$MINIO_GID" "$MINIO_GROUPNAME" && \
|
|
|
|
useradd -u "$MINIO_UID" -g "$MINIO_GROUPNAME" "$MINIO_USERNAME"
|
|
|
|
else
|
|
|
|
groupadd "$MINIO_GROUPNAME" && \
|
|
|
|
useradd -g "$MINIO_GROUPNAME" "$MINIO_USERNAME"
|
|
|
|
fi
|
|
|
|
exec setpriv --reuid="${MINIO_USERNAME}" --regid="${MINIO_GROUPNAME}" --keep-groups "$@"
|
2019-07-17 14:20:55 -04:00
|
|
|
else
|
|
|
|
exec "$@"
|
2019-06-12 15:16:21 -04:00
|
|
|
fi
|
2017-04-08 04:43:40 -04:00
|
|
|
}
|
|
|
|
|
2021-05-05 18:20:02 -04:00
|
|
|
## Set access env from secrets if necessary. Legacy
|
2021-04-29 13:55:05 -04:00
|
|
|
docker_secrets_env_old
|
|
|
|
|
2021-05-05 18:20:02 -04:00
|
|
|
## Set access env from secrets if necessary. Override
|
2017-05-04 03:48:13 -04:00
|
|
|
docker_secrets_env
|
|
|
|
|
2019-10-23 01:59:13 -04:00
|
|
|
## Set sse encryption from secrets if necessary. Legacy
|
2021-05-05 18:20:02 -04:00
|
|
|
docker_kms_master_encryption_env
|
|
|
|
|
|
|
|
## Set kms encryption from secrets if necessary. Override
|
|
|
|
docker_kms_secret_encryption_env
|
2019-07-17 15:55:26 -04:00
|
|
|
|
2019-06-10 10:57:42 -04:00
|
|
|
## Switch to user if applicable.
|
|
|
|
docker_switch_user "$@"
|