> Index of every page on this site: [llms.txt](https://docs.a-line.cloud/llms.txt)

# Store secrets

> Keep API keys and passwords out of your code and hand them to apps as variables or files.

**Goal**: a secret, such as a payment provider's API key, stored once and
given to one or more apps as an environment variable or a file.

## Before you start

- An [environment](/concepts/organizations#environments) with at least one
  app that needs the secret.
- The secret value, or a plan to let A-Line.cloud generate one.

## Create a secret

<InterfaceTabs items={['Console', 'IaC', 'API', 'MCP']}>
<InterfaceTab value="Console">

<Steps>
<Step>

Open **Secrets** in the sidebar. The **Managed Secrets** tab lists the
secrets of the environment.

</Step>
<Step>

Select **Create secret**. The **Create Environment Secret** dialog opens.

</Step>
<Step>

Enter a **Key**, such as `STRIPE_API_KEY`, and an optional
**Description**.

</Step>
<Step>

Paste the **Value**, or turn on **Generate a random value** for a
password the app creates its own account with.

</Step>
<Step>

Turn on **Write-only** if nobody should read the value back after you
save it. Apps still get it.

</Step>
<Step>

Pick the **Injection Mode**: **Env Var**, **File Mount** or **Both**. For
a file, set the **Mount Path**.

</Step>
<Step>

Select **Create Secret**.

</Step>
</Steps>

</InterfaceTab>
<InterfaceTab value="IaC">

IaC files hold the keys, never the values. Declare the key in a
[secret group](/iac/secrets#groups), then set its value in the console or
through the API:

```yaml title="secrets/payments.yaml" iac tree=secrets-guide
# yaml-language-server: $schema=https://a-line.cloud/schemas/iac/v1.json
version: 1
environment: production
description: Payment provider keys
keys:
  STRIPE_API_KEY: {write_only: true}
```

</InterfaceTab>
<InterfaceTab value="API">

Create the secret in the environment. The value is write-only in the API:
it is never returned.

```http api
POST /v1/environments/{environment_id}/secrets
Authorization: Bearer $ALC_API_KEY
Content-Type: application/json

{ "name": "STRIPE_API_KEY", "value": "sk_test_example", "injection_mode": "env", "write_only": true }
```

See [Secrets](/api/reference/secrets) for setting a new value later.

</InterfaceTab>
<InterfaceTab value="MCP">

Ask your connected client to create the secret, for example: "Create the
secret STRIPE_API_KEY in production." Its `set_secret` tool creates it and
refuses a name that already exists, so a retry never overwrites a value.
Paste values only into clients you trust with them. See
[Connect an AI client](/mcp).

</InterfaceTab>
</InterfaceTabs>

## Give it to an app

<Steps>
<Step>

Open the app on the project canvas and go to its **Env Vars** tab.

</Step>
<Step>

Select **Add from Secrets** and pick the secret.

</Step>
<Step>

Deploy the app. The new value is used from the next deploy.

</Step>
</Steps>

## Share secrets with a group

A **secret group** bundles secrets that belong together, such as all
credentials of one service, and links them to several apps at once.

<Steps>
<Step>

On the **Secret Groups** tab, select **New group**, enter a name and
select **Create group**.

</Step>
<Step>

In the group, select **Add existing** to add secrets.

</Step>
<Step>

Select **Link an app...** to give every secret in the group to an app.

</Step>
</Steps>

Changes to a group show **Restarts on next deploy** for the apps that use
it: they get the new values on their next deploy.

## Verify

- The secret is listed on the **Managed Secrets** tab. Open it to see its
  versions and the apps that use it.
- After a deploy, the app's **Logs** show it starting without a missing
  variable error.

## Troubleshooting

- **The app still has the old value**: values are read when a pod starts.
  Deploy the app again.
- **The secret is not offered in Add from Secrets**: secrets belong to one
  environment. Check that the app runs in the same environment.
- **You cannot see the value**: the secret is **Write-only**. Set a new
  value instead.

## Database credentials

Do not store database passwords as secrets. Use a definition instead: each
pod then gets its own short-lived login. See
[Add a database and connect an app](/guides/managed-database). Short-lived
credentials are listed on the **Dynamic Leases** tab.

## In IaC

A secret group is a file `secrets/<group>.yaml` that lists the keys, never
the values. Apps name the groups they use under `secrets`. See
[Secrets in IaC](/iac/secrets) and [using a group](/iac/secrets#using).

## Next steps

- [Secrets in IaC](/iac/secrets): generated and derived values, versions.
- [Add a database and connect an app](/guides/managed-database)
- [Permissions in IaC](/iac/permissions): who can read and change secrets.
