Introducing a new way to review your PRs.

Read the announcement

keephq / keep

The open-source AIOps and alert management platform

View on GitHub

22 documents · Updated Nov 23, 2026

docs / secret-management

Secret management

Secret management gives Keep one way to store, read, update, and delete sensitive values while allowing each deployment to choose its storage system. The same contract can resolve secrets from local files, the Keep database, AWS Secrets Manager, Google Cloud Secret Manager, Kubernetes Secrets, or HashiCorp Vault. It supports provider setup, workflow execution, tenant keys, and other features that must use sensitive values without depending on one storage platform.

Secret manager abstraction

The secret manager abstraction is the common boundary between Keep features and secret storage. A caller supplies a secret name and receives either its text value or a parsed JSON object. The caller can also write or delete that named value without knowing which backend serves it. References: keep/…/secretmanager.py• L7-47

JSON handling belongs to the read contract rather than to a separate secret type. A caller sets is_json=True when a stored value represents an object. The selected backend then parses the text and raises an error when the value is not valid JSON. References: keep/…/secretmanager.py• L12-23, keep/…/awssecretmanager.py• L144-197, keep/…/gcpsecretmanager.py• L72-85

Backend selection

The secret manager factory selects a backend at the point where a feature needs secret access. A caller may pass a type directly. When it does not, the factory reads SECRET_MANAGER_TYPE and uses FILE when the setting is absent. References: keep/…/secretmanagerfactory.py• L8-31

The supported backend types define the deployment choices:

TypeStorage systemMain deployment fit
fileFiles in a local directoryLocal or simple deployments
dbKeep's databaseCentral storage in the application database
awsAWS Secrets ManagerAWS-hosted deployments
gcpGoogle Cloud Secret ManagerGoogle Cloud deployments
k8sKubernetes Secret objectsIn-cluster deployments
vaultHashiCorp Vault KV v2Vault-managed deployments

The factory returns the selected backend through the shared contract. An unknown type stops selection with a not-implemented error, so deployment settings must match one of the supported values. References: keep/…/secretmanagerfactory.py• L17-57

Secret storage backends

Each backend maps the common name and value to a different storage system. The mapping changes the required platform access and lifecycle behavior, but it does not change how Keep features request a secret.

File storage

File storage treats each secret name as a file below SECRET_MANAGER_DIRECTORY. It reads and writes the file content as text, parses it as JSON when requested, and removes the file on delete. The directory defaults to the current directory. References: keep/…/filesecretmanager.py• L7-36

Database storage

Database storage keeps one secret per key in the secret table. A write creates the key or replaces its value and records the update time. A missing key causes a read error, while deleting a missing key has no effect. References: keep/…/dbsecretmanager.py• L11-86, keep/…/secret.py• L5-11

AWS storage

AWS storage uses AWS Secrets Manager as the source of truth. A write updates an existing secret or creates one with optional KMS and tag settings. New secrets can receive an automatic rotation policy when rotation is enabled and a rotation Lambda is configured. Delete uses immediate removal without recovery. References: keep/…/awssecretmanager.py• L13-16, keep/…/awssecretmanager.py• L46-142, keep/…/awssecretmanager.py• L199-235

Google Cloud storage

Google Cloud storage places secrets in the project named by GOOGLE_CLOUD_PROJECT. A write creates the secret when needed and adds a new version. Reads use the latest version, while delete removes the project secret. References: keep/…/gcpsecretmanager.py• L13-17, keep/…/gcpsecretmanager.py• L19-91

Kubernetes storage

Kubernetes storage maps each secret to a Kubernetes Secret in K8S_NAMESPACE, which defaults to default. Keep stores the value under the value data key and converts names to lower-case Kubernetes names by replacing underscores with hyphens. The manager expects in-cluster Kubernetes access and can be configured to skip certificate checks through K8S_VERIFY_SSL_CERT. References: keep/…/kubernetessecretmanager.py• L15-53, keep/…/kubernetessecretmanager.py• L55-140

Vault storage

Vault storage uses the KV version 2 engine and keeps the application value under the value field at the requested path. The manager authenticates with HASHICORP_VAULT_TOKEN or with a Kubernetes service-account token and a configured Vault Kubernetes role. It removes all metadata and versions when a secret is deleted. References: keep/…/vaultsecretmanager.py• L12-44, keep/…/vaultsecretmanager.py• L46-75

Secret resolution flows

Secret resolution starts with a feature-specific name and ends with a value in the feature's context. The factory hides backend choice, so provider setup, tenant utilities, and workflows use the same flow. The broader access rules are described in authentication and authorization, while provider configuration is described in provider configuration and provisioning.

This diagram shows how a request moves from a Keep feature through backend selection to a stored value.

flowchart LR
    A[Keep feature] --> B[Secret name]
    B --> C[SecretManagerFactory]
    C --> D[Selected backend]
    D --> E[Stored secret]
    E --> F[Text or JSON value]

Workflow secrets use one backend record for each tenant and workflow. The record contains a JSON object. A write merges new keys into that object, a read returns the object or raw value, and a delete removes one key before writing the object back. Missing or unreadable workflow secrets resolve as an empty object in the workflow context and read route. References: keep/…/contextmanager.py• L131-149, keep/…/workflows.py• L1218-1247, keep/…/workflows.py• L1250-1315

