Skip to content

prometheus: enable readOnlyRootFilesystem#858

Draft
marcleblanc2 wants to merge 1 commit intomainfrom
prometheus-readonly-root-filesystem
Draft

prometheus: enable readOnlyRootFilesystem#858
marcleblanc2 wants to merge 1 commit intomainfrom
prometheus-readonly-root-filesystem

Conversation

@marcleblanc2
Copy link
Copy Markdown
Contributor

Problem

The Prometheus container has readOnlyRootFilesystem: false (see sourcegraph/sourcegraph#34012), which is undesirable for security-hardened environments. The reason it was required is that prom-wrapper writes the Alertmanager configuration to /sg_config_prometheus/alertmanager.yml at runtime whenever observability.alerts or SMTP settings change in site config, and Alertmanager stores state at /alertmanager/.

Solution

This PR enables readOnlyRootFilesystem: true by:

  1. Adding an emptyDir volume at /alertmanager — provides writable storage for Alertmanager state (--storage.path) and the Alertmanager config file.

  2. Setting ALERTMANAGER_CONFIG_PATH=/alertmanager/alertmanager.yml — redirects prom-wrapper to write the Alertmanager config to the writable emptyDir instead of the read-only image layer at /sg_config_prometheus/.

Why this is safe

Path Writable? How
/prometheus (TSDB data) Already a PVC mount
/sg_prometheus_add_ons (Helm ConfigMap) ✅ (ConfigMap) Already mounted
/sg_config_prometheus (baked-in alert rules + prometheus.yml) Read-only ✅ Only written at image build time, never at runtime
/alertmanager (Alertmanager state + config) New emptyDir mount

Changes

  • values.yaml: Set readOnlyRootFilesystem: true, removed outdated comment referencing #34012
  • prometheus.Deployment.yaml: Added ALERTMANAGER_CONFIG_PATH env var, alertmanager-data emptyDir volume and mount
  • README.md: Auto-regenerated by helm-docs

@marcleblanc2 marcleblanc2 force-pushed the prometheus-readonly-root-filesystem branch from a10dc49 to c5a28ed Compare April 25, 2026 13:42
The Prometheus container previously required readOnlyRootFilesystem: false
because prom-wrapper writes the Alertmanager configuration file to
/sg_config_prometheus/alertmanager.yml at runtime whenever site config
observability.alerts or SMTP settings change. Additionally, Alertmanager
stores state (silences, notification log) at /alertmanager/.

This change enables readOnlyRootFilesystem: true by:

1. Adding an emptyDir volume mounted at /alertmanager for Alertmanager
   state storage (--storage.path).

2. Setting ALERTMANAGER_CONFIG_PATH=/alertmanager/alertmanager.yml so
   prom-wrapper writes the Alertmanager config to the writable emptyDir
   instead of the read-only image layer at /sg_config_prometheus/.

The /prometheus TSDB data path was already handled by the existing PVC,
and /sg_prometheus_add_ons is already a ConfigMap mount. The baked-in
alert rules at /sg_config_prometheus/ are read-only at runtime (only
written at image build time), so they remain accessible on the
read-only root filesystem.

Resolves: https://github.com/sourcegraph/sourcegraph/issues/34012
Co-authored-by: Amp <amp@ampcode.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019dbe72-f13d-7233-aa22-cbeb04d03182
@marcleblanc2 marcleblanc2 force-pushed the prometheus-readonly-root-filesystem branch from c5a28ed to b827bfa Compare April 25, 2026 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant