dbt · Macros, Packages & Advanced

Secrets with env_var

Mediumenv_varsecretssecurityprofiles

Interview question

How should you handle secrets in dbt (env_var)?

How to answer

The short answer

Don't commit passwords, tokens, or private keys in git. Use `env_var` (and your secret manager / CI variables) so credentials are injected at runtime.

In profiles.yml

YAML
password: "{{ env_var('DBT_PASSWORD') }}"
user: "{{ env_var('DBT_USER') }}"

Optional default for non-secrets only:

YAML
schema: "{{ env_var('DBT_SCHEMA', 'dbt_dev') }}"

In project code

SQL
-- rare: API-related configs, never hardcode tokens
{{ config(snowflake_warehouse=env_var('DBT_WAREHOUSE')) }}

Prefer env for connection/profile concerns; keep models free of secrets entirely.

Mental model

Output
Secret store / CI vars / local shell env
        |
   env_var('NAME')
        |
 profiles.yml / rare configs
        |
   warehouse auth

Practices

  • Different credentials for dev vs prod targets
  • Rotate credentials without editing SQL
  • Fail loudly if a required env var is missing (no silent empty password)

Interview tip: "dbt_project.yml is code; secrets are environment. env_var is the bridge."