2017-04-08 01:43:40 -07:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
|
2017-05-04 00:48:13 -07:00
|
|
|
# If command starts with an option, prepend minio.
|
2017-04-08 01:43:40 -07:00
|
|
|
if [ "${1}" != "minio" ]; then
|
|
|
|
if [ -n "${1}" ]; then
|
|
|
|
set -- minio "$@"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2021-04-29 10:55:05 -07: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 10:22:57 -08: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 15:20:02 -07:00
|
|
|
## Set KMS_SECRET_KEY from docker secrets if provided
|
|
|
|
docker_kms_secret_encryption_env() {
|
2021-04-22 17:45:30 +02:00
|
|
|
if [ -f "$MINIO_KMS_SECRET_KEY_FILE" ]; then
|
|
|
|
KMS_SECRET_KEY_FILE="$MINIO_KMS_SECRET_KEY_FILE"
|
2020-08-28 23:04:29 +02:00
|
|
|
else
|
2021-04-22 17:45:30 +02:00
|
|
|
KMS_SECRET_KEY_FILE="/run/secrets/$MINIO_KMS_SECRET_KEY_FILE"
|
2020-08-28 23:04:29 +02:00
|
|
|
fi
|
2019-10-22 22:59:13 -07:00
|
|
|
|
2021-04-22 17:45:30 +02:00
|
|
|
if [ -f "$KMS_SECRET_KEY_FILE" ]; then
|
|
|
|
MINIO_KMS_SECRET_KEY="$(cat "$KMS_SECRET_KEY_FILE")"
|
|
|
|
export MINIO_KMS_SECRET_KEY
|
2019-10-22 22:59:13 -07:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
## Legacy
|
2021-05-05 15:20:02 -07: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 21:55:26 +02:00
|
|
|
|
2021-05-05 15:20:02 -07: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 21:55:26 +02:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-07-17 11:20:55 -07:00
|
|
|
# su-exec to requested user, if service cannot run exec will fail.
|
2019-06-10 07:57:42 -07:00
|
|
|
docker_switch_user() {
|
2019-07-18 18:19:50 +02:00
|
|
|
if [ ! -z "${MINIO_USERNAME}" ] && [ ! -z "${MINIO_GROUPNAME}" ]; then
|
2020-12-09 00:44:06 +05:30
|
|
|
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 11:20:55 -07:00
|
|
|
else
|
|
|
|
exec "$@"
|
2019-06-12 12:16:21 -07:00
|
|
|
fi
|
2017-04-08 01:43:40 -07:00
|
|
|
}
|
|
|
|
|
2021-05-05 15:20:02 -07:00
|
|
|
## Set access env from secrets if necessary. Legacy
|
2021-04-29 10:55:05 -07:00
|
|
|
docker_secrets_env_old
|
|
|
|
|
2021-05-05 15:20:02 -07:00
|
|
|
## Set access env from secrets if necessary. Override
|
2017-05-04 00:48:13 -07:00
|
|
|
docker_secrets_env
|
|
|
|
|
2019-10-22 22:59:13 -07:00
|
|
|
## Set sse encryption from secrets if necessary. Legacy
|
2021-05-05 15:20:02 -07:00
|
|
|
docker_kms_master_encryption_env
|
|
|
|
|
|
|
|
## Set kms encryption from secrets if necessary. Override
|
|
|
|
docker_kms_secret_encryption_env
|
2019-07-17 21:55:26 +02:00
|
|
|
|
2019-06-10 07:57:42 -07:00
|
|
|
## Switch to user if applicable.
|
|
|
|
docker_switch_user "$@"
|