Skip to content

Commit 5f21f34

Browse files
committed
Clarify RBAC in TargetAllocator readme. #2734
1 parent 08b33a5 commit 5f21f34

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

cmd/otel-allocator/README.md

+26-17
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,32 @@ OpenTelemetry Collector Operator-specific config.
118118

119119
Upstream documentation here: [PrometheusReceiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/receiver/prometheusreceiver#opentelemetry-operator)
120120

121-
The TargetAllocator service is named based on the OpenTelemetryCollector CR name. `collector_id` should be unique per
121+
The TargetAllocator service is named based on the `OpenTelemetryCollector` CR name. For example, if your Collector CR name is `my-collector`, then the TargetAllocator `service` and `deployment` will each be named `my-collector-targetallocator`, and the `pod` will be named `my-collector-targetallocator-<pod_id>`. `collector_id` should be unique per
122122
collector instance, such as the pod name. The `POD_NAME` environment variable is convenient since this is supplied
123123
to collector instance pods by default.
124124

125125

126126
### RBAC
127-
The ServiceAccount that the TargetAllocator runs as, has to have access to the CRs and the namespaces to watch for the pod and service monitors. A role like this will provide that
128-
access.
127+
128+
Before the TargetAllocator can start scraping, you need to set up a Kubernetes RBAC (role-based access controls). This means that you need to have a `ServiceAccount` and corresponding cluster roles so that the TargetAllocator has access to all of the necessary resources to pull metrics from.
129+
130+
You can create your own `ServiceAccount`, and reference it in `spec.targetAllocator.serviceAccount` in your `OpenTelemetryCollector` CR. You’ll then need to configure the `ClusterRole` and `ClusterRoleBinding` for this `ServiceAccount`, as per below.
131+
132+
```yaml
133+
targetAllocator:
134+
enabled: true
135+
serviceAccount: opentelemetry-targetallocator-sa
136+
prometheusCR:
137+
enabled: true
138+
```
139+
140+
> 🚨 **Note**: The Collector part of this same CR *also* has a serviceAccount key which only affects the collector and *not*
141+
the TargetAllocator.
142+
143+
If you omit the `ServiceAccount` name, the TargetAllocator creates a `ServiceAccount` for you. The `ServiceAccount`’s default name is a concatenation of the Collector name and the `-collector` suffix. By default, this `ServiceAccount` has no defined policy, so you’ll need to create your own `ClusterRole` and `ClusterRoleBinding` for it, as per below.
144+
145+
The role below will provide the minimum access required for the Target Allocator to query all the targets it needs based on any Prometheus configurations:
146+
129147
```yaml
130148
apiVersion: rbac.authorization.k8s.io/v1
131149
kind: ClusterRole
@@ -144,8 +162,9 @@ rules:
144162
- namespaces
145163
verbs: ["get", "list", "watch"]
146164
```
147-
In addition, the TargetAllocator needs the same permissions as a Prometheus instance would to find the matching targets
148-
from the CR instances.
165+
166+
If you enable the the `prometheusCR` (set `spec.targetAllocator.prometheusCR.enabled` to `true`) in the `OpenTelemetryCollector` CR, you will also need to define the following roles. These give the TargetAllocator access to the `PodMonitor` and `ServiceMonitor` CRs. It also gives namespace access to the `PodMonitor` and `ServiceMonitor`.
167+
149168
```yaml
150169
apiVersion: rbac.authorization.k8s.io/v1
151170
kind: ClusterRole
@@ -177,19 +196,9 @@ rules:
177196
- nonResourceURLs: ["/metrics"]
178197
verbs: ["get"]
179198
```
180-
These roles can be combined.
181199

182-
A ServiceAccount bound with the above permissions in the namespaces that are to be monitored can then be referenced in
183-
the `targetAllocator:` part of the OpenTelemetryCollector CR.
184-
```yaml
185-
targetAllocator:
186-
enabled: true
187-
serviceAccount: opentelemetry-targetallocator-sa
188-
prometheusCR:
189-
enabled: true
190-
```
191-
**Note**: The Collector part of this same CR *also* has a serviceAccount key which only affects the collector and *not*
192-
the TargetAllocator.
200+
> ✨ The above roles can be combined into a single role.
201+
193202

194203
### Service / Pod monitor endpoint credentials
195204

0 commit comments

Comments
 (0)