- 
                Notifications
    
You must be signed in to change notification settings  - Fork 442
 
Description
When configuring a PostgreSQL datasource using GrafanaDatasource CRD with valuesFrom to inject the password from a Kubernetes secret, the password is not properly applied to the datasource. This results in authentication failures with error: pq: password authentication failed for user "report_reader".
The same password works correctly when hardcoded directly in secureJsonData.password, confirming this is an issue with the valuesFrom mechanism specifically.
Environment
- Grafana Operator version: v5.19.0
 - Kubernetes version: v1.33.5-eks-113cf36 (EKS)
 - Grafana version: 12.1.0
 
Current Configuration (Not Working)
apiVersion: grafana.integreatly.org/v1beta1
kind: GrafanaDatasource
metadata:
  name: postgresql
  namespace: monitoring
spec:
  instanceSelector:
    matchLabels:
      app: grafana
  datasource:
    name: PostgreSQL
    type: postgres
    uid: postgresql
    url: mydb.eu-west-1.rds.amazonaws.com:5432
    access: proxy
    database: mydb
    user: report_reader
    jsonData:
      sslmode: require
  valuesFrom:
    - targetPath: secureJsonData.password
      valueFrom:
        secretKeyRef:
          name: grafana
          key: postgresql-passwordExpected Behavior
The password from the secret should be injected into the datasource's secureJsonData.password field, allowing successful authentication to the PostgreSQL database.
Actual Behavior
The datasource is created but authentication fails with:
db query error: pq: password authentication failed for user "report_reader"
What Works (Workaround)
Hardcoding the password directly in the datasource configuration works:
datasource:
  # ... other fields ...
  secureJsonData:
    password: "actual-password-here"Additional Information
Operator Logs
The operator logs show the datasource is being reconciled successfully:
2025-11-02T19:03:38Z INFO GrafanaDatasourceReconciler found matching Grafana instances for datasource
Status
The GrafanaDatasource status shows as successfully applied:
status:
  conditions:
  - lastTransitionTime: "2025-11-02T15:43:37Z"
    message: Datasource was successfully applied to 1 instances
    observedGeneration: 1
    reason: ApplySuccessful
    status: "True"
    type: DatasourceSynchronizedAnalysis
- The secret exists and contains the correct password (verified by base64 decoding)
 - The operator is processing the datasource (seen in logs)
 - The datasource status shows as "successfully applied"
 - However, the password is not actually being injected into Grafana
 
This appears to be similar to previously reported issues (#1482, #1485) with secureJsonData in the operator, but those were supposedly fixed in versions after 5.8.1.
Reproducible Test Case
- Create a secret with a PostgreSQL password
 - Create a GrafanaDatasource of type 
postgresusingvaluesFromto reference the secret - Try to query the datasource in Grafana
 - Observe authentication failure
 
Impact
This prevents secure password management for PostgreSQL datasources, forcing users to either:
- Hardcode passwords in the datasource configuration (security risk)
 - Find alternative methods for password injection
 
Related Issues
- [Bug] secureJsonData don't work in 5.8.1 #1482 - secureJsonData don't work in 5.8.1
 - [Bug] Unable to set secureJsonData.basicAuthPassword in GrafanaDatasource #1485 - Unable to set secureJsonData.basicAuthPassword in GrafanaDatasource