Skip to content

Commit 4aa6af8

Browse files
petewallphilk
andauthored
Add OAuth2 support to OTLP output (#938)
Co-authored-by: Phil Kates <[email protected]> Signed-off-by: Pete Wall <[email protected]>
1 parent 5d16003 commit 4aa6af8

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

Diff for: charts/k8s-monitoring-v1/templates/alloy_config/_logs_service_otlp.alloy.txt

+29
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,33 @@ otelcol.auth.bearer "logs_service" {
7676
token = remote.kubernetes.secret.logs_service.data[{{ .bearerToken.tokenKey | quote }}]
7777
}
7878
{{- end }}
79+
{{- else if eq .authMode "oauth2" }}
80+
otelcol.auth.oauth2 "logs_service" {
81+
{{- if eq .oauth2.clientId "" }}
82+
client_id = nonsensitive(remote.kubernetes.secret.logs_service.data[{{ .oauth2.clientIdKey | quote }}])
83+
{{- else }}
84+
client_id = {{ .oauth2.clientId | quote }}
85+
{{- end }}
86+
87+
{{- if eq .oauth2.clientSecretFile "" }}
88+
client_secret = remote.kubernetes.secret.logs_service.data[{{ .oauth2.clientSecretKey | quote }}]
89+
{{- else }}
90+
client_secret_file = {{ .oauth2.clientSecretFile | quote }}
91+
{{- end }}
92+
{{- if .oauth2.endpointParams }}
93+
endpoint_params = {
94+
{{- range $k, $v := .oauth2.endpointParams }}
95+
{{ $k }} = {{ $v | quote }},
96+
{{- end }}
97+
}
98+
{{- end }}
99+
{{- if .oauth2.scopes }}
100+
scopes = {{ .oauth2.scopes | toJson }}
101+
{{- end }}
102+
{{- if .oauth2.tokenURL }}
103+
token_url = {{ required ".Values.oauth2.tokenURL is a required value when .Values.authMode is oauth2" .oauth2.tokenURL | quote }}
104+
{{- end }}
105+
}
79106
{{- end }}
80107
{{ if eq .protocol "otlp" }}
81108
otelcol.exporter.otlp "logs_service" {
@@ -89,6 +116,8 @@ otelcol.exporter.otlphttp "logs_service" {
89116
auth = otelcol.auth.basic.logs_service.handler
90117
{{- else if eq .authMode "bearerToken" }}
91118
auth = otelcol.auth.bearer.logs_service.handler
119+
{{- else if eq .authMode "oauth2" }}
120+
auth = otelcol.auth.oauth2.logs_service.handler
92121
{{- end }}
93122
headers = {
94123
"X-Scope-OrgID" = nonsensitive(remote.kubernetes.secret.logs_service.data[{{ .tenantIdKey | quote }}]),

Diff for: charts/k8s-monitoring-v1/templates/alloy_config/_metrics_service_otlp.alloy.txt

+29
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,33 @@ otelcol.auth.bearer "metrics_service" {
7676
token = remote.kubernetes.secret.metrics_service.data[{{ .bearerToken.tokenKey | quote }}]
7777
}
7878
{{- end }}
79+
{{- else if eq .authMode "oauth2" }}
80+
otelcol.auth.oauth2 "metrics_service" {
81+
{{- if eq .oauth2.clientId "" }}
82+
client_id = nonsensitive(remote.kubernetes.secret.metrics_service.data[{{ .oauth2.clientIdKey | quote }}])
83+
{{- else }}
84+
client_id = {{ .oauth2.clientId | quote }}
85+
{{- end }}
86+
87+
{{- if eq .oauth2.clientSecretFile "" }}
88+
client_secret = remote.kubernetes.secret.metrics_service.data[{{ .oauth2.clientSecretKey | quote }}]
89+
{{- else }}
90+
client_secret_file = {{ .oauth2.clientSecretFile | quote }}
91+
{{- end }}
92+
{{- if .oauth2.endpointParams }}
93+
endpoint_params = {
94+
{{- range $k, $v := .oauth2.endpointParams }}
95+
{{ $k }} = {{ $v | quote }},
96+
{{- end }}
97+
}
98+
{{- end }}
99+
{{- if .oauth2.scopes }}
100+
scopes = {{ .oauth2.scopes | toJson }}
101+
{{- end }}
102+
{{- if .oauth2.tokenURL }}
103+
token_url = {{ required ".Values.oauth2.tokenURL is a required value when .Values.authMode is oauth2" .oauth2.tokenURL | quote }}
104+
{{- end }}
105+
}
79106
{{- end }}
80107
{{ if eq .protocol "otlp" }}
81108
otelcol.exporter.otlp "metrics_service" {
@@ -89,6 +116,8 @@ otelcol.exporter.otlphttp "metrics_service" {
89116
auth = otelcol.auth.basic.metrics_service.handler
90117
{{- else if eq .authMode "bearerToken" }}
91118
auth = otelcol.auth.bearer.metrics_service.handler
119+
{{- else if eq .authMode "oauth2" }}
120+
auth = otelcol.auth.oauth2.metrics_service.handler
92121
{{- end }}
93122
headers = {
94123
"X-Scope-OrgID" = nonsensitive(remote.kubernetes.secret.metrics_service.data[{{ .tenantIdKey | quote }}]),

0 commit comments

Comments
 (0)