Files
infisical/docs/documentation/platform/secret-reference.mdx
2023-07-12 01:23:28 -04:00

38 lines
2.3 KiB
Plaintext

---
title: "Reference Secrets"
description: "How to use reference secrets in Infisical"
---
Secret referencing is a powerful feature that allows you to create a secret whose value is linked to one or more other secrets.
This is useful when you need to use a single secret's value across multiple other secrets.
Consider a scenario where you have a database password. In order to utilize this password, you may need to incorporate it into a database connection string.
With secret referencing, you can easily construct these more intricate secrets by directly referencing the base secret.
This centralizes the management of your base secret, as any updates made to it will automatically propagate to all the secrets that depend on it.
## Referencing syntax
<img src="../../images/example-secret-referencing.png" />
Secret referencing relies on interpolation syntax. This syntax allows you to reference a secret in any environment or [folder](./folder).
To reference a secret named 'mysecret' in the same [folder](./folder) and environment, you'd use `${mysecret}`.
However, to reference the same secret at the root of a different environment, for instance `dev` environment, you'd use `${dev.mysecret}`.
Here are a few more examples to help you understand how to reference secrets in different contexts:
| Reference syntax | Environment | Folder | Secret Key |
| --------------------- | ----------- | ------------ | ---------- |
| `${KEY1}` | same env | same folder | KEY1 |
| `${dev.KEY2}` | `dev` | `/` (root of dev environment) | KEY2 |
| `${prod.frontend.KEY2}` | `prod` | `/frontend` | KEY2 |
## Fetching fully constructed values
Secret referencing combines multiple secrets into one unified value, reconstructed only on the client side. To retrieve this value, you need access to read the environment and [folder](./folder) from where the secrets originate.
For instance, to access a secret 'A' composed of secrets 'B' and 'C' from different environments, you must have read access to both.
When using [service tokens](./token) to fetch referenced secrets, ensure the service token has read access to all referenced environments and folders.
Without proper permissions, the final secret value may be incomplete.