Skip to content

Commit a286349

Browse files
[extension/headersetter] Add support for chaining with other auth extensions (#44120)
#### Description This PR adds support for chaining the `headersetter` extension with other authentication extensions (e.g., OAuth2). It introduces a new configuration parameter `additional_auth` in headersetter and ensures that the additional auth extension is started first using the Dependent interface. #### Link to tracking issue Fixes [#43935](#43935) --------- Signed-off-by: Kushal Shukla <[email protected]>
1 parent 0a1f310 commit a286349

File tree

9 files changed

+551
-16
lines changed

9 files changed

+551
-16
lines changed

.chloggen/chaining.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. receiver/filelog)
7+
component: extension/headers_setter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: "Add support for chaining with other auth extensions via `additional_auth` configuration parameter. This allows combining multiple authentication methods, such as OAuth2 for bearer token authentication and custom headers for additional metadata."
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [43797]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: |
19+
The `additional_auth` parameter enables the `headers_setter` extension to work in conjunction
20+
with other authentication extensions like `oauth2client`. The additional auth extension is called
21+
first to apply its authentication, then headers_setter adds its configured headers on top.
22+
23+
# If your change doesn't affect end users or the exported elements of any package,
24+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
25+
# Optional: The change log or logs in which this entry should be included.
26+
# e.g. '[user]' or '[user, api]'
27+
# Include 'user' if the change is relevant to end users.
28+
# Include 'api' if there is a change to a library API.
29+
# Default: '[user]'
30+
change_logs: [user]

extension/headerssetterextension/README.md

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ header to the value extracted from the context.
2323

2424
## Configuration
2525

26-
The following settings are required:
26+
The following settings are available:
27+
28+
- `additional_auth` (Optional): The ID of another auth extension to chain with.
29+
When specified, this extension will call the additional auth extension first,
30+
then apply its own headers on top. This allows combining multiple authentication
31+
methods, such as OAuth2 for authorization and custom headers for additional metadata.
2732

2833
- `headers`: a list of header configuration objects that specify headers and
2934
their value sources. Each configuration object has the following properties:
@@ -100,6 +105,65 @@ service:
100105
exporters: [ loki ]
101106
```
102107
108+
## Chaining with other Auth Extensions
109+
110+
The `headers_setter` extension can be chained with another authentication extension
111+
using the `additional_auth` parameter. This allows combining multiple authentication
112+
methods, such as OAuth2 for bearer token authentication and custom headers for
113+
additional metadata or routing information.
114+
115+
### Example: Combining OAuth2 and Custom Headers
116+
117+
```yaml
118+
extensions:
119+
oauth2client:
120+
client_id: someclientid
121+
client_secret: someclientsecret
122+
token_url: https://example.com/oauth2/default/v1/token
123+
scopes: ["api.metrics"]
124+
# The timeout parameter is optional
125+
timeout: 2s
126+
127+
headers_setter:
128+
# Chain with the oauth2client extension
129+
additional_auth: oauth2client
130+
headers:
131+
- key: X-Scope-OrgID
132+
value: acme-tenant
133+
- key: X-Custom-Header
134+
from_context: custom_metadata
135+
136+
receivers:
137+
otlp:
138+
protocols:
139+
http:
140+
include_metadata: true
141+
142+
exporters:
143+
prometheusremotewrite:
144+
endpoint: https://prometheus.example.com/api/v1/write
145+
auth:
146+
# Use headers_setter as the authenticator
147+
# This will apply both OAuth2 and custom headers
148+
authenticator: headers_setter
149+
150+
service:
151+
extensions: [oauth2client, headers_setter]
152+
pipelines:
153+
metrics:
154+
receivers: [otlp]
155+
exporters: [prometheusremotewrite]
156+
```
157+
158+
In this configuration:
159+
1. The `oauth2client` extension provides OAuth2 bearer token authentication
160+
2. The `headers_setter` extension adds custom headers on top of the OAuth2 authentication
161+
3. When the exporter sends data, both authentication methods are applied:
162+
- OAuth2 adds the `Authorization: Bearer <token>` header
163+
- Headers setter adds `X-Scope-OrgID` and `X-Custom-Header` headers
164+
4. The collector ensures the `oauth2client` extension starts before `headers_setter`
165+
due to the dependency relationship
166+
103167
[batch-processor]: https://github.com/open-telemetry/opentelemetry-collector/tree/main/processor/batchprocessor/README.md
104168
[batch-processor-preserve-metadata]: https://github.com/open-telemetry/opentelemetry-collector/tree/main/processor/batchprocessor/README.md#batching-and-client-metadata
105169

0 commit comments

Comments
 (0)