Skip to content

Using existing secret for configuring alloy #2031

Description

@krisztiansala

Hi,
The Grafana cloud UI auto-generates Helm values for deploying the Kubernetes monitoring chart, but the values file contains the access token and I don't want to push that to version control.
I tried configuring it with a custom secret, but it's not working well.
This is my whole values file:

# Grafana k8s Monitoring Helm Chart Values
# Documentation: https://grafana.com/docs/grafana-cloud/monitor-infrastructure/kubernetes-monitoring/configuration/helm-chart-config/helm-chart/

# Cluster configuration
cluster:
  name: my-cluster

# Grafana Cloud destinations
destinations:
  - name: grafana-cloud-metrics
    type: prometheus
    url: https://prometheus-prod-24-prod-eu-west-2.grafana.net/api/prom/push
    auth:
      type: basic
      usernameKey: "username-grafana"
      passwordKey: "access-policy-token"    
    secret:
      create: false
      name: grafana-cloud-credentials
      namespace: infra
  - name: grafana-cloud-logs
    type: loki
    url: https://logs-prod-012.grafana.net/loki/api/v1/push
    auth:
      type: basic
      usernameKey: "username"
      passwordKey: "access-policy-token"
    secret:
      create: false
      name: grafana-cloud-credentials
      namespace: infra
  - name: gc-otlp-endpoint
    type: otlp
    url: https://otlp-gateway-prod-eu-west-2.grafana.net/otlp
    protocol: http
    auth:
      type: basic
      usernameKey: "username"
      passwordKey: "access-policy-token"
    secret:
      create: false
      name: grafana-cloud-credentials
      namespace: infra
    metrics:
      enabled: true
    logs:
      enabled: true
    traces:
      enabled: true
  - name: grafana-cloud-profiles
    type: pyroscope
    url: https://profiles-prod-002.grafana.net:443
    auth:
      type: basic
      usernameKey: "username"
      passwordKey: "access-policy-token"
    secret:
      create: false
      name: grafana-cloud-credentials
      namespace: infra
# Cluster metrics collection
clusterMetrics:
  enabled: true
  opencost:
    enabled: true
    metricsSource: grafana-cloud-metrics
    opencost:
      exporter:
        defaultClusterId: my-cluster
      prometheus:
        existingSecretName: grafana-cloud-credentials
        username_key: "username-grafana"
        password_key: access-policy-token
        external:
          url: https://prometheus-prod-24-prod-eu-west-2.grafana.net/api/prom
  kepler:
    enabled: true

# Annotation autodiscovery
annotationAutodiscovery:
  enabled: true

# Prometheus operator objects
prometheusOperatorObjects:
  enabled: true

# Cluster events
clusterEvents:
  enabled: true

# Log collection
nodeLogs:
  enabled: true
podLogs:
  enabled: true

# Application observability
applicationObservability:
  enabled: true
  receivers:
    otlp:
      grpc:
        enabled: true
        port: 4317
      http:
        enabled: true
        port: 4318
    zipkin:
      enabled: true
      port: 9411

# Auto instrumentation
autoInstrumentation:
  enabled: true

# Profiling
profiling:
  enabled: true

# Alloy instances configuration
alloy-metrics:
  enabled: true
  alloy:
    extraEnv:
      - name: GCLOUD_RW_API_KEY
        valueFrom:
          secretKeyRef:
            name: grafana-cloud-credentials
            key: access-policy-token
      - name: CLUSTER_NAME
        value: my-cluster
      - name: NAMESPACE
        valueFrom:
          fieldRef:
            fieldPath: metadata.namespace
      - name: POD_NAME
        valueFrom:
          fieldRef:
            fieldPath: metadata.name
      - name: GCLOUD_FM_COLLECTOR_ID
        value: grafana-k8s-monitoring-$(CLUSTER_NAME)-$(NAMESPACE)-$(POD_NAME)
  remoteConfig:
    enabled: true
    url: https://fleet-management-prod-011.grafana.net
    auth:
      type: basic
      usernameKey: "username"
      passwordKey: "access-policy-token"
    secret:
      create: false
      name: grafana-cloud-credentials
      namespace: infra
alloy-singleton:
  enabled: true
  alloy:
    extraEnv:
      - name: GCLOUD_RW_API_KEY
        valueFrom:
          secretKeyRef:
            name: grafana-cloud-credentials
            key: access-policy-token
      - name: CLUSTER_NAME
        value: my-cluster
      - name: NAMESPACE
        valueFrom:
          fieldRef:
            fieldPath: metadata.namespace
      - name: POD_NAME
        valueFrom:
          fieldRef:
            fieldPath: metadata.name
      - name: GCLOUD_FM_COLLECTOR_ID
        value: grafana-k8s-monitoring-$(CLUSTER_NAME)-$(NAMESPACE)-$(POD_NAME)
  remoteConfig:
    enabled: true
    url: https://fleet-management-prod-011.grafana.net
    auth:
      type: basic
      usernameKey: "username"
      passwordKey: "access-policy-token"
    secret:
      create: false
      name: grafana-cloud-credentials
      namespace: infra
