Skip to main content

Source secrets

A source's credentials live on the Worker, in sources-conf.yaml. The file is readable only by the worker user, but anyone who is root on the host, or who can read a backup of the volume, can read every password in it.

Instead of the secret itself, a source can hold a reference to it. The Worker reads the secret when it needs it, and the file keeps only the reference.

Secret references, and the masking of credentials, need QALITA CLI 3.2.0 or later on the Worker.

Syntax​

Any text value under a source's config can be a reference:

ReferenceResolves to
${env:NAME}The Worker's environment variable NAME.
${secret:NAME}The file NAME in the secrets directory: /run/secrets, where Docker and Kubernetes mount secrets, or QALITA_SECRETS_DIR when set. NAME holds letters, digits, ., _ and - only.
${file:/absolute/path}The content of that file. The path must be absolute.
sources-conf.yaml
version: 1
sources:
- id: 12
name: Sales database
type: postgresql
config:
host: postgres.example.org
port: 5432
database: sales
username: qalita_ro
password: ${secret:pg_password}
  • A reference can sit inside a longer value, and a value can hold several, for example postgresql://${env:PG_USER}:${env:PG_PASSWORD}@postgres.example.org/sales.
  • A file is read as UTF-8 text, up to 64 KiB, without its trailing newline: a file written with echo "..." > file works.
  • A reference always resolves to text.
  • A reference to an unknown backend, such as ${vault:secret/data/pg}, is refused with an explicit error instead of being sent as a password.
  • There is no escape syntax: a value shaped like ${word:...} (a lowercase word, then a colon) is always read as a reference.

Where references are accepted​

References are accepted only in source configurations written on the Worker:

  • sources-conf.yaml, edited by hand;
  • qalita source add: type the reference at the password prompt;
  • the Worker's local UI, which must stay out of reach of untrusted users (see Limits).

A source created from the platform's source form travels to the Worker, which writes it into its sources-conf.yaml. If that configuration holds a reference, the Worker refuses it and the platform does not create the source.

This is deliberate. Otherwise anyone allowed to create sources on the platform could register a source pointing at a server they control, with the password set to the reference of another source's secret, or of the worker token. The Worker would resolve it and send the secret to that server. It would also defeat the user access modality, which binds a source to the credentials of one person.

The Worker also marks each source it receives from the platform with origin: platform in sources-conf.yaml. A reference in such a source is never resolved when the source is used: previews, Studio actions and jobs fail with an explicit error, and qalita source validate marks the source invalid. To use references in a source first registered from the platform, check its configuration, delete its origin: platform line, and write the references yourself.

The recommended flow is:

  1. define the source on the Worker, with references, in one of the three ways above;
  2. check it with qalita source validate;
  3. publish it with qalita source push. The platform receives the source's metadata, never its configuration.

Upgrading an existing Worker​

Workers older than QALITA CLI 3.2.0 wrote the sources registered from the platform into sources-conf.yaml as typed, without the origin: platform mark. A value shaped like a reference was harmless then, because nothing resolved it. Once the Worker is upgraded to QALITA CLI 3.2.0 or later, it would be resolved.

Before upgrading, list the values that look like references, in the Worker's QALITA_HOME (~/.qalita by default, /home/qalita/.qalita in the Docker image):

grep -nF '${' sources-conf.yaml

Keep only the references you wrote. Remove the others, or add origin: platform to the sources that were registered from the platform.

When values are resolved​

References are resolved on the Worker only, on a copy, each time a source is used:

  • jobs: the source_conf.json and target_conf.json files handed to the pack hold the resolved values only while the pack runs, with mode 0600. Before and after, they hold the references. If the Worker is killed while a pack runs, the files keep the resolved values until the Worker starts again, which writes the references back;
  • Studio previews and agent actions;
  • connection tests: qalita source validate, qalita source add, qalita source push and the local UI.

The Worker never writes a resolved value back to sources-conf.yaml.

A file (${secret:...}, ${file:...}) is read again at each use, so a rotated secret is picked up without a restart. An environment variable (${env:...}) comes from the Worker's process: a new value needs a Worker restart.

A secret that cannot be resolved fails the operation with a message that names the variable or the file, never a value. A job is reported failed before its pack starts.

What the platform sees​

The platform does not store source credentials: it keeps the source's metadata, and qalita source push sends nothing else. With references, the Worker's own file no longer holds them either.

Masking​

The Worker replaces with *** every resolved value, and every plain value under a sensitive key (password, token, secret, api_key, account_key, private_key, connection_string...), wherever text leaves it:

  • Worker logs: the console, docker logs and log files;
  • pack logs: the logs.txt uploaded to the platform, and the live log stream;
  • job error messages, which the platform stores, and Studio, preview and add-source errors.

Pack output files are not masked: a file that holds one of these values is not uploaded, and the Worker logs a warning (see pack output files).

The plain values of a source registered from the platform are not masked: they were typed by a platform user, who could otherwise make a shared Worker hide any text in every job's logs.

Recipes​

Docker Compose secrets​

docker-compose.yml
services:
qalita-worker:
image: qalita/cli:latest
command: worker run
volumes:
- /srv/qalita:/home/qalita/.qalita
secrets:
- pg_password

secrets:
pg_password:
file: ./secrets/pg_password.txt

Compose mounts the secret at /run/secrets/pg_password. In sources-conf.yaml:

password: ${secret:pg_password}
  • A file secret is mounted with the owner and mode of the host file. The Worker runs as uid 10001, so make the file readable by it, for example with sudo chown 10001 secrets/pg_password.txt and chmod 400.
  • Write references in sources-conf.yaml. Only a source's config is resolved: a reference set in an environment: entry reaches the container as plain text and is never resolved.
  • If you inline the content of sources-conf.yaml in the compose file (a configs: entry with content:, for instance), double the $ of each reference there ($${secret:pg_password}): Compose interpolates ${...} in its own file.

Environment variables: docker run, Kubernetes Secret​

export PG_PASSWORD='...'   # or let your CI or orchestrator set it
docker run -d --name qalita-worker --restart unless-stopped \
-v /srv/qalita:/home/qalita/.qalita \
-e PG_PASSWORD \
qalita/cli:latest worker run

-e PG_PASSWORD without a value passes the variable from the current environment, so the secret does not appear in the command line.

On Kubernetes, take the variable from a Secret:

env:
- name: PG_PASSWORD
valueFrom:
secretKeyRef:
name: qalita-sources
key: pg-password

In both cases, in sources-conf.yaml:

password: ${env:PG_PASSWORD}

Kubernetes Secret volume​

Mount the Secret as files and point QALITA_SECRETS_DIR at them:

containers:
- name: qalita-worker
image: qalita/cli:latest
env:
- name: QALITA_SECRETS_DIR
value: /etc/qalita/secrets
volumeMounts:
- name: source-secrets
mountPath: /etc/qalita/secrets
readOnly: true
volumes:
- name: source-secrets
secret:
secretName: qalita-sources

Each key of the Secret becomes a file:

password: ${secret:pg-password}

Kubernetes updates the mounted files when the Secret changes (unless the volume is mounted with subPath): the next job uses the new value.

HashiCorp Vault, through Vault Agent​

The Vault Agent injector writes secrets to files in the pod. Annotate the Worker's pod:

metadata:
annotations:
vault.hashicorp.com/agent-inject: "true"
vault.hashicorp.com/role: "qalita-worker"
vault.hashicorp.com/agent-inject-secret-pg_password: "secret/data/qalita/sales"
vault.hashicorp.com/agent-inject-template-pg_password: |
{{- with secret "secret/data/qalita/sales" -}}{{ .Data.data.password }}{{- end -}}

The agent writes the password alone to /vault/secrets/pg_password:

password: ${file:/vault/secrets/pg_password}

Outside Kubernetes, a Vault Agent whose template stanza writes to a file the Worker can read works the same way.

Azure Key Vault, through the Secrets Store CSI driver​

The Azure Key Vault provider for the Secrets Store CSI driver mounts Key Vault secrets as files:

apiVersion: secrets-store.csi.x-k8s.io/v1
kind: SecretProviderClass
metadata:
name: qalita-sources
spec:
provider: azure
parameters:
keyvaultName: my-keyvault
tenantId: "<tenant id>"
clientID: "<workload identity client id>"
objects: |
array:
- |
objectName: pg-password
objectType: secret
containers:
- name: qalita-worker
volumeMounts:
- name: secrets-store
mountPath: /mnt/secrets-store
readOnly: true
volumes:
- name: secrets-store
csi:
driver: secrets-store.csi.k8s.io
readOnly: true
volumeAttributes:
secretProviderClass: qalita-sources
password: ${file:/mnt/secrets-store/pg-password}
Native Vault backends

A native vault:// or ${vault:...} backend is not supported yet: Vault Agent and the CSI driver above deliver the secret as a file instead.

Writing the file from a shell​

In double quotes, the shell expands ${...} itself. Use single quotes, or a quoted heredoc:

cat >> ~/.qalita/sources-conf.yaml <<'EOF'
- name: Sales database
type: postgresql
config:
password: ${env:PG_PASSWORD}
EOF

Limits​

  • Root on the host, and pack code, which runs as the worker user, can still read the Worker's environment, its mounted secret files or its memory. References keep credentials out of the configuration file and its backups; they do not protect against a compromised host.
  • Masking works on values. A secret a pack re-encodes (base64, hash, split) is not caught. Values shorter than 4 characters are never masked. A password that is a common word masks that word in every log line: with the password postgres, postgresql shows as ***ql.
  • A kept job workspace (QALITA_KEEP_JOB_WORKSPACE, QALITA_DEBUG_KEEP_FAILED_JOBS) holds the references, not the values. To re-run its pack by hand, provide the values yourself.
  • A Worker killed while a pack runs, or a host crash, leaves that job's source_conf.json and target_conf.json resolved on the jobs volume until the Worker starts again.
  • The local UI has no authentication, and it resolves the references typed into it when it tests a connection. Anyone who can reach it can make the Worker send one of its environment variables, or a file it can read, to a server of their choice. Never make it reachable by untrusted users: from a container, publish its port on the loopback only (-p 127.0.0.1:7070:7070). A web page open in a browser on the Worker's machine can send it requests too, so run the UI only while you use it.
  • Sources registered from the platform by a Worker older than QALITA CLI 3.2.0 carry no origin: platform mark: check them before upgrading (see Upgrading an existing Worker).