Docker Runtime
Retrieve secrets from Keeper Secrets Manager at Docker runtime

Prerequisites

This page documents the Secrets Manager Docker Runtime integration. In order to utilize this integration, you will need:

About

Keeper Secrets Manager integrates with the Docker Runtime so that you can dynamically retrieve a secret from the vault when the container executes.
The ksm command is used to set environment variables when the container is started instead of hard-coding them into a deployment script. A real world example of this implementation is demonstrated below.

Example: Provision MySQL network user account

The official MySQL docker allows a user to set the MySQL root password and create a network accessible user via environment variables. The MySQL instance is then provisioned when a container is run.
The official MySQL dockerfile is below:
1
FROM debian:buster-slim
2
3
...
4
... INSTALL MySQL 8.0 SERVER
5
...
6
7
ENTRYPOINT ["docker-entrypoint.sh"]
8
9
EXPOSE 3306 33060
10
CMD ["mysqld"]
Copied!
In the standard implementation, the ENTRYPOINT does the provisioning of the container and will use environmental variables that are passed in to set up MYSQL. The environmental variables referenced are the following:
  • MYSQL_ROOT_PASSWORD
  • MYSQL_USER
  • MYSQL_PASSWORD
  • MYSQL_DATABASE
The below steps will show how to initialize the MySQL database with secrets that are stored in the Keeper Vault.
Step 1: Create 2 Vault Records with Secrets
Create two records in the Vault that are managed by the Secrets Manager application. One record contains the root password. The other record contains the regular user, password and database values.
Root MySQL DB
User MySQL DB
Make sure to copy the Record UID that appears in the vault records. These are used in Step 3 below when referencing the vault secrets.
Capture Record UID for Root Record
Capture Record UID for User Record
Step 2: Create dockerfile that builds on the default MySQL dockerfile
We'll create a dockerfile that installs Keeper Secrets Manager CLI (ksm) and then wraps the ENTRYPOINT with ksm exec
In the below dockerfile, the 4 environment variables are replaced using Keeper Notation. We are also passing in the Secrets Manager profile that points to the vault where the secrets are stored.
1
FROM mysql:8
2
3
ARG BUILD_KSM_INI_CONFIG
4
ARG BUILD_ROOT_UID
5
ARG BUILD_USER_UID
6
7
# Avoid system installed modules that might interfer.
8
ENV VIRTUAL_ENV /venv
9
RUN python3 -m pip install --upgrade pip && \
10
python3 -m venv $VIRTUAL_ENV
11
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
12
13
# Upgrade pip since the distro's Python might be old enough that it doesn't like to install newer modules.
14
RUN pip3 install --upgrade pip
15
16
# Install Keeper Secrets Manager CLI
17
RUN pip3 install keeper-secrets-manager-cli
18
19
# Import our configuration, decode it, and store it a place where ksm can find it.
20
RUN ksm profile import $(printenv --null BUILD_KSM_INI_CONFIG)
21
22
ENV MYSQL_ROOT_PASSWORD keeper://${BUILD_ROOT_UID}/field/password
23
ENV MYSQL_USER keeper://${BUILD_USER_UID}/field/login
24
ENV MYSQL_PASSWORD keeper://${BUILD_USER_UID}/field/password
25
ENV MYSQL_DATABASE keeper://${BUILD_USER_UID}/custom_field/database
26
27
ENTRYPOINT ["ksm", "exec", "--", "docker-entrypoint.sh"]
Copied!
​Step 3: Create a shell script to execute the docker build
To execute the docker build, the below script will pass in the Secrets Manager device configuration, root user Record UID and network user Record UID from the vault that contains the secrets.
1
#!/bin/sh
2
3
​export CF=$(ksm profile export
4
5
docker build \
6
--build-arg "BUILD_KSM_INI_CONFIG=${CF}" \
7
--build-arg "BUILD_ROOT_UID=DvpMcO4xV5nZF6jqLGF1fQ" \
8
--build-arg "BUILD_USER_UID=VNxZvvNAZ8j2mL4WIjEzjg" \
9
-t mysql_custom \
10
.
11
Copied!

Contribute to the Docker Runtime Examples

If you have some great examples to contribute to this page, please ping us on Slack or email [email protected]
Last modified 26d ago