You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Don't use the top-level `username` and `password` arguments for new configurations as they are deprecated. Use the `client_auth` block for client authentication and the `htpasswd` block for server authentication instead.
41
+
{{< /admonition >}}
42
+
39
43
You can use the following arguments with `otelcol.auth.basic`:
40
44
41
-
| Name | Type | Description | Default | Required |
|`password`|`string`| Password to use for basic authentication requests. || yes |
73
+
|`username`|`string`| Username to use for basic authentication requests. || yes |
74
+
75
+
{{< admonition type="note" >}}
76
+
When you specify both the `client_auth` block and the deprecated top-level `username` and `password` attributes, the `client_auth` block takes precedence and {{< param "PRODUCT_NAME" >}} ignores the top-level attributes for client authentication.
|`file`|`string`| Path to the `htpasswd` file to use for basic authentication requests. |`""`| no |
90
+
|`inline`|`string`| The `htpasswd` file content in inline format. |`""`| no |
91
+
92
+
You can specify either `file`, `inline`, or both.
93
+
When you use `inline`, the format should be `username:password` with each user on a new line.
94
+
95
+
{{< admonition type="note" >}}
96
+
When you specify both the `htpasswd` block and the deprecated top-level `username` and `password` attributes, {{< param "PRODUCT_NAME" >}} automatically appends the deprecated credentials to the `inline` content.
97
+
This allows authentication using credentials from both the `htpasswd` configuration and the deprecated attributes.
98
+
If the same username appears in both the `file` and `inline` content, including appended deprecated credentials, the entry in the `inline` content takes precedence.
99
+
{{< /admonition >}}
100
+
60
101
## Exported fields
61
102
62
103
The following fields are exported and can be referenced by other components:
@@ -73,7 +114,11 @@ The following fields are exported and can be referenced by other components:
73
114
74
115
`otelcol.auth.basic` doesn't expose any component-specific debug information.
75
116
76
-
## Example
117
+
## Examples
118
+
119
+
This section includes examples to help you configure basic authentication for exporters and receivers.
120
+
121
+
### Forward signals to exporters
77
122
78
123
This example configures [`otelcol.exporter.otlp`][otelcol.exporter.otlp] to use basic authentication:
79
124
@@ -91,4 +136,134 @@ otelcol.auth.basic "creds" {
91
136
}
92
137
```
93
138
139
+
### Authenticating requests for receivers
140
+
141
+
These examples show how to perform basic authentication using the `client_auth` block for exporters or the `htpasswd` block for receivers.
142
+
143
+
#### Use client authentication
144
+
145
+
This example configures [`otelcol.exporter.otlp`][otelcol.exporter.otlp] to use basic authentication with a single username and password combination:
146
+
147
+
```alloy
148
+
otelcol.receiver.otlp "example" {
149
+
grpc {
150
+
endpoint = "127.0.0.1:4317"
151
+
}
152
+
153
+
output {
154
+
metrics = [otelcol.exporter.otlp.default.input]
155
+
logs = [otelcol.exporter.otlp.default.input]
156
+
traces = [otelcol.exporter.otlp.default.input]
157
+
}
158
+
}
159
+
160
+
otelcol.exporter.otlp "default" {
161
+
client {
162
+
endpoint = "my-otlp-grpc-server:4317"
163
+
auth = otelcol.auth.basic.creds.handler
164
+
}
165
+
}
166
+
167
+
otelcol.auth.basic "creds" {
168
+
client_auth {
169
+
username = "demo"
170
+
password = sys.env("API_KEY")
171
+
}
172
+
}
173
+
```
174
+
175
+
{{< admonition type="note" >}}
176
+
To migrate from the deprecated `username` and `password` attributes, move them into the `client_auth` block for client authentication.
177
+
{{< /admonition >}}
178
+
179
+
180
+
#### Use htpasswd file
181
+
182
+
This example configures [`otelcol.receiver.otlp`][otelcol.receiver.otlp] to use basic authentication using an `htpasswd` file containing the users to use for basic authentication:
183
+
184
+
```alloy
185
+
otelcol.receiver.otlp "example" {
186
+
grpc {
187
+
endpoint = "127.0.0.1:4317"
188
+
189
+
auth = otelcol.auth.basic.creds.handler
190
+
}
191
+
192
+
output {
193
+
metrics = [otelcol.exporter.debug.default.input]
194
+
logs = [otelcol.exporter.debug.default.input]
195
+
traces = [otelcol.exporter.debug.default.input]
196
+
}
197
+
}
198
+
199
+
otelcol.exporter.debug "default" {}
200
+
201
+
otelcol.auth.basic "creds" {
202
+
htpasswd {
203
+
file = "/etc/alloy/.htpasswd"
204
+
}
205
+
}
206
+
```
207
+
208
+
#### Use htpasswd inline content
209
+
210
+
This example shows how to specify `htpasswd` content directly in the configuration:
211
+
212
+
```alloy
213
+
otelcol.receiver.otlp "example" {
214
+
grpc {
215
+
endpoint = "127.0.0.1:4317"
216
+
217
+
auth = otelcol.auth.basic.creds.handler
218
+
}
219
+
220
+
output {
221
+
metrics = [otelcol.exporter.debug.default.input]
222
+
logs = [otelcol.exporter.debug.default.input]
223
+
traces = [otelcol.exporter.debug.default.input]
224
+
}
225
+
}
226
+
227
+
otelcol.exporter.debug "default" {}
228
+
229
+
otelcol.auth.basic "creds" {
230
+
htpasswd {
231
+
inline = "user1:password1\nuser2:password2"
232
+
}
233
+
}
234
+
```
235
+
236
+
{{< admonition type="note" >}}
237
+
To make the migration from the deprecated `username` and `password` attributes easier, you can specify both the deprecated attributes and the `htpasswd` block in the same configuration.
238
+
{{< param "PRODUCT_NAME" >}} appends the deprecated attributes to the `htpasswd` content.
0 commit comments