2021-08-18 00:17:28 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -eo pipefail
|
|
|
|
|
|
|
|
# Paraphrased from:
|
|
|
|
# https://github.com/influxdata/influxdata-docker/blob/0d341f18067c4652dfa8df7dcb24d69bf707363d/influxdb/2.0/entrypoint.sh
|
|
|
|
# (a repo with no LICENSE.md)
|
|
|
|
|
|
|
|
export STEPPATH=$(step path)
|
|
|
|
|
|
|
|
# List of env vars required for step ca init
|
2021-08-18 20:37:58 +00:00
|
|
|
declare -ra REQUIRED_INIT_VARS=(DOCKER_STEPCA_INIT_NAME DOCKER_STEPCA_INIT_DNS_NAMES)
|
2021-08-18 00:17:28 +00:00
|
|
|
|
|
|
|
# Ensure all env vars required to run step ca init are set.
|
|
|
|
function init_if_possible () {
|
|
|
|
local missing_vars=0
|
|
|
|
for var in "${REQUIRED_INIT_VARS[@]}"; do
|
|
|
|
if [ -z "${!var}" ]; then
|
|
|
|
missing_vars=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [ ${missing_vars} = 1 ]; then
|
2023-01-10 00:51:36 +00:00
|
|
|
>&2 echo "there is no ca.json config file; please run step ca init, or provide config parameters via DOCKER_STEPCA_INIT_ vars"
|
2021-08-18 00:17:28 +00:00
|
|
|
else
|
|
|
|
step_ca_init "${@}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-08-18 18:09:26 +00:00
|
|
|
function generate_password () {
|
|
|
|
set +o pipefail
|
|
|
|
< /dev/urandom tr -dc A-Za-z0-9 | head -c40
|
2021-08-18 19:50:14 +00:00
|
|
|
echo
|
2021-08-18 18:09:26 +00:00
|
|
|
set -o pipefail
|
|
|
|
}
|
|
|
|
|
2021-08-18 00:17:28 +00:00
|
|
|
# Initialize a CA if not already initialized
|
|
|
|
function step_ca_init () {
|
2023-01-10 17:57:47 +00:00
|
|
|
DOCKER_STEPCA_INIT_PROVISIONER_NAME="${DOCKER_STEPCA_INIT_PROVISIONER_NAME:-admin}"
|
|
|
|
DOCKER_STEPCA_INIT_ADMIN_SUBJECT="${DOCKER_STEPCA_INIT_ADMIN_SUBJECT:-step}"
|
2023-02-08 21:22:45 +00:00
|
|
|
DOCKER_STEPCA_INIT_ADDRESS="${DOCKER_STEPCA_INIT_ADDRESS:-:9000}"
|
2023-01-10 17:57:47 +00:00
|
|
|
|
2021-08-18 00:17:28 +00:00
|
|
|
local -a setup_args=(
|
|
|
|
--name "${DOCKER_STEPCA_INIT_NAME}"
|
2023-01-10 00:51:36 +00:00
|
|
|
--dns "${DOCKER_STEPCA_INIT_DNS_NAMES}"
|
2023-01-10 17:57:47 +00:00
|
|
|
--provisioner "${DOCKER_STEPCA_INIT_PROVISIONER_NAME}"
|
2023-01-10 00:51:36 +00:00
|
|
|
--password-file "${STEPPATH}/password"
|
|
|
|
--provisioner-password-file "${STEPPATH}/provisioner_password"
|
2023-02-08 21:22:45 +00:00
|
|
|
--address "${DOCKER_STEPCA_INIT_ADDRESS}"
|
2021-08-18 00:17:28 +00:00
|
|
|
)
|
2021-08-18 18:11:05 +00:00
|
|
|
if [ -n "${DOCKER_STEPCA_INIT_PASSWORD}" ]; then
|
2021-08-18 19:50:14 +00:00
|
|
|
echo "${DOCKER_STEPCA_INIT_PASSWORD}" > "${STEPPATH}/password"
|
2023-01-10 00:36:00 +00:00
|
|
|
echo "${DOCKER_STEPCA_INIT_PASSWORD}" > "${STEPPATH}/provisioner_password"
|
2023-01-10 00:51:36 +00:00
|
|
|
else
|
|
|
|
generate_password > "${STEPPATH}/password"
|
|
|
|
generate_password > "${STEPPATH}/provisioner_password"
|
2021-08-18 18:11:05 +00:00
|
|
|
fi
|
2023-01-11 19:19:39 +00:00
|
|
|
if [ "${DOCKER_STEPCA_INIT_SSH}" == "true" ]; then
|
2021-08-18 00:17:28 +00:00
|
|
|
setup_args=("${setup_args[@]}" --ssh)
|
|
|
|
fi
|
2023-01-11 19:19:39 +00:00
|
|
|
if [ "${DOCKER_STEPCA_INIT_ACME}" == "true" ]; then
|
2022-12-08 05:00:39 +00:00
|
|
|
setup_args=("${setup_args[@]}" --acme)
|
|
|
|
fi
|
2023-01-11 19:19:39 +00:00
|
|
|
if [ "${DOCKER_STEPCA_INIT_REMOTE_MANAGEMENT}" == "true" ]; then
|
|
|
|
setup_args=("${setup_args[@]}" --remote-management
|
|
|
|
--admin-subject "${DOCKER_STEPCA_INIT_ADMIN_SUBJECT}"
|
|
|
|
)
|
2022-12-08 05:00:39 +00:00
|
|
|
fi
|
2021-08-18 00:17:28 +00:00
|
|
|
step ca init "${setup_args[@]}"
|
2023-01-10 01:59:33 +00:00
|
|
|
echo ""
|
2023-01-11 19:19:39 +00:00
|
|
|
if [ "${DOCKER_STEPCA_INIT_REMOTE_MANAGEMENT}" == "true" ]; then
|
2023-01-10 17:57:47 +00:00
|
|
|
echo "👉 Your CA administrative username is: ${DOCKER_STEPCA_INIT_ADMIN_SUBJECT}"
|
2023-01-10 01:59:33 +00:00
|
|
|
fi
|
|
|
|
echo "👉 Your CA administrative password is: $(< $STEPPATH/provisioner_password )"
|
|
|
|
echo "🤫 This will only be displayed once."
|
2023-01-10 02:01:14 +00:00
|
|
|
shred -u $STEPPATH/provisioner_password
|
2021-08-18 00:17:28 +00:00
|
|
|
mv $STEPPATH/password $PWDPATH
|
|
|
|
}
|
|
|
|
|
2022-04-24 09:08:51 +00:00
|
|
|
if [ -f /usr/sbin/pcscd ]; then
|
2023-01-10 00:51:36 +00:00
|
|
|
/usr/sbin/pcscd
|
2022-04-24 09:08:51 +00:00
|
|
|
fi
|
|
|
|
|
2023-01-10 00:39:34 +00:00
|
|
|
if [ ! -f "${STEPPATH}/config/ca.json" ]; then
|
2023-01-10 00:51:36 +00:00
|
|
|
init_if_possible
|
2023-01-10 00:39:34 +00:00
|
|
|
fi
|
|
|
|
|
2021-08-18 20:37:58 +00:00
|
|
|
exec "${@}"
|