Why credentials in prometheus.yml cause trouble and how to keep them out
This section explains why passwords, bearer tokens and webhook keys inside Prometheus and Alertmanager configuration create risk, and where those secrets tend to travel. The page that follows covers the fixes: the _file variants of secret fields, how the API handles redaction, Alertmanager template pitfalls and Kubernetes secrets with the Operator. The typical starting point is a prometheus.yml that carries a basic_auth password or a bearer_token for an exporter, or an alertmanager.yml with a Slack or PagerDuty key in a receiver, and that file has been committed to Git, copied to several hosts for a second Prometheus, or included in a configuration backup. Each copy is another place the credential can be read, and rotating it means finding every one of them.
The secret-bearing fields sit in both files. In Prometheus, they include scrape job authentication blocks such as basic_auth, authorization and oauth2, remote write and remote read settings, and TLS key material. In Alertmanager, they include receiver integration keys, SMTP passwords and webhook URLs that act as credentials. Prometheus itself has no secrets manager, so the store is your choice: a vault, the platform's own secret objects, or files with tight ownership and permissions. Confirm which option your team already operates and who holds its access policy before choosing the mechanism. Also confirm that anyone who can read the configuration endpoint or the host filesystem can read the value you put there, because the file and the file's readers define your real exposure.
Teams usually need this work before a security review or compliance assessment, because reviewers ask where credentials are stored, who can read them and how they are rotated. A configuration that is clean today but has a history of committed passwords still produces findings, so check the repository history as well as the current files. Start with an inventory: list every secret field in each Prometheus and Alertmanager file, record where each copy exists, and note which secrets have never been rotated. That inventory becomes the scope for the migration and the evidence an assessor will request.
Which secret field pattern fits each part of the configuration
This table compares the four ways to supply passwords and tokens to Prometheus and Alertmanager: inline fields, _file variants, runtime environment injection and Kubernetes secrets with the Operator. Read each row for when the pattern fits and what it still leaves exposed, then confirm exact field names in the configuration references before you write any file.
| Pattern | Fits when | Protects against | Still exposed |
|---|---|---|---|
| Inline secret fields in prometheus.yml | Only for throwaway lab setups with no shared repository or backups | Nothing beyond what file permissions already give | Values sit in plain text in the config file, in version control, in backups and in anything that copies the file |
| _file variants that read a path on disk | Standalone hosts or VMs where you control the file system and a secret mount exists | Keeps the value out of the main configuration file and out of config diffs | File permissions, ownership and backup copies of the secret file, plus the rotation step, which usually needs a reload |
| Environment injection through the runtime | Containers or service managers that populate variables at start time | Keeps values out of files stored with the configuration | Variables are visible to anyone who can inspect the process or container spec, and changes need a restart |
| Kubernetes secrets with the Prometheus Operator | Clusters where the Operator manages Prometheus and Alertmanager resources | Keeps values in the cluster secret store, separate from generated configuration | Cluster RBAC scope, secret encryption at rest and who can read the namespace; confirm how your Operator version mounts secrets |
| Alertmanager receiver credentials | Any receiver that needs a webhook URL, API key or SMTP password | Limits exposure of routing and receiver settings if secret fields are kept separate | Templates can print values into notifications, so review every template that reads secret data |
| Rotation and reload process | Every pattern, since no secret stays valid forever | A documented rotation cuts the window in which a leaked value works | Missed reloads leave old values in use, and a failed reload can stop the service from starting; test rotation in staging |
Moving a scrape or receiver secret into a file
This sequence moves each password, token and key out of prometheus.yml and alertmanager.yml and into files that only the service can read. It ends with proof that targets and receivers still authenticate and that a rotated secret loads after a reload.
Inventory every secret field in both files
The engineer who owns the monitoring configuration searches prometheus.yml and alertmanager.yml for password, bearer token, API key, credentials and client secret fields. Check scrape jobs, remote write and read blocks, and every receiver definition. Record each field, the job or receiver it belongs to, and the system it authenticates against. Done when the list covers every job and receiver and a second reviewer has checked it against the live files.
Create secret files with restricted ownership
On each host that runs Prometheus or Alertmanager, create one file per secret in a directory that only administrators and the service account can reach. First confirm which account the package or container image runs the service as, then set that account as owner with read-only permissions. Check the result with a directory listing and a read test as the service account, and confirm other local users are denied. Done when the service account can read each file and no other user can.
Switch each field to its _file variant
Replace each inline value with the matching _file key, such as password_file or bearer_token_file, and point it at the secret file path. Confirm in the configuration reference for your running version that every field you change has a _file variant, since some fields may not. Change one job or receiver at a time so any failure is easy to trace. Done when the changed fields reference file paths and contain no inline values.
Validate both configuration files
Run promtool check config against prometheus.yml and amtool check-config against alertmanager.yml on the host, or inside the same container image the service uses. Validation confirms the YAML parses and the keys are recognized. Check whether your version also reads the secret files during validation, and if it does not, leave readability to the test in the reload step. Done when both commands exit without errors and the output is saved to the change record.
Confirm the value is gone from the files
Search prometheus.yml and alertmanager.yml, and any Git repository or template they are rendered from, for the old password, token or key value. Search for the value itself as well as the field name, because a field name alone does not show a leak. Then open the running configuration view and confirm the value is absent or redacted for your version. Done when no match for the old value remains in the files or in the API output.
Reload and confirm each target and receiver authenticates
Reload Prometheus and Alertmanager with SIGHUP, or with the reload endpoint if lifecycle endpoints are enabled. Then check the Targets page for every job that was healthy before the change, and send a test alert to a non-production receiver. Done when each job reports up and the test notification arrives. If a target returns an authentication error, check the file path and file permissions first.
Rotate a secret and verify it loads
Write the new value into the same file, keep ownership and permissions unchanged, and reload the service that reads it. Confirm in your version's documentation that the reload picks up the file contents. Check target health or send a test notification to confirm the new value works, and confirm the old credential is refused by the remote system. Record who rotated the secret and when. Done when the new credential authenticates and the old one no longer does.
What the Prometheus API redacts and what it still shows
The status and configuration endpoints of Prometheus can reveal the configuration the server has loaded, so a password or token that sits in prometheus.yml may be visible to anyone who can reach those endpoints. According to the Prometheus security documentation, secret fields are masked in that output. Read that masking as a limited promise: it applies to the documented secret fields only. Any credential placed in a field that is not on that list, or pasted into a label, URL or query parameter, can appear in plain text. Before you rely on redaction, run a test on your own version: load a dummy secret into each job and alerting block you use, then query the configuration endpoint from the network segment where your operators sit. Confirm the output yourself rather than assuming it matches the documentation for a different release.
Redaction also depends on what sits between the client and Prometheus. A reverse proxy or API gateway may log full request paths, and a dashboard or troubleshooting tool may copy configuration into tickets or chat. Check proxy access logs, container logs and any scraping of the API by monitoring tools for the same values. Treat the configuration endpoint as sensitive even when secrets are masked, because it also discloses target addresses, job names and internal network layout that help an attacker plan further steps.
The admin and lifecycle APIs raise the stakes. The admin APIs are disabled by default, but when --web.enable-admin-api is set they allow destructive operations, and --web.enable-lifecycle exposes reload and shutdown endpoints. Anyone who can call these endpoints can change or disrupt monitoring, so restrict them at the network layer or behind an authenticating proxy, and verify the flags on every instance. Because Prometheus has no built-in CSRF protection on mutating endpoints, a browser session from an authorized user can be abused if it reaches the API. The related hardening topics on TLS, basic authentication, controlling the admin and lifecycle APIs, and per-tenant read access cover these controls in detail.
Alertmanager template pitfalls that leak secrets
Alertmanager receivers are the most common place a credential leaves the configuration file. Templates, notification bodies, version control and debug output each carry a copy of whatever the receiver was given, so the controls below follow the value from the config file to every place it can appear.
Secrets pasted into receiver templates
Receiver templates in Alertmanager configuration sometimes contain a literal token or password, often added while testing a new Slack, email or webhook receiver. The template then travels with the config file to every environment and every reviewer. Move the value into a file or environment-supplied secret and reference only the placeholder in templates. Check each receiver in your own configuration for any string that looks like a credential, including those inside template blocks rather than only in the receiver fields.
Alertmanager docsValues echoed into notification bodies
A template that prints every label or annotation can copy a credential into a chat channel, ticket or email body if an upstream exporter or rule attaches one. Once delivered, the value sits in the notification archive of a third-party service you may not control. Restrict templates to named fields you intend to send, and review annotations on alert rules for values such as connection strings. Confirm with each receiver owner which fields reach their channel and who can read it.
Labels that carry tokens
Labels become part of alert identity, so a rule that derives a label from a URL query string, header or request path can publish a token in every alert and every grouping key. Those labels then appear in the Alertmanager UI, API responses and notifications. Review label values produced by relabeling and by rules that copy from target metadata, and drop or hash any value that carries a credential before it reaches Alertmanager. Test this with a sample alert from a non-production target.
Git history keeping old values
Removing a secret from the current alertmanager.yml does not remove it from the commits that already contain it. Anyone with read access to the repository, including forks, mirrors and CI caches, can recover the previous value. If a credential has ever been committed, rotate it at the issuing service first, then rewrite history or treat the repository as exposed. Ask your team whether a secret scanner runs on every push and on the default branch.
Backups and debug output holding rendered config
Backups of the configuration directory, copies made during incident work and debug or configuration endpoints can all hold the rendered configuration with values substituted in. Alertmanager exposes its loaded configuration through its API, so access to that endpoint is access to the receiver secrets unless the web interface is protected. Confirm which backup jobs capture the configuration directory, who can read those backups, and whether the status and configuration endpoints sit behind authentication.
Webhook URLs with embedded keys
Many chat and incident webhooks put the authorization key inside the URL path, so the URL itself is the credential. Pasting that URL into a receiver field, a template or a ticket comment makes it readable to everyone who sees the config. Store the full URL in a secret file where the receiver supports it, rotate the webhook when a URL is exposed, and list which receivers rely on path-embedded keys so that rotation can be scheduled and tested.
Kubernetes secrets with the Prometheus Operator
Plain Prometheus on Kubernetes reads a prometheus.yml file, usually delivered in a ConfigMap. The file should only point at secrets. Store each password, bearer token or key in a Kubernetes Secret, mount that Secret into the Prometheus pod as a volume, and reference the mounted path in the scrape job with a field such as password_file or bearer_token_file. The ConfigMap then holds no credential values and can be stored in version control without exposing them.
- Mount secrets read-only: Set the volume mount to read-only so the pod can read each value but cannot change it.
- Keep rendered ConfigMaps clean: If a templating tool generates the file, check the rendered output in CI so a value does not slip in as plain text.
- Scope the service account: Confirm the Prometheus pod's service account has no API rights to list or read Secrets beyond what the pod needs.
- Test rotation per field: Confirm whether each file-based credential is picked up without a restart in your Prometheus version, and rehearse a rotation in a non-production cluster.
- Reload after changes: A changed ConfigMap needs a configuration reload or a pod restart before Prometheus uses it.
Before sign-off, check the ConfigMap and pod spec with kubectl get configmap -o yaml and confirm they show file paths and no secret values.
The Prometheus Operator manages Prometheus and Alertmanager through custom resources, and several of those resources can reference Kubernetes Secrets directly. A ServiceMonitor or PodMonitor can point an endpoint at a Secret key for basic authentication, a bearer token or TLS material. The Prometheus resource can mount named Secrets into the pod through its secrets field and can read raw scrape jobs from a Secret key through additionalScrapeConfigs. The Alertmanager resource takes its whole configuration from a Secret named in configSecret, which is where webhook URLs and SMTP passwords belong.
- Endpoint credentials: Reference basic auth and bearer token values from a Secret key inside the monitor resource, so the monitor manifest stays free of values.
- Raw scrape jobs: Put any scrape job the custom resource cannot express into a Secret and reference it from
additionalScrapeConfigs. - Alertmanager receivers: Keep receiver credentials in the Secret that holds
alertmanager.yaml, and version the non-secret parts separately. - Mounted secrets: Secrets listed under
secretsappear in the pod, so limit that list to what the scrape jobs actually use. - Confirm field names: Check the exact field names, and whether a reference must sit in the same namespace, against the Prometheus Operator documentation for the operator version you run.
Before go-live, render the generated Prometheus and Alertmanager configuration and confirm the credential fields show references, not values.
Secret references move the question of who can read a credential into Kubernetes RBAC. The operator needs to read the Secrets its custom resources refer to, so its cluster role is the first thing to review. Its scope should match the namespaces it watches. Any team that can create or edit a ServiceMonitor may be able to make the operator use a Secret that team cannot read directly, so this path needs testing rather than assumption. Alertmanager configuration deserves the same care, because write access to its Secret controls where alerts are sent.
- Operator cluster role: Limit the operator's read access on Secrets to the namespaces it manages, and use namespace-scoped roles where the chart or bundle allows it.
- Indirect secret use: Test whether a user with rights only to create monitors can cause a credential to be used in a scrape, and restrict those rights if they can.
- Alertmanager Secret writes: Treat write access to the Alertmanager configuration Secret as control over notification destinations.
- Human read access: Restrict
get,listandwatchon Secrets for people, and keep break-glass access documented. - Audit trail: Confirm that the API server audit policy records Secret reads and writes at the level your auditors expect.
Finish by running an access review with kubectl auth can-i for each role against each Secret the monitoring namespace uses.
The Prometheus Operator reads and mounts Secrets, but it does not protect them beyond what Kubernetes already provides. A Kubernetes Secret is stored encoded, not encrypted, unless the cluster enables encryption at rest for Secret objects in etcd. The operator also does not create, rotate or audit credentials, and it does not replace an external secret store. Those controls sit in the platform, so the monitoring design has to name the owner for each one.
- Encryption at rest: Confirm with your Kubernetes distribution whether etcd encryption is enabled for Secrets, and who manages the key.
- External secret stores: Tools such as the External Secrets Operator, a secrets manager agent or a CSI driver can sync values into Kubernetes, but they are separate components with their own RBAC and failure modes.
- Rotation and generation: Decide who generates new passwords and tokens, how often they change, and how a changed value reaches Prometheus and Alertmanager.
- Logs and manifests: Keep credentials out of container logs, Helm values files, GitOps repositories and CI output, since the operator does not scan for them.
- Backups: Confirm that backups of etcd and of Secret manifests are encrypted and restricted.
Before relying on any of these controls, ask the platform owner for written evidence of the encryption setting and the rotation procedure.
Security and operational controls around secret files
Once a credential lives in a file instead of the configuration, the file becomes the thing to protect. The cards below cover the controls that keep those files readable only by the right process, changeable without downtime, owned by the right people, and recoverable from backups without exposing them.
File ownership and mode
Each secret file should be owned by the account that runs Prometheus or Alertmanager, with permissions restricted so no other local user can read it. Set the owner and mode when the file is created, not later, and check them in the deployment pipeline. Confirm that the service account can read the file at startup, because a permissions error often shows up only after a restart. Keep the directory itself as restrictive as the file.
Secret rotation and reload
Plan how a credential changes before it needs to. Write the new value to the file, confirm that the consuming component reads it, and then revoke the old value on the remote system. Reloading Prometheus through its configuration reload path depends on whether the lifecycle endpoint is enabled, so confirm that setting before you rely on it. Record each rotation with a date and an owner so the next rotation is not guesswork.
Separation of duties
Config authors write scrape jobs and alert routes, while secret holders manage the values those jobs use. Where the same people do both, a single change can add a target and expose a password to it. Put secret files in a separate repository or access group, and require review for any change that points an existing credential at a new endpoint. This split should match how your change approval process already works.
Auditing who can read secret files
Review the list of accounts, groups and automation identities that can read each secret file on the host and in any mounted volume or Kubernetes secret. Compare that list with the people who actually run the monitoring stack. Repeat the review on a fixed schedule and after staff changes. Confirm with your platform team how file access events are logged on your hosts, since the Prometheus configuration itself does not record reads of these files.
Backup encryption for secret material
Configuration backups often include secret files, and an unencrypted backup copies every credential into a second place. Encrypt backups that contain secret files, store the decryption keys apart from the backups, and limit restore rights to the same group that manages secrets. Test a restore in a separate environment so you know the secret files come back with the correct owner and mode. Ask your backup provider how keys are managed and rotated.
Exposure in logs and version control
A secret can leak through a copied configuration file, a debug log or a commit that briefly contained the value. Keep secret files out of version control, add them to ignore rules in the repository, and scan commit history before adoption. Review what your deployment tooling prints during a run, because some tools echo rendered configuration on failure. Treat any value that appeared in a log or commit as exposed and rotate it.
Questions teams ask before moving secrets out of configuration
How much effort does moving secrets out of prometheus.yml take?
The effort scales with how many places hold credentials and how many systems read them. Count the scrape jobs with basic auth or bearer tokens, the remote write and remote read blocks, the Alertmanager receivers (webhooks, email, chat and paging integrations), and any Grafana data sources that connect to Prometheus. Each of those is a place where a password or token can appear in plain text today. A team with a few jobs and one receiver has a small, bounded task. A team with dozens of jobs across several Alertmanager receivers, plus Kubernetes and virtual machine hosts, has more files to change, more consumers to test and more rotation steps to coordinate. The secret store you choose also matters, since each store needs its own access policy, provisioning method and failure plan.
- Number of scrape jobs and remote endpoints
- Number of Alertmanager receivers and templates
- Kubernetes Operator use or plain virtual machine hosting
- Secret store choice and how it is reached from each host
Can our own team move secrets out of Prometheus configuration in-house?
Yes, if the team already runs Prometheus and has someone comfortable with file permissions, service configuration and the secret store they plan to use. The core change is small: many Prometheus and Alertmanager secret fields have a _file variant, such as password_file or bearer_token_file, that reads the value from a file at load time, so the YAML holds a path instead of the value. The harder parts are inventory, Alertmanager template review and rotation. Teams that lack an inventory habit, or that run Prometheus across many environments, often find the work takes longer than the config edit itself. Outside help makes most sense when the scope is large, when the environment is regulated and the change must be evidenced, or when no one has time to test every receiver after the change.
What do we need to provide before the work starts?
The most useful input is a current inventory of every configuration file for Prometheus, Alertmanager and any exporter or agent that reads credentials. The inventory should list each secret field, the system it authenticates to, the host or cluster that runs the component, and the person who can rotate the credential at the source. You will also need access to the hosts or Kubernetes clusters where the components run, read access to the current configuration and, for planning, a named owner for secret rotation who can approve changes to passwords and tokens on the receiving systems. Ask whether the secret store is already in place, who administers it and how applications authenticate to it, because those answers decide the design.
How long does this take for a typical setup?
No fixed duration can be given here because it depends on the scope inventory, the number of consumers and the secret store already in use. Ask for a timeline based on a written scope rather than a generic figure. A useful scope names the components covered (Prometheus, Alertmanager, exporters, Grafana), the count of secret fields found in the inventory, the hosting model, the secret store and the testing you expect for each receiver after the switch. Time is usually spent in four places: finding every secret, deciding where each one lives, changing and reloading configuration, and confirming that scrapes and notifications still work. Ask the provider to show how each of those phases is planned and tested.
Does moving secrets into files satisfy a compliance review by itself?
No. Moving secrets out of configuration reduces one exposure, but a compliance review looks at the whole control environment: who can read the secret store, how access is granted and removed, how rotation happens, whether changes are logged and how the process is tested. Prometheus metrics and alert records can supply some monitoring and capacity evidence, but they do not prove access control on their own. Your auditor or certification body decides whether the controls meet the standard you are assessed against. DeployOpen prepares systems, controls and evidence for compliance assessments, but it does not issue audit reports, attestations or certifications.
What breaks if a secret file is missing or unreadable after the change?
The component usually fails to load its configuration or cannot authenticate, so scrapes stop or notifications fail. Confirm the behavior for your installed version before relying on it, and test a deliberately wrong path in a non-production environment. Plan for file ownership and permissions, so the service account can read the file but other users cannot. Check that configuration reloads fail safely and that a failed reload does not leave you with no working configuration. Keep the previous working secret available until the new one is verified, and run promtool checks on the configuration before reloading. Most outages in this kind of change come from path mistakes, wrong permissions or secrets that were rotated at the source but not on the server.
Does the API show secret values when someone queries the configuration?
Prometheus and Alertmanager redact secret fields in their configuration endpoints, so a query to the running configuration should not return the raw password or token. Do not treat that as the whole control, though. The file on disk, the process environment, backups, container images and logs can still expose the value. Confirm redaction behavior on your exact version, and check that your own tooling, dashboards and CI jobs do not print configuration to logs.
How secret values reach Prometheus and Alertmanager without sitting in the config file
The flow starts at the secret store or Kubernetes secret, which mounts the value as a file on the host or pod. Prometheus or Alertmanager reads that file when it loads configuration, then sends authenticated requests to the scrape target or receiver. The boundary to check is the prometheus.yml or Alertmanager file and the API output, which should show a reference to the file and never the value itself.
Secret values travel through a mounted file, never through the configuration file or API output.
How DeployOpen scopes the secret handling work
DeployOpen scopes this work as a fixed-scope engagement, with the scope, deliverables and timeline agreed in writing before any change is made to a production configuration. The work starts with an inventory of every field that carries a credential: scrape job basic_auth and authorization blocks, tls_config key paths, remote write and remote read credentials, and every Alertmanager receiver that holds a token, webhook URL or SMTP password. The inventory also records where each value is currently stored, who can read it, and which systems consume it. Clients are often surprised by how many receivers and exporters carry a secret that nobody has listed.
Next, the client and DeployOpen agree a target pattern for each secret class. For Prometheus and Alertmanager running on servers, this usually means files referenced through the _file variants of the secret fields, with the files owned by the service account and readable only by it. On Kubernetes with the Operator, the pattern is usually Kubernetes secrets that the client's existing secret store or external secrets tooling already manages. DeployOpen implements the change, then verifies it by checking that the rendered configuration no longer contains literal values, that the API does not return secret values to a reader who should not see them, and that Alertmanager templates do not expose credentials in notifications. The engagement ends with a handover of documented rotation steps, so the client's own team can rotate each credential without DeployOpen. DeployOpen prepares these controls and evidence, but it does not issue audit reports or attestations. The client's auditors review the evidence and decide whether it meets their requirements.
How DeployOpen delivers Prometheus hardening
DeployOpen treats credentials in Prometheus and Alertmanager configuration as a scoped piece of work: we inventory every secret field, move it out of prometheus.yml into files or Kubernetes secrets, and test that the API and logs no longer expose it. Each step is agreed in writing before work starts, and the result is handed over with documentation your team can rerun.
How we scope
- Inventory every password, token and key in prometheus.yml and alertmanager.yml across all scrape jobs and receivers.
- Confirm which fields in your Prometheus version accept _file variants and which need a different approach.
- Agree in writing whether the work covers bare-metal, Docker, or Kubernetes with the Prometheus Operator.
How we build
- Move secrets into root-readable files or Kubernetes secrets, and reference them from configuration without inline values.
- Review Alertmanager templates for places where secret values could render into notifications or logs.
- Check the configuration API output and the web UI to confirm that secret fields are not returned in plain text.
How we hand over
- Deliver a secrets map showing each credential, its storage location, owner and rotation procedure.
- Provide runbooks for rotating a credential and reloading Prometheus or Alertmanager with promtool validation.
- Document the checks your team can rerun after each configuration change or Prometheus upgrade.
How we support
- Engagements are fixed-scope, so the agreed deliverables and retest are defined before any work begins.
- Ongoing support, upgrades and continuous testing are available as a retainer if your configuration keeps changing.
- Ask any partner to confirm how they handle credential rotation after handover and who keeps access to the secret stores.

