Learn how esi-cli injects secrets as environment variables and files.
esi-cli
provides two primary mechanisms for making secrets available to your applications: environment variable injection and file injection. The availability and behavior of these mechanisms can depend on the chosen mode of operation.
init
mode (--mode=init
). Secrets are injected as environment variables, making them directly accessible to the application process executed by esi-cli
via the --binary-path
flag.
There are two main ways to control environment variable injection:
--external-secrets
Flag:
ExternalSecret
names to the --external-secrets
flag (e.g., --external-secrets=my-db-config,my-api-keys
):esi-cli
fetches the data from the Kubernetes Secret
resources that are managed by these ExternalSecret
s._
). For example, a secret key database-url
would become the environment variable DATABASE_URL
.--inject-on-env
Flag:
ENV_VAR_NAME=secretName.key
(e.g., --inject-on-env=API_TOKEN=backend-credentials.apiToken,DB_USER=db-access.username
).ExternalSecret
s (referenced by secretName
) and assign them to custom environment variable names.--inject-on-env
conflicts with one that would be generated from --external-secrets
, the mapping from --inject-on-env
takes precedence.esi-cli
process itself before it uses syscall.Exec
to run the target binary specified by --binary-path
. This means the target binary inherits these environment variables directly.esi-cli
to write secret data into files. It is the primary mechanism for daemon
mode (--mode=daemon
) and can also be used in init
mode.
File injection is controlled by the --inject-on-file
flag.
/path/to/target/file=secretName.key
: Injects the value of a specific key
from the Kubernetes Secret
managed by secretName
into the target file. The raw content of the secret key’s value is written to the file./path/to/target/file=secretName
: Injects all data from the Kubernetes Secret
managed by secretName
into the target file. The data is written in YAML format.esi-cli
will automatically create any necessary parent directories for the specified target file paths if they do not already exist. This simplifies deployment as you don’t need to pre-create directory structures for secret files.
Updated HandleFileInjection in pkg/engine/file/file.go to automatically create parent directories...
esi-cli
writes the raw byte data from the Kubernetes Secret directly to files. It does not perform base64 decoding itself, assuming the data in the Secret is already in the desired final form (or, for full secrets, it structures the raw data as YAML).
The USER modified pkg/engine/file/file.go to remove all explicit base64 decoding logic...
init
mode, file injection specified by --inject-on-file
typically occurs before environment variables are set up and before the main application binary is executed. This ensures files are present when the application starts.--inject-on-file
:
--inject-on-file=/etc/app/config/api.token=app-tokens.api,/var/run/secrets/db.yaml=db-credentials
api
key from the app-tokens
secret to /etc/app/config/api.token
.db-credentials
secret as a YAML file to /var/run/secrets/db.yaml
.esi-cli
to deliver secrets to your applications in the most suitable format and at the right stage of their lifecycle.