Prerequisites
Prerequisites
- A Checkly Monitoring as Code project using a current version of the Checkly CLI.
- A secrets manager that your CI/CD workload can authenticate to.
- Permission to deploy the checks and groups that will use the secrets.
- Runtime
2024.09or later. Private Locations require agent3.3.4or later.
Understand the names in these examples
How the deployment works
The secret value exists in the deployment process long enough for the Checkly CLI to synthesize and deploy the construct. Checkly then encrypts it and stores it at the configured group or check scope.Choose the narrowest scope
Checkly merges variables when a check runs. Check-level values override group-level values, which override account-level values.
Each check or group can define up to 100 environment variables. If one deployment project spans many teams or systems, consider splitting it into independently deployed projects so each deployment identity can access only its own secrets.
Read secrets during deployment
Thesecret() helper reads CHECKLY_SECRET_<NAME> from the environment and stops with an error when the value is missing. For example, secret('PAYMENTS_API_KEY') reads CHECKLY_SECRET_PAYMENTS_API_KEY.
secrets.ts
CHECKLY_SECRET_* names expected by the project when you fetch the values in CI/CD.
Every CLI command that loads these constructs needs the corresponding environment values, including checkly test and checkly deploy. Never provide production secrets to pull request workflows that run untrusted code.
Deploy a group-level secret
__checks__/payments-group.check.ts
{{PAYMENTS_API_KEY}} is resolved by Checkly when the API check runs. It does not read a secret from your CI/CD provider or external secrets manager.
Deploy a check-level secret
Define a secret directly on the check when no other check needs it:__checks__/payments-admin.check.ts
process.env.PAYMENTS_ADMIN_TOKEN instead.
Treat the deployment as authoritative
For checks and groups managed by a Checkly CLI project, the construct is the desired state:- Changing a declared secret manually in the Checkly UI is reverted by the next deployment.
- Adding an undeclared group- or check-level secret in the UI removes it on the next deployment.
- Removing a declared secret in the UI recreates it on the next deployment.
Secure the deployment job
- Prefer workload identity federation or OIDC over long-lived cloud credentials.
- Grant the deployment identity read access only to the secrets required by that project.
- Fetch secrets only in trusted deployment workflows. Do not expose production secrets to workflows triggered from forks or untrusted pull requests.
- Avoid printing command output that contains secret values. Mask dynamically retrieved values according to your CI/CD provider’s guidance.
- Expose secrets only to the step that runs
npx checkly deploywhere your workflow system allows it. - Split large projects along team or service ownership boundaries to reduce the number of secrets available to one deployment process.