-
Notifications
You must be signed in to change notification settings - Fork 651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decode URL-encoded headers in environment vars #2312
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
The [opentelemetry-specification](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/protocol/exporter.md#specifying-headers-via-environment-variables) wants `OTEL_EXPORTER_OTLP_HEADERS` to conform to the [Baggage HTTP Header Format](https://github.com/w3c/baggage/blob/main/baggage/HTTP_HEADER_FORMAT.md). To effectively use the headers from `OTEL_EXPORTER_OTLP_HEADERS` for things like authentication (a common use case) the values need to be decoded. Given a header like this: ``` export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic base64" ``` The code prior to this commit would reject the header for containing whitespace mid-value. If the header is modified to this: ``` export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic%20base64" ``` The code prior to this commit would send the header as `Authorization: Basic%20base64`, which will be rejected upstream. This change applies `urllib.parse.unquote` to header **names** and **values**, based on precedent set by the following libraries: - [opentelemetry-go](https://github.com/open-telemetry/opentelemetry-go) - [opentelemetry-js](https://github.com/open-telemetry/opentelemetry-js) - [opentelemetry-ruby](https://github.com/open-telemetry/opentelemetry-ruby)
mattoberle
force-pushed
the
issue/2248
branch
from
December 8, 2021 00:19
85a1288
to
17c5f2a
Compare
Unquoting header keys and values **after** calling `str.strip()` opened the possibility for user encoding errors where a header contained invalid whitespace. Unquoting **before** `str.strip()` aligns `opentelemetry-python` with other `opentelemetry-{lang}` libraries that implemenent URL decoding.
The HTTP exporter allows headers to be provided as `Dict[str, str]`. The gRPC exporter required headers to be `Sequence[Tuple[str, str]]`. This commit enables the `Dict[str, str]` format for gRPC.
srikanthccv
approved these changes
Dec 9, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
lzchen
reviewed
Dec 10, 2021
...pentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py
Outdated
Show resolved
Hide resolved
lzchen
reviewed
Dec 10, 2021
lzchen
reviewed
Dec 10, 2021
...pentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py
Outdated
Show resolved
Hide resolved
owais
approved these changes
Dec 25, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The opentelemetry-specification wants
OTEL_EXPORTER_OTLP_HEADERS
to conform to the Baggage HTTP Header Format.To effectively use the headers from
OTEL_EXPORTER_OTLP_HEADERS
for things like authentication (a common use case) the values need to be decoded.Given a header like this:
The code prior to this commit would reject the header for containing white space mid-value.
If the header is modified to this:
The code prior to this commit would send the header as
Authorization: Basic%20base64
, which will be rejected upstream.This change applies
urllib.parse.unquote
to header names and values, based on precedent set by the following libraries:Fixes #2248 1
1 This PR does not restore previous functionality (where the header
str
could be provided with spaces in the values), but it does provide the ability to provide a headerstr
with encoded spaces. I also added the ability to passheaders
asDict[str, str]
to address both issues raised in #2248. These can be split into individual PRs if needed.Type of change
Please delete options that are not relevant.
How Has This Been Tested?
re.py
Does This PR Require a Contrib Repo Change?
Checklist: