---
title: Sensitive environment variables
slug: hosty/sensitive-environment-variables
createdAt: 2026-11-08T11:27:49.007Z
---

Keep secrets, such as API keys and tokens, out of the repository. Hosty has no web interface for them. Instead, your [CI](https://wiki.systemseed.com/hosty/cicd-configuration) keeps the secrets, writes them into a file during the build, and Hosty CLI reads the file.

## 1. Add the secrets to your CI

Add each secret as an environment variable of the project in your CI. In CircleCI, it's **Project Settings > Environment Variables**, or a context shared by several projects.

![Environment variables of a project in CircleCI](https://api.archbee.com/api/optimize/J5fagZai1i-rRUBgkgJC3/81ZhI7mDEqJZcEd_plXfG_circleci-environment-variables.png)

## 2. Write them into a file in CI

Before Hosty CLI builds the images, write the secrets into a file in the root of the project, one `NAME=value` per line:

```yaml
- run:
    name: Write the secrets into .env.secrets
    command: |
      printf '%s=%s\n' \
        FORECAST_API_KEY "$FORECAST_API_KEY" \
        HARVEST_API_KEY "$HARVEST_API_KEY" \
        > .env.secrets
```

`printf` writes the values exactly as they are, whatever characters they have.

Add the file to `.gitignore`, so that nobody commits it by mistake. You don't need a placeholder of the file in the repository: only the `build` and `deploy` commands need it, and they stop with an error when it's missing.

## 3. Load the file in hosty.yaml

List the file in `environmentFiles` of the container that needs the secrets:

```yaml
applications:
  backend:
    php:
      environmentVariables:
        APP_MODE: development
      environmentFiles:
        - ./.env.secrets
```

The path is relative to the root of the project. A variable in the file wins over the same variable in `environmentVariables`.

## How the file is read

Hosty CLI takes the values literally:

- Each line is `NAME=value`, optionally after `export `.
- Empty lines and lines starting with `#` are skipped.
- Quotes around the whole value are removed. Nothing else is changed: `$NAME` isn't expanded and commands aren't run, so a value like `$2y$10$...` stays as it is.
- A value can't have a line break. Encode a multi-line value, such as a private key, with base64, and decode it in the application.
- Tokens such as `{{ backend.host.0 }}` don't work in the file.

## Different secrets per environment

Write a separate file for production, and load it in an override. Lists in overrides replace the list of the application:

```yaml
applications:
  backend:
    php:
      environmentFiles:
        - ./.env.secrets
    overrides:
      - condition:
          environments: [production]
        php:
          environmentFiles:
            - ./.env.production
```

Hosty CLI needs only the files of the environment it builds: here `.env.production` for production and `.env.secrets` for the rest.

## Where the secrets end up

The variables are built into the images of the application, which are kept in the private image repository of the project in AWS. A changed secret builds a new image on the next deployment. Anyone who can run commands in the environment can read the variables, i.e. with `hosty exec <environment> --command env`, so give access to production only to those who need it (see [Roles and permissions](https://wiki.systemseed.com/hosty/roles-and-permissions)).
