This commit is contained in:
Rasmus Sjorslev 2019-05-21 15:15:25 +02:00
Родитель 37d6a97219
Коммит a8a7659fae
6 изменённых файлов: 111 добавлений и 0 удалений

2
.gitignore поставляемый Normal file
Просмотреть файл

@ -0,0 +1,2 @@
**/.idea/**
vault.env

13
Dockerfile Normal file
Просмотреть файл

@ -0,0 +1,13 @@
FROM vault:latest
ADD . /tmp/
RUN /tmp/setup.sh
ENV SKIP_SETCAP=1
ENV VAULT_ADDR=http://0.0.0.0:8200
ENTRYPOINT ["/opt/run.sh"]
CMD ["server", "-dev"]
HEALTHCHECK --interval=5s --timeout=2s \
CMD [[ -f /opt/healthcheck ]]

Просмотреть файл

@ -1,2 +1,6 @@
# vault-developer
HashiCorp Vault Docker image for Development purposes
Heavily based on: [https://github.com/dollarshaveclub/vault-dev-docker](https://github.com/dollarshaveclub/vault-dev-docker)
Basic Vault docker image that uses upstream vault (`vault:latest`) Docker image with additional options for configuring secrets, policies and secrets engines after Vault has started.

78
run.sh Executable file
Просмотреть файл

@ -0,0 +1,78 @@
#!/usr/bin/dumb-init /bin/sh
set -e
# Note above that we run dumb-init as PID 1 in order to reap zombie processes
# as well as forward signals to all processes in its session. Normally, sh
# wouldn't do either of these functions so we'd leak zombies as well as do
# unclean termination of all our sub-processes.
# Prevent core dumps
ulimit -c 0
rm -f /opt/healthcheck
# Delete any existing vault.env to get a clean start
rm -f /vaultenv/vault.env
VAULT_CONFIG_DIR=/vault/config
VAULT_SECRETS_FILE=${VAULT_SECRETS_FILE:-"/tmp/secrets.json"}
# You can also set the VAULT_LOCAL_CONFIG environment variable to pass some
# Vault configuration JSON without having to bind any volumes.
if [ -n "$VAULT_LOCAL_CONFIG" ]; then
echo "$VAULT_LOCAL_CONFIG" > "$VAULT_CONFIG_DIR/local.json"
fi
vault server \
-config="$VAULT_CONFIG_DIR" \
-dev-root-token-id="${VAULT_DEV_ROOT_TOKEN_ID:-root}" \
-dev-listen-address="${VAULT_DEV_LISTEN_ADDRESS:-"0.0.0.0:8200"}" \
-dev "$@" &
# Wait for Vault to come up
sleep 1
# Create a new secrets engine with the name provided in environment var VAULT_SECRETS_ENGINE_NAME if it's set
if [[ -n "${VAULT_SECRETS_ENGINE_NAME}" ]]; then
vault secrets enable -path="$VAULT_SECRETS_ENGINE_NAME" -version=2 kv
fi
# Add secrets from the secrets.json file to pre-populate vault with some secrets
# If VAULT_SECRETS_ENGINE_NAME has been defined the secrets will be created in that engine rather than default /secret
if [[ -f "$VAULT_SECRETS_FILE" ]]; then
echo "secrets.json found - writing secrets..."
if [[ -n "${VAULT_SECRETS_ENGINE_NAME}" ]]; then
echo "$VAULT_SECRETS_ENGINE_NAME was found"
vault kv put $VAULT_SECRETS_ENGINE_NAME/project01 "@${VAULT_SECRETS_FILE}"
else
vault kv put secret/project01 "@${VAULT_SECRETS_FILE}"
fi
else
echo "$VAULT_SECRETS_FILE not found, skipping"
fi
vault auth enable approle
# Write a policy that gives full permission to secret/* as well as an additional secrets engine if specified in $VAULT_SECRETS_ENGINE_NAME
echo "{\"path\":{\"secret/*\":{\"capabilities\":[\"create\",\"read\",\"update\",\"delete\",\"list\",\"sudo\"]},\"$VAULT_SECRETS_ENGINE_NAME/*\":{\"capabilities\":[\"create\",\"read\",\"update\",\"delete\",\"sudo\"]}}}" | vault policy write developer -
vault write auth/approle/role/developer \
secret_id_ttl=60m \
token_num_uses=100 \
token_ttl=60m \
token_max_ttl=120m \
secret_id_num_uses=80 \
policies="default,developer"
# Write out the vault URI as well as a roleID and secretID so applications can talk to Vault by reading in the env file.
cat <<EOT >> /vaultenv/vault.env
VAULT_BASE_URI=http://$(hostname -i):8200/v1
VAULT_ROLE_ID=$(vault read -field=role_id auth/approle/role/developer/role-id)
VAULT_SECRET_ID=$(vault write -field=secret_id -f auth/approle/role/developer/secret-id)
EOT
# Docker healthcheck - see Dockerfile for more into
touch /opt/healthcheck
# Block forever so we keep running the vault process
tail -f /dev/null

5
secrets.json Normal file
Просмотреть файл

@ -0,0 +1,5 @@
{
"foo": "bar",
"something": "else",
"run": "stop"
}

9
setup.sh Executable file
Просмотреть файл

@ -0,0 +1,9 @@
#!/bin/sh -x
set -e
mkdir -p /opt/
mv /tmp/run.sh /opt/
chmod a+x /opt/run.sh
rm -rf /var/cache/apk/*