alloy-logs:
  enabled: true
  alloy:
    extraEnv:
      - name: GCLOUD_RW_API_KEY
        valueFrom:
          secretKeyRef:
            name: grafana-cloud-credentials
            key: access-policy-token
      - name: CLUSTER_NAME
        value: my-cluster
      - name: NAMESPACE
        valueFrom:
          fieldRef:
            fieldPath: metadata.namespace
      - name: POD_NAME
        valueFrom:
          fieldRef:
            fieldPath: metadata.name
      - name: NODE_NAME
        valueFrom:
          fieldRef:
            fieldPath: spec.nodeName
      - name: GCLOUD_FM_COLLECTOR_ID
        value: grafana-k8s-monitoring-$(CLUSTER_NAME)-$(NAMESPACE)-alloy-logs-$(NODE_NAME)
  remoteConfig:
    enabled: true
    url: https://fleet-management-prod-011.grafana.net
    auth:
      type: basic
      usernameKey: "username"
      passwordKey: "access-policy-token"
    secret:
      create: false
      name: grafana-cloud-credentials
      namespace: infra
alloy-receiver:
  enabled: true
  alloy:
    extraPorts:
      - name: otlp-grpc
        port: 4317
        targetPort: 4317
        protocol: TCP
      - name: otlp-http
        port: 4318
        targetPort: 4318
        protocol: TCP
      - name: zipkin
        port: 9411
        targetPort: 9411
        protocol: TCP
    extraEnv:
      - name: GCLOUD_RW_API_KEY
        valueFrom:
          secretKeyRef:
            name: grafana-cloud-credentials
            key: access-policy-token
      - name: CLUSTER_NAME
        value: my-cluster
      - name: NAMESPACE
        valueFrom:
          fieldRef:
            fieldPath: metadata.namespace
      - name: POD_NAME
        valueFrom:
          fieldRef:
            fieldPath: metadata.name
      - name: NODE_NAME
        valueFrom:
          fieldRef:
            fieldPath: spec.nodeName
      - name: GCLOUD_FM_COLLECTOR_ID
        value: grafana-k8s-monitoring-$(CLUSTER_NAME)-$(NAMESPACE)-alloy-receiver-$(NODE_NAME)
  remoteConfig:
    enabled: true
    url: https://fleet-management-prod-011.grafana.net
    auth:
      type: basic
      usernameKey: "username"
      passwordKey: "access-policy-token"
    secret:
      create: false
      name: grafana-cloud-credentials
      namespace: infra
alloy-profiles:
  enabled: true
  alloy:
    extraEnv:
      - name: GCLOUD_RW_API_KEY
        valueFrom:
          secretKeyRef:
            name: grafana-cloud-credentials
            key: access-policy-token
      - name: CLUSTER_NAME
        value: my-cluster
      - name: NAMESPACE
        valueFrom:
          fieldRef:
            fieldPath: metadata.namespace
      - name: POD_NAME
        valueFrom:
          fieldRef:
            fieldPath: metadata.name
      - name: NODE_NAME
        valueFrom:
          fieldRef:
            fieldPath: spec.nodeName
      - name: GCLOUD_FM_COLLECTOR_ID
        value: grafana-k8s-monitoring-$(CLUSTER_NAME)-$(NAMESPACE)-alloy-profiles-$(NODE_NAME)
  remoteConfig:
    enabled: true
    url: https://fleet-management-prod-011.grafana.net
    auth:
      type: basic
      usernameKey: "username"
      passwordKey: "access-policy-token"
    secret:
      create: false
      name: grafana-cloud-credentials
      namespace: infra

But I'm seeing these errors, for example in the grafana-k8s-monitoring-alloy-logs pod:
Error: /etc/alloy/config.alloy:371:1: Failed to evaluate service: updating service: unauthenticated: authentication error: invalid authentication credentials

370 |
371 | remotecfg {
| _^^^^^^^^^^^
372 | | id = sys.env("GCLOUD_FM_COLLECTOR_ID")
373 | | url = "https://fleet-management-prod-011.grafana.net"
374 | | basic_auth {
375 | | username = convert.nonsensitive(remote.kubernetes.secret.alloy_logs_remote_cfg.data["username"])
376 | | password = remote.kubernetes.secret.alloy_logs_remote_cfg.data["access-policy-token"]
377 | | }
378 | | tls_config {
379 | | insecure_skip_verify = false
380 | | ca_pem = convert.nonsensitive(remote.kubernetes.secret.alloy_logs_remote_cfg.data["ca"])
381 | | cert_pem = convert.nonsensitive(remote.kubernetes.secret.alloy_logs_remote_cfg.data["cert"])
382 | | key_pem = remote.kubernetes.secret.alloy_logs_remote_cfg.data["key"]

If you check my values file, I'm referencing the grafana-cloud-credentials secret, but it's still trying to use alloy_logs_remote_cfg.

What am I doing wrong? I also tried using passwordFrom instead of passwordKey, but it didn't help.

Also, I only want to specify the password like this, I don't want to touch the default values of the SSL certificates. Is this achievable?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions