@@ -44,3 +44,98 @@ https://simple-nifi-node-default-0.simple-nifi-node-default.<namespace>.svc.clus
4444```
4545
4646IMPORTANT: If NiFi is configured to do any user authentication, requests to the metric endpoint must be authenticated and authorized.
47+
48+ === Authentication with NiFi `2.x.x`
49+
50+ [IMPORTANT]
51+ ===
52+ The NiFi metrics endpoints are behind a strong authentication mechanism which require credentials for each individual pod.
53+ ===
54+
55+ To authenticate, you can use a bearer token created by your NiFi instance e.g.
56+
57+ [source,bash]
58+ ----
59+ curl -X POST https://simple-nifi-node-default-0.simple-nifi-node-default.<namespace>.svc.cluster.local:8443/nifi-api/access/token -d 'username=<user>&password=<password>' -k
60+ ----
61+
62+ where `-k` equals `verify=false` to allow self-signed certificates. The reply is your bearer token.
63+
64+ The following example shows how to configure the Prometheus scraper to use the bearer token to authenticate against a NiFi pod.
65+
66+ [source,yaml]
67+ ----
68+ ---
69+ authorization: <1>
70+ type: Bearer
71+ credentials: "<Bearer Token>" <2>
72+ tls_config:
73+ insecure_skip_verify: true
74+ static_configs:
75+ - targets:
76+ - '<pod>.<statefulset>.svc.cluster.local:8443' <3>
77+ metrics_path: '/nifi-api/flow/metrics/prometheus'
78+ scheme: https
79+ ----
80+ <1> Use the `authorization` property instead if the `basic_auth`.
81+ <2> Add the previously obtained token here.
82+ <3> Static targets only scrapes one pod.
83+
84+ or use it in a NiFi secret which should look like
85+ [source,yaml]
86+ ----
87+ ---
88+ apiVersion: v1
89+ kind: Secret
90+ metadata:
91+ name: nifi-authorization-secret
92+ type: Opaque
93+ stringData:
94+ nifi_token: "<Bearer_token>"
95+ ----
96+
97+ If you want to use a `ServiceMonitor` you'd need to configure it as follows:
98+ [source,yaml]
99+ ----
100+ ---
101+ apiVersion: monitoring.coreos.com/v1
102+ kind: ServiceMonitor
103+ metadata:
104+ name: scrape-nifi2
105+ labels:
106+ stackable.tech/vendor: Stackable
107+ release: prometheus
108+ spec:
109+ endpoints:
110+ - port: https
111+ path: 'nifi-api/flow/metrics/prometheus'
112+ scheme: https
113+ interval: 5s
114+ tlsConfig:
115+ insecureSkipVerify: true
116+ authorization:
117+ credentials: <1>
118+ key: "nifi_token"
119+ name: "nifi-authorization-secret"
120+ optional: false
121+ type: "Bearer"
122+ relabelings: <2>
123+ - sourceLabels:
124+ - __meta_kubernetes_pod_name
125+ - __meta_kubernetes_service_name
126+ - __meta_kubernetes_namespace
127+ - __meta_kubernetes_pod_container_port_number
128+ targetLabel: __address__
129+ replacement: ${1}.${2}.${3}.svc.cluster.local:${4}
130+ regex: (.+);(.+?)(?:-metrics)?;(.+);(.+)
131+ selector:
132+ matchLabels:
133+ prometheus.io/scrape: "true"
134+ namespaceSelector:
135+ any: true
136+ jobLabel: app.kubernetes.io/instance
137+ ----
138+ <1> Authorization via Bearer Token stored in a secret
139+ <2> Relabel \\__address__ to be a FQDN rather then the IP-Address of target pod
140+
141+ NOTE: As of xref:listener-operator:listener.adoc[Listener] integration, SDP exposes a Service with `-metrics` thus we need to regex this suffix.
0 commit comments