Skip to content

[Helm] Add rbac.rules #3874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions operations/helm/charts/alloy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ internal API changes are not present.
Unreleased
----------
- Add NetworkPolicy support. (@TheRealNoob)
- Add rbac.rules to customize ClusterRole's rules. (@kun98-liu)


1.1.1 (2025-06-05)
Expand Down
1 change: 1 addition & 0 deletions operations/helm/charts/alloy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ useful if just using the default DaemonSet isn't sufficient.
| networkPolicy.policyTypes[0] | string | `"Ingress"` | |
| networkPolicy.policyTypes[1] | string | `"Egress"` | |
| rbac.create | bool | `true` | Whether to create RBAC resources for Alloy. |
| rbac.rules | list | `[]` | Rules to add to ClusterRole for Alloy. If empty, default rules are used. |
| service.annotations | object | `{}` | |
| service.clusterIP | string | `""` | Cluster IP, can be set to None, empty "" or an IP address |
| service.enabled | bool | `true` | Creates a Service for the controller's pods. |
Expand Down
11 changes: 11 additions & 0 deletions operations/helm/charts/alloy/ci/rbac-rules-values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
rbac:
create: true
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- list
- watch
4 changes: 4 additions & 0 deletions operations/helm/charts/alloy/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ metadata:
{{- include "alloy.labels" . | nindent 4 }}
app.kubernetes.io/component: rbac
rules:
{{- if gt (len .Values.rbac.rules) 0 }}
{{- toYaml .Values.rbac.rules | nindent 2 }}
{{- else }}
# Rules which allow discovery.kubernetes to function.
- apiGroups:
- ""
Expand Down Expand Up @@ -92,6 +95,7 @@ rules:
- apiGroups: ["extensions"]
resources: ["replicasets"]
verbs: ["get", "list", "watch"]
{{- end }}

---
apiVersion: rbac.authorization.k8s.io/v1
Expand Down
6 changes: 6 additions & 0 deletions operations/helm/charts/alloy/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ image:
rbac:
# -- Whether to create RBAC resources for Alloy.
create: true

# -- Rules to add to ClusterRole for Alloy. If empty, default rules are used.
rules: []
# - apiGroups: [""]
# resources: ["pods"]
# verbs: ["get", "list", "watch"]

serviceAccount:
# -- Whether to create a service account for the Grafana Alloy deployment.
Expand Down
44 changes: 44 additions & 0 deletions operations/helm/tests/rbac-rules/alloy/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
# Source: alloy/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: alloy
namespace: default
labels:
helm.sh/chart: alloy
app.kubernetes.io/name: alloy
app.kubernetes.io/instance: alloy
app.kubernetes.io/version: "vX.Y.Z"
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: config
data:
config.alloy: |-
logging {
level = "info"
format = "logfmt"
}

discovery.kubernetes "pods" {
role = "pod"
}

discovery.kubernetes "nodes" {
role = "node"
}

discovery.kubernetes "services" {
role = "service"
}

discovery.kubernetes "endpoints" {
role = "endpoints"
}

discovery.kubernetes "endpointslices" {
role = "endpointslice"
}

discovery.kubernetes "ingresses" {
role = "ingress"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
# Source: alloy/templates/controllers/daemonset.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: alloy
namespace: default
labels:
helm.sh/chart: alloy
app.kubernetes.io/name: alloy
app.kubernetes.io/instance: alloy
app.kubernetes.io/version: "vX.Y.Z"
app.kubernetes.io/managed-by: Helm
spec:
minReadySeconds: 10
selector:
matchLabels:
app.kubernetes.io/name: alloy
app.kubernetes.io/instance: alloy
template:
metadata:
annotations:
kubectl.kubernetes.io/default-container: alloy
labels:
app.kubernetes.io/name: alloy
app.kubernetes.io/instance: alloy
spec:
serviceAccountName: alloy
containers:
- name: alloy
image: docker.io/grafana/alloy:v1.9.1
imagePullPolicy: IfNotPresent
args:
- run
- /etc/alloy/config.alloy
- --storage.path=/tmp/alloy
- --server.http.listen-addr=0.0.0.0:12345
- --server.http.ui-path-prefix=/
- --stability.level=generally-available
env:
- name: ALLOY_DEPLOY_MODE
value: "helm"
- name: HOSTNAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
ports:
- containerPort: 12345
name: http-metrics
readinessProbe:
httpGet:
path: /-/ready
port: 12345
scheme: HTTP
initialDelaySeconds: 10
timeoutSeconds: 1
volumeMounts:
- name: config
mountPath: /etc/alloy
- name: config-reloader
image: quay.io/prometheus-operator/prometheus-config-reloader:v0.81.0
args:
- --watched-dir=/etc/alloy
- --reload-url=http://localhost:12345/-/reload
volumeMounts:
- name: config
mountPath: /etc/alloy
resources:
requests:
cpu: 10m
memory: 50Mi
dnsPolicy: ClusterFirst
volumes:
- name: config
configMap:
name: alloy
43 changes: 43 additions & 0 deletions operations/helm/tests/rbac-rules/alloy/templates/rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
# Source: alloy/templates/rbac.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: alloy
labels:
helm.sh/chart: alloy
app.kubernetes.io/name: alloy
app.kubernetes.io/instance: alloy
app.kubernetes.io/version: "vX.Y.Z"
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: rbac
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- list
- watch
---
# Source: alloy/templates/rbac.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: alloy
labels:
helm.sh/chart: alloy
app.kubernetes.io/name: alloy
app.kubernetes.io/instance: alloy
app.kubernetes.io/version: "vX.Y.Z"
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: rbac
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: alloy
subjects:
- kind: ServiceAccount
name: alloy
namespace: default
25 changes: 25 additions & 0 deletions operations/helm/tests/rbac-rules/alloy/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
# Source: alloy/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
name: alloy
namespace: default
labels:
helm.sh/chart: alloy
app.kubernetes.io/name: alloy
app.kubernetes.io/instance: alloy
app.kubernetes.io/version: "vX.Y.Z"
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: networking
spec:
type: ClusterIP
selector:
app.kubernetes.io/name: alloy
app.kubernetes.io/instance: alloy
internalTrafficPolicy: Cluster
ports:
- name: http-metrics
port: 12345
targetPort: 12345
protocol: "TCP"
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
# Source: alloy/templates/serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
automountServiceAccountToken: true
metadata:
name: alloy
namespace: default
labels:
helm.sh/chart: alloy
app.kubernetes.io/name: alloy
app.kubernetes.io/instance: alloy
app.kubernetes.io/version: "vX.Y.Z"
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/component: rbac