Create and manage secrets
Note
Secrets management is currently in public preview. Grafana Labs offers limited support, and breaking changes might occur prior to the feature being made generally available.
Secrets management provides a centralized location to securely store and manage values such as API keys, passwords, tokens, and credentials. Synthetic Monitoring tests reference secrets in a way that prevents them from being exposed in the UI, scripts, and logs generated by Synthetic Monitoring.
With secrets management, you can:
- Create secrets and attach metadata to secrets, such as description and labels.
- Reference secrets by name in k6 scripted and k6 browser synthetics.
- Reset and revoke secret values.
Secrets are encrypted at rest using envelope encryption. Grafana Cloud stores the secrets’ metadata in one location while simultaneously encrypting and storing secret values in a different location. Secret values can only be decrypted by Synthetic Monitoring by using references to the metadata, not the encrypted value itself. This ensures that secrets are never stored permanently and are only available in memory during active use.
Before you begin
- Users with the Grafana Admin role can create, edit, and delete secrets by default.
- Users with the Grafana Editor and Viewer roles can be granted access to create, edit, and delete secrets using a fixed role. Refer to the Role-based access control section for more details.
- Only users with the Admin or Editor role, or the Checks writer permission, can use secrets when editing tests. Refer to Manage users and teams for Synthetic Monitoring for more details.
- Secrets are only supported in k6 scripted and k6 browser synthetics.
- Only text-based secrets, such as passwords and certificates, are supported. Secrets have a limit of 24kB.
- Secret names must be 253 characters or less.
- Secret descriptions must be 253 characters or less.
- Secrets can have a maximum of 10 labels.
- Label keys must be 63 characters or less.
Create a secret
To create a new secret:
- Navigate to Home > Testing & synthetics > Synthetics > Config
- Click the Secrets tab.
- Click Create secret.
- In the Create secret dialog box, fill in the following fields:
- Name: A unique name for your secret. Use a descriptive name, such as
api-key-production
. Can contain letters, numbers, hyphens, and underscores. - Description: An optional description explaining the secret’s purpose.
- Value: The secure value to be encrypted. This field is masked for security.
- Name: A unique name for your secret. Use a descriptive name, such as
- Click Save to create the secret.
Edit a secret
To edit a secret:
- Navigate to Home > Testing & synthetics > Synthetics > Config.
- Click the Secrets tab.
- Find the name of the secret you want to edit and click the Edit button next to it.
- Update the fields you want to change. To update the Value field, click Reset first, and then update the secret’s value.
- Click Save.
Delete a secret
To delete a secret:
- Navigate to Home > Testing & synthetics > Synthetics > Config
- Click the Secrets tab.
- Find the name of the secret you want to delete and click the trash icon next to it.
- In the confirmation dialog box, type “Delete”.
- Click Delete.
Warning
Deleting a secret is permanent and can’t be undone. Any Synthetic Monitoring tests using a deleted secret will fail until you update them with a new secret, or a secret with the same name as the deleted secret is created.
Use secrets in a test
To use secrets in a test:
- Navigate to Home > Testing & synthetics > Synthetics > Checks.
- Click “Add new check”.
- Select the “Scripted” or “Browser” check type.
- In your script:
- Import the
k6/secrets
module:import secrets from 'k6/secrets';
- Retrieve the secret value by using its name:
const secret_value = await secrets.get('test-secret-name');
- Import the
- Use the secret value variable in your script.
Here is an example of a minimal k6 scripted test that fetches a secret value and tries to log it:
import secrets from 'k6/secrets';
export default async function main() {
const secret_value = await secrets.get('test-secret-name');
// Try logging the secret -- the value is redacted
console.log(`try to log the secret value: ${secret_value}`);
}
Refer to the k6/secrets documentation for more details on the secrets module.
Secret redaction
Secret values are masked in the Synthetic Monitoring output with the ***SECRET_REDACTED***
placeholder.
For example, the following script snippet:
const result = http.post('https://my-endpoint.test.app', '', { headers: { Authorization: `Bearer ${secret_value}` } });
Produces a header in the form of:
Authorization: Bearer xm_MCp5aalOF2BGlafChR8Gu5hv
But that same line appears in the logs as:
Authorization: Bearer ***SECRET_REDACTED***
Role-based access control
The ability to create, edit, and delete secrets is defined by the Grafana role assigned to a user:
- Admins can create, edit, and delete secrets by default.
- Only users with the Admin or Editor role, or the Checks writer permission, can use secrets when editing tests.
You can use Role-based access control to give users, whether they’re Admins, Editors, or Viewers, granular access to secrets. The following roles are available:
Role | Description |
---|---|
Secure Values Reader | Read and list secure values |
Secure Values Creator | Create secure values |
Secure Values Updater | Update secure values |
Secure Values Deleter | Delete secure values |
To assign a role to a user:
- Navigate to Home > Administration > Users and access > Users.
- Assign a fixed role from Fixed roles > Secret manager.
When assigning secret manager roles to users, ensure these users have been granted appropriate access to Synthetic Monitoring. For example, a user with the Grafana Viewer role and the Secure Values Creator role has the ability to create secrets, but they also need the Checks writer role to gain access to the Synthetic checks interface containing the secrets configuration.
Refer to Synthetic Monitoring RBAC roles for more details about the available roles.