> For the complete documentation index, see [llms.txt](https://docs.lenses.io/latest/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.lenses.io/latest/k2k/configuration-reference/secrets-and-templates.md).

# Secrets and templates

Inject secrets and environment values at runtime.

Pipeline files need bootstrap servers, SASL credentials, and license tokens, but those values should not live in source control. Because K2K reads configuration at startup, we can resolve secrets from the environment before the YAML is parsed.

K2K evaluates `${...}` template expressions at startup. Load secrets from environment variables or files, and layer a `secrets_overrides.yml` over a base pipeline so the structure stays the same across environments. See [Loading pipeline files](https://docs.lenses.io/latest/k2k/minimal-configuration.md#loading-pipeline-files). To include a literal `${` in a value, write `$${` — it renders as `${` without being resolved.

## Prerequisites

* Pipeline files that reference template variables
* Secrets available as environment variables or files at deploy time

## Example

```yaml
name: "my_pipeline"
license:
  acceptEula: true
  token: "${env:K2K_LICENSE_TOKEN}"
source:
  kafka:
    common:
      "bootstrap.servers": "${env:KAFKA_SOURCE_BOOTSTRAP}"
      "sasl.jaas.config": "${file:raw:/secrets/jaas.conf}"
    consumer:
      "group.id": "my-k2k-group"
target:
  kafka:
    common:
      "bootstrap.servers": "${env:KAFKA_TARGET_BOOTSTRAP}"
replication:
  - source:
      topic: "orders.*"
  - sink:
      topic: source
      partition: source
```

Start with multiple files so secrets override the base definition:

```shell
k2k start -f base_pipeline.yml -f secrets_overrides.yml
```

The template engine is enabled by default. Disable it with `-g disabled` or `--template-engine disabled`. The flag accepts only `enabled` or `disabled`.

## Variable syntax

Variables use the form `${loader:mapper:name}`. Shorthand forms:

| Form             | Meaning                                      |
| ---------------- | -------------------------------------------- |
| `${name}`        | Environment variable (same as `${env:name}`) |
| `${mapper:name}` | Environment variable with mapper applied     |
| `${loader:name}` | Value loaded by loader                       |

Mappers can be chained: `${env:raw:base64:MY_SECRET}` or `${file:raw:/path/to/secret}`.

## Loaders

| Loader | Description                       |
| ------ | --------------------------------- |
| `env`  | Read from an environment variable |
| `file` | Read from a file path             |

## Mappers

| Mapper   | Description                                               |
| -------- | --------------------------------------------------------- |
| `string` | Escape and wrap value in double quotes (for YAML strings) |
| `raw`    | Use value as is, no escaping                              |
| `base64` | Base64 decode, then escape and wrap in double quotes      |
| `number` | Use value as a numeric literal                            |

## Examples

**Environment variable**

Pipeline:

```yaml
"bootstrap.servers": "${env:KAFKA_BOOTSTRAP}"
```

Environment:

```shell
export KAFKA_BOOTSTRAP="kafka.example.com:9092"
```

Rendered value:

```yaml
"bootstrap.servers": "kafka.example.com:9092"
```

**File loader**

Pipeline:

```yaml
"sasl.jaas.config": "${file:raw:/secrets/jaas.conf}"
```

File `/secrets/jaas.conf`:

```
org.apache.kafka.common.security.plain.PlainLoginModule required username="user" password="secret";
```

Rendered value (inserted as is):

```yaml
"sasl.jaas.config": org.apache.kafka.common.security.plain.PlainLoginModule required username="user" password="secret";
```

**String mapper**

Pipeline:

```yaml
"schema.registry.basic.auth.user.info": "${env:string:SR_CREDENTIALS}"
```

Environment:

```shell
export SR_CREDENTIALS='user:password'
```

Rendered value:

```yaml
"schema.registry.basic.auth.user.info": "user:password"
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.lenses.io/latest/k2k/configuration-reference/secrets-and-templates.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
