Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Use a Secrets Manager

Keep the credentials of a self-hosted Soda Runner in HashiCorp Vault and sync them into Kubernetes with the External Secrets Operator, so that rotated passwords reach the runner without a redeploy.

A self-hosted Soda Runner connects to your data sources from your own Kubernetes cluster, so the data source credentials can stay in your environment. This guide keeps every credential the runner needs in HashiCorp Vault: the user name and password of the data source, and the runner's own API key. None of them appears in Soda Cloud or in the Helm values of the runner.

The External Secrets Operator (ESO) copies the credentials from Vault into Kubernetes secrets and reads Vault again at a set interval. The runner mounts the data source credentials into every job it starts, and the data source configuration in Soda Cloud refers to them as environment variables. When you rotate the password in Vault, the next job uses the new one.

The self-hosted Soda Runner is available on license plans. Need access? Contact us.

The examples use a PostgreSQL database sales_dw with a read-only user soda_reader, and a runner in the namespace soda-runner. The setup has these parts:

Part
Role

Vault

Holds the credentials under secret/soda/ in a KV version 2 secrets engine

SecretStore

Tells ESO how to reach Vault and how to authenticate, here with an AppRole

ExternalSecret

Tells ESO which Vault secret to copy into which Kubernetes secret, and how often to refresh it

Soda Runner

Reads its API key from one Kubernetes secret and mounts the data source credentials from another into its jobs

Data source in Soda Cloud

Refers to the credentials as ${env.POSTGRES_USER} and ${env.POSTGRES_PASSWORD}

ESO supports other secrets managers, such as AWS Secrets Manager and Azure Key Vault. With another provider, you store the credentials there and write a SecretStore for that provider; the runner and the data source configuration stay the same.

Prerequisites

  • A Kubernetes cluster, with kubectl and Helm installed. See Deploy a Soda Runner in a Kubernetes cluster for the network access the runner needs.

  • A Vault server that pods in the cluster can reach, with a KV version 2 secrets engine mounted at secret, and the vault CLI logged in with permission to write policies and enable auth methods.

  • A PostgreSQL database that the cluster can reach, with a read-only user for Soda. See PostgreSQL for the grants.

  • In Soda Cloud, the global permission Create data sources and manage runners. See Global and dataset roles.

To try the setup without a Vault server, run Vault in dev mode in the cluster. A dev server keeps its data in memory, starts unsealed, and mounts KV version 2 at secret; the Helm chart sets its root token to root. Use it only to try things out.

helm repo add hashicorp https://helm.releases.hashicorp.com
helm install vault hashicorp/vault -n vault --create-namespace --set server.dev.enabled=true
kubectl -n vault port-forward svc/vault 8200:8200

In a second terminal, export VAULT_ADDR=http://127.0.0.1:8200 VAULT_TOKEN=root. In secret-store.yml, set server to http://vault.vault.svc.cluster.local:8200.

Store the credentials in Vault

Store the user name and password of the database user in Vault. read -rs reads the password without showing it, and password=- makes Vault read it from standard input, so it does not end up in your shell history:

Give ESO read access to Vault

Create a policy that can read the secrets under secret/soda/. With KV version 2, the policy path includes data/:

Write the policy, enable the AppRole auth method, and create a role with the policy:

ESO logs in with the role ID and a secret ID of this role, and uses the token it receives to read the secrets.

Install the External Secrets Operator

Install ESO with its Helm chart:

The operator serves its resources in the API version external-secrets.io/v1.

Sync the credentials into Kubernetes

Create the namespace of the runner, and a Kubernetes secret with the role ID and a new secret ID of the AppRole. The values go from vault straight into the secret:

Create a SecretStore that connects to Vault with the AppRole. Set server to the address of your Vault server:

Create an ExternalSecret that copies the database credentials into the Kubernetes secret sales-postgres-credentials:

A few details in the two resources:

  • A SecretStore serves only the ExternalSecret resources in its own namespace. To share one Vault connection across namespaces, use a ClusterSecretStore: add the namespace of the vault-approle secret to roleRef and secretRef, and set kind: ClusterSecretStore in secretStoreRef. See SecretStore and ClusterSecretStore in the ESO documentation.

  • dataFrom.extract reads every key of the Vault secret soda/sales-postgres, so the template can use .username and .password.

  • The template writes a single key, sales_postgres.env, in the dotenv format. The runner reads each key of the secret as a file of environment variables. The single quotes keep characters such as #, $, and spaces in the password as they are. See Templating for the template syntax.

  • refreshInterval sets how often ESO reads Vault and updates the Kubernetes secret. Without it, ESO refreshes every hour. Match it to how soon the runner must pick up a rotated password.

Apply both resources and check that they are ready:

Deploy the runner

1

Create the runner's API key

In Soda Cloud, go to Settings > Runners and click New Soda Runner. Copy the API key ID and the API key secret from the dialog.

Store both in Vault. Replace <API key ID>, then paste the secret when read waits for it:

2

Sync the API key into Kubernetes

The runner uses its API key twice: to connect to Soda Cloud, and to pull its images from the Soda container registry. Create two ExternalSecret resources, one for each:

The registry is registry.us.soda.io for the US region of Soda Cloud and registry.cloud.soda.io for the EU region.

3

Install the runner

Create a values file that points the runner at the three Kubernetes secrets:

A few details in the values:

  • soda.apikey.existingSecret and secretKeys name the secret and the keys that hold the API key ID and secret.

  • imageCredentials.create: false stops the chart from creating its own registry secret from the API key, and existingImagePullSecrets gives it the one that ESO maintains.

  • soda.scanLauncher.existingSecrets mounts each listed secret into every job the runner starts, including contract verifications, and tells the job to read the mounted files as environment variables.

  • soda.cloud.region is us or eu, the region of your Soda Cloud organization.

Install the runner:

Once the runner registers with Soda Cloud, it shows up in Settings > Runners, with a green dot under Last seen while it is online.

The Runners page with secrets-manager-guide, last seen less than a minute ago
The runner is online

For every value of the Helm chart, see Soda Runner: additional information.

Connect the data source

Add the data source in Soda Cloud on the new runner:

  1. Go to Data Sources, click New Data Source, and select PostgreSQL.

  2. Under Data Source Identifier, enter sales_postgres.

  3. Under Default Runner, in Default Scan Runner, select secrets-manager-guide.

    The Default Runner field, with secrets-manager-guide selected
    The data source runs on the self-hosted runner
  4. Under Connection Details, enter the host, port, and database. In User, enter ${env.POSTGRES_USER}, and in Password, enter ${env.POSTGRES_PASSWORD}.

  5. Click Test connection. When the test passes, click Connect and complete the remaining steps.

The Connection Details of sales_postgres, with the user and password set to environment variables
The connection refers to the credentials as environment variables

Soda Cloud stores only the variable names. The runner's jobs resolve them from the mounted secret. This is the data source configuration that Soda Cloud stores:

To create the data source with the REST API instead, send this configuration in configurationFileContents to POST /api/v1/datasources, with the runner's ID in runnerId. See the REST API reference.

After you connect the data source, onboard its datasets and verify contracts as with any other data source. Every scan runs on the runner with the credentials from Vault.

The Checks tab of fact_internet_sales, with every check of the contract passing
Contract results of fact_internet_sales, verified on the runner

For the onboarding steps, see Onboard datasets on Soda Cloud.

Rotate the password

To rotate the password, change it in the database:

Then update it in Vault. vault kv patch changes the password and keeps the user name:

At its next refresh, ESO writes the new password to the Kubernetes secret, and every job that the runner starts after that uses it. You don't redeploy or restart the runner. Until the refresh, jobs use the old password, so keep the refreshInterval of the ExternalSecret short enough for your rotation.

Next steps

Last updated

Was this helpful?