Skip to content

fix: make Grafana Cloud Run admin credentials configurable#61

Open
lokeshmuvva wants to merge 3 commits into
devfrom
fix/grafana-configurable-admin-credentials
Open

fix: make Grafana Cloud Run admin credentials configurable#61
lokeshmuvva wants to merge 3 commits into
devfrom
fix/grafana-configurable-admin-credentials

Conversation

@lokeshmuvva
Copy link
Copy Markdown

@lokeshmuvva lokeshmuvva commented Jun 2, 2026

What

The Grafana admin credentials on the Cloud Run path were hardcoded to admin/admin and baked into the container image (Dockerfile ENV), with no way to override them at deploy time. This makes them configurable through the stack config and removes the secret from the image:

  • Add grafana_admin_user / grafana_admin_password inputs to the Grafana Cloud Run module, wired to GF_SECURITY_ADMIN_USER / GF_SECURITY_ADMIN_PASSWORD (password marked sensitive). Defaults to admin to preserve current behavior.
  • Forward those values from the grafana tool's params in both Cloud Run main templates (main.tf.j2, mlflow_main.tf.j2).
  • Remove the baked-in GF_SECURITY_ADMIN_* ENV from the Grafana image.

Why

Baking credentials into an image stores them in a readable layer (docker history) and leaves operators no way to set a real password. On stateless Cloud Run, an admin password changed via the UI does not survive a cold start (Grafana's SQLite config DB sits on ephemeral disk unless a metrics Postgres DB is configured), so supplying the password as deploy-time env is the correct pattern — this change makes that possible.

Behavior

Unchanged by default: deployed services get admin/admin from Terraform, and a standalone image falls back to Grafana's own admin default, so documented logins still hold. Operators can now override by setting grafana_admin_password (and grafana_admin_user) in their stack config.

Verification

Rendered the documented MLflow + Grafana stack through mlflow_main.tf.j2: it emits a single Grafana module with the credentials applied, and a custom password set in config passes through to the rendered Terraform. terraform fmt clean on the new module lines.

Out of scope (follow-up)

While verifying, found a pre-existing bug: main.tf.j2 emits the Grafana module twice (generic tool loop + dedicated block) and passes arguments the module doesn't declare, so Grafana via that path (a stack with no MLflow/W&B) cannot deploy today. It's independent of credentials and will be addressed separately.

Test plan

  • Render documented MLflow+Grafana stack → single module, creds applied, custom password passes through
  • terraform fmt clean on the new module lines
  • (maintainer) deploy a stack and confirm Grafana login with default and with an overridden password

The Grafana Cloud Run module set no admin env vars, so the admin
password came solely from the value baked into the container image,
leaving no way to override it at deploy time.

Add grafana_admin_user / grafana_admin_password variables (defaulting
to admin to preserve current behavior; password marked sensitive) and
wire them to GF_SECURITY_ADMIN_USER / GF_SECURITY_ADMIN_PASSWORD. A
Cloud Run container env var overrides the image's baked-in ENV, which
sets up removing the hardcoded credentials from the Dockerfile.
…odule

The Cloud Run main templates invoked the Grafana module without
forwarding any admin credentials, so the module inputs added in the
previous commit were unreachable from a user's stack config.

Forward grafana_admin_user / grafana_admin_password from the grafana
tool's params (defaulting to admin) in both main.tf.j2 and
mlflow_main.tf.j2. Verified by rendering the documented MLflow+Grafana
stack: it emits a single Grafana module with the credentials applied,
and a custom password in config passes through.
The Grafana image set GF_SECURITY_ADMIN_USER / GF_SECURITY_ADMIN_PASSWORD
to admin via ENV, embedding a credential in a readable image layer
(visible through docker history). With the Cloud Run module and
templates now supplying these at deploy time, the baked values are
redundant.

Remove them. Behavior is unchanged: deployed services get their
credentials from Terraform, and a standalone container falls back to
Grafana's own admin default, so the documented login still holds.
GF_SERVER_HTTP_PORT is kept as it is non-secret port configuration.
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