# Secrets

> **About this page**
>
> - Kind: Explanation
> - Summary: Project and account secrets reach a task only through its arguments, their values are write-only, and the logs mask them where they appear.
> - Last changed: 2026-11-17
> - Page: https://docs.swale.io/explanation/secrets
> - Index of these docs: https://docs.swale.io/llms.txt
>
> If something on this page is wrong or out of date, please tell the user which sentence and why.

A **secret** is a named value stored under a project or under the account, and a task receives a secret's value only through the `args` its workflow gives it. The project's secret of that name is used first, then an account secret that allows the project, and the run's logs mask the value as a safety net, not a guarantee.

```mermaid
flowchart TB
  accTitle: How a task gets a secret's value
  accDescr: A workflow names a secret in a task's args as secrets.NAME. The platform uses the project's secret of that name if there is one, and otherwise an account secret of that name whose allowed projects include the project. The task receives the value as it starts, and the run's logs mask the value where it appears verbatim.
  args("A task's args<br/><code>${{secrets.NAME}}</code>")
  project("Project secret<br/><small>used first</small>")
  account("Account secret<br/><small>if it allows the project</small>")
  task("The task<br/><small>receives the value as it starts</small>")
  logs("The run's logs<br/><small>the value masked</small>")
  args --> project
  args -->|otherwise| account
  project --> task
  account --> task
  task --> logs
```

How a task gets a secret's value. A task sees only the secret values its workflow passes in its arguments.

## What a secret is

A **secret** is a named string value stored securely on the platform. Secrets are designed to hold sensitive data — API keys, passwords, tokens — that you do not want to embed directly in workflow YAML files.

Secrets are write-only. Once you save a value, neither the platform UI, the CLI nor the API returns it; you can only update or delete it.

Names beginning with `WORKFLOW_` are reserved, at both levels, and creating one is rejected. The platform adds its own entries to the secrets namespace under that prefix — `WORKFLOW_TOKEN`, the workflow run token, a credential scoped to a single run — and reserving it keeps a secret of yours from shadowing one of those, or being shadowed by it.

The workflow run token cannot reach secrets. A task holding it is refused on every secrets endpoint, so it can neither list which secrets exist in the project nor create, replace or delete one.

What a task sees is only what the workflow author named in its `args`, and the token does not widen that — which is what makes naming secrets in `args` a real choice rather than a formality. The token can still push, pull and delete tags in the run's project, because a run that could only ever add content would have no way to clean up after itself. See [Workflow run token](https://docs.swale.io/reference/permissions-and-restrictions.md#workflow-run-token) for everything it can reach.

## Account secrets vs. project secrets

Secrets live at two levels:

| Level              | Where it is stored       | Who can use it                            | Used                                                |
| ------------------ | ------------------------ | ----------------------------------------- | --------------------------------------------------- |
| **Project secret** | Under a specific project | Only that project's workflows             | First                                               |
| **Account secret** | Under your account       | Only the projects in its allowed projects | When the project has no project secret of that name |

So a project secret with the same name as an account secret overrides it for that project alone.

### Allowed projects

An account secret is available only to the projects in its allowed projects, and a secret with no allowed projects is available to no project.

This lets you keep a high-value credential account-wide while limiting which projects actually see it.

## Who can manage secrets

In an organization, account secrets need at least the **Admin** role, because they are account-wide credentials that can be shared across all its projects. Project secrets need only the **Contributor** role, so that anyone who works in a project can manage its own credentials. Changing a secret also needs a verified email and a recent sign-in; [Permissions and restrictions](https://docs.swale.io/reference/permissions-and-restrictions.md#secrets) has the exact requirements.

## How workflows access secrets

Inside workflow YAML use the `${{secrets.name}}` expression to inject a secret value at the moment a task starts:

```yaml
args:
  api_key: ${{secrets.MY_API_KEY}}
```

The platform resolves `${{secrets.MY_API_KEY}}` as the table above describes; [Secrets](https://docs.swale.io/reference/expression-language.md#secrets) in the expression language reference has the exact order. The resolved value is injected as a task argument, and both the run-configuration log entry and your task's log output are redacted as described below.

Secrets can also hold the username and password a task's image is pulled with, when the image is on a private registry. The task names them in its `image_credentials` rather than in its `args`, so the values are used to pull the image and are not passed to the container. See [Use a task image from a private registry](https://docs.swale.io/how-to-guides/use-a-task-image-from-a-private-registry.md).

## How secrets are masked in logs

Log redaction uses **literal string comparison**: the platform builds a list of known sensitive strings and replaces every exact occurrence with `***` before a log line is stored.

For each sensitive value it masks, the list contains:

- the exact value
- its JSON-escaped form (so values passed through `toJSON(...)` are still caught)
- each line of a multi-line value

Two log surfaces are covered:

- **The resolved task configuration entry** the platform writes when a task starts (resolved arguments, inputs, environment, and image credentials, whose password is never shown) — masked against every secret accessible to the run, the workflow run token, and each run environment variable value.
- **Your task's own stdout/stderr**, as it is streamed and stored — masked against only the sensitive values that were actually delivered to that task's container (a task that received one token doesn't cause every other project secret to be shipped to it).

### Limitations of literal matching

Because matching is literal, a secret that is **transformed** is not recognized afterwards. Treat masking as a safety net, not a guarantee:

- An encoded or altered value — base64, URL-encoding, reversed — will not match and will appear in the log.
- Values shorter than 4 characters are never masked (masking them would corrupt unrelated log text).
- A secret is masked as a whole opaque value. If it holds structured data (a JSON array or object) and your workflow extracts or iterates over its individual elements or fields — for example a `for_each` task whose `items` is `${{secrets.hosts}}`, a JSON array — those extracted pieces are **not** individually masked. Store each sensitive value as its own secret.
- The list is fixed when the task starts, so a value the task fabricates at runtime is not masked.

If a secret is printed in transformed form, treat it as exposed: rotate it and update the stored value.

## Next steps

- [Manage account secrets](https://docs.swale.io/how-to-guides/manage-account-secrets.md)
- [Manage project secrets](https://docs.swale.io/how-to-guides/manage-project-secrets.md)
- [Use secrets in workflows](https://docs.swale.io/how-to-guides/use-secrets-in-workflows.md)