Provider credential lifecycle

Provider setup uses the same secret boundary as workflow and tenant features. A provider can return secret material from webhook setup or OAuth handling for storage, and later provider loading reads the stored provider configuration before the provider instance is used. The base provider contract keeps these flows separate from the provider's normal alert, query, and event work. References: keep/…/base_provider.py• L689-740, keep/…/providers_service.py• L371-419

Provider configuration follows the same abstraction but uses provider-specific secret names. Keep reads the stored JSON before it creates or validates the provider instance. Provider authentication can include sensitive values, such as the Zabbix auth token, which must remain outside normal provider configuration handling. References: keep/…/providers_service.py• L371-398, keep/…/providers_service.py• L411-419, keep/…/zabbix_provider.py• L27-57

Tenant key resolution

Tenant API keys also resolve through the selected manager. Their secret name combines the tenant and key reference. Deactivated keys are reported without reading their stored value, and a configured read-only bypass key is not returned. References: keep/…/tenant_utils.py• L215-254

Access and lifecycle boundaries

Secret storage is separate from access control. Workflow secret routes require the read:secrets scope for reads and the write:secrets scope for writes and deletes. The route also checks that the workflow belongs to the authenticated tenant before it reaches the manager. References: keep/…/workflows.py• L1215-1228, keep/…/workflows.py• L1250-1273, keep/…/workflows.py• L1279-1304

The backend controls the lifetime of the stored value. This means a delete may be a local file removal, a database row removal, a cloud-provider deletion, a Kubernetes object deletion, or removal of all Vault versions. Callers should rely on the shared delete action, but operators must understand the selected backend's recovery and retention behavior. References: keep/…/filesecretmanager.py• L22-36, keep/…/dbsecretmanager.py• L39-86, keep/…/awssecretmanager.py• L199-235, keep/…/gcpsecretmanager.py• L87-91, keep/…/kubernetessecretmanager.py• L125-140, keep/…/vaultsecretmanager.py• L70-75

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the SecretManagerTypes values aligned with deployment settings and with every backend returned by the factory.
  • Preserve the stored shape expected by callers: provider values are JSON objects and workflow values are merged JSON objects under one tenant-workflow name.
  • Review name normalization when changing Kubernetes storage because underscores and case do not map to Kubernetes names unchanged.
  • Review delete semantics when changing a cloud or Vault backend because callers may assume that a deleted value cannot be recovered.
  • Keep backend authentication settings aligned with the runtime platform. In particular, Kubernetes and Vault Kubernetes login require in-cluster service-account access.
  • Preserve the JSON parse contract when changing a backend. A caller that requests JSON must receive an object or a clear parse failure.
  • Keep provider setup and OAuth secret outputs aligned with the provider service's storage and later provider-loading paths.

Important failure modes

TriggerConsequenceGuard
SECRET_MANAGER_TYPE names an unsupported backendFactory creation fails before the feature can read or write a secretUse one of file, db, aws, gcp, k8s, or vault
A JSON secret contains invalid JSONThe read fails instead of returning a partial valueStore valid JSON for provider and workflow records when callers request JSON
The selected backend cannot authenticate or connectSecret operations raise the backend errorProvide the platform credentials and runtime access required by the selected backend
A Kubernetes name contains unsupported form before normalizationReads and writes can target a different object than the caller expectsTreat underscores as hyphens and use lower-case names for Kubernetes secrets
A workflow secret is missing or cannot be read during context setupWorkflow context uses an empty secret objectCheck backend availability and the tenant-workflow secret name
AWS rotation is enabled without a rotation Lambda ARNA new secret is created without the requested rotation policyConfigure both rotation enablement and the rotation Lambda ARN
Provider setup or OAuth returns secret data but the provider storage path does not save itLater provider loading cannot authenticate or cannot find the provider configurationKeep provider secret output and provider service persistence aligned

Key files

FileWhy to read it
keep/…/secretmanager.pyDefines the shared read, write, and delete boundary.
keep/…/secretmanagerfactory.pyShows how deployment choice maps to a backend.
keep/…/contextmanager.pyShows how workflow execution loads secrets into its context.
keep/…/workflows.pyShows the workflow secret API and its tenant and scope checks.
keep/…/base_provider.pyDefines how provider setup and OAuth flows can return secret material.
keep/…/providers_service.pyShows how provider configuration is resolved before provider use.
keep/…/zabbix_provider.pyIllustrates a provider authentication contract that marks its auth token as sensitive.
keep/…/tenant_utils.pyShows how tenant API key values are resolved and filtered.
keep/…/filesecretmanager.pyIllustrates the simplest local storage behavior.
keep/…/dbsecretmanager.pyShows database-backed secret lifecycle and missing-key behavior.
keep/…/awssecretmanager.pyShows AWS storage, tags, KMS support, and rotation setup.
keep/…/gcpsecretmanager.pyShows project-scoped Google Cloud storage and latest-version reads.
keep/…/kubernetessecretmanager.pyShows Kubernetes namespace, naming, and in-cluster access behavior.
keep/…/vaultsecretmanager.pyShows Vault KV storage and token or Kubernetes authentication.
keep/…/secret.pyDefines the database record used by the database backend.