-
Notifications
You must be signed in to change notification settings - Fork 3k
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
{Logging} Redact token headers from SDK HTTP log #17671
Conversation
Logging |
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
*_, external_tenant_tokens = cred.get_all_tokens(*scopes) | ||
# Hard-code scheme to 'Bearer' as _BearerTokenCredentialPolicyBase._update_headers does. | ||
client_kwargs['headers']['x-ms-authorization-auxiliary'] = \ | ||
', '.join("Bearer {}".format(t[1]) for t in external_tenant_tokens) |
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.
Just curious, always Bearer token here?
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.
Yes. The comment at L182 explains that:
# Hard-code scheme to 'Bearer' as _BearerTokenCredentialPolicyBase._update_headers does. |
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.
if isinstance(http_request.body, types.GeneratorType): | ||
_LOGGER.debug("File upload") | ||
return | ||
try: | ||
if isinstance(http_request.body, types.AsyncGeneratorType): | ||
_LOGGER.debug("File upload") | ||
return |
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.
In storage track1 data plane SDK, for such file, it will logging with file size. Could we also support it here?
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.
This SafeNetworkTraceLoggingPolicy
is designed as a generic policy. That's why I am hesitating to apply it to all SDKs (including data-plane SDKs) at the beginning.
If storage data-plane SDK or other data-plane SDKs requires additional/special logic, we may apply SafeNetworkTraceLoggingPolicy
only to ARM and let data-plane SDKs decide what policy they want.
Another solution is to define your own policy and override
azure-cli/src/azure-cli-core/azure/cli/core/commands/client_factory.py
Lines 155 to 156 in 36e3d15
from azure.cli.core.sdk.policies import SafeNetworkTraceLoggingPolicy | |
client_kwargs['logging_policy'] = SafeNetworkTraceLoggingPolicy() |
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.
We could keep current design then.
Resolve #17625
Context
azure-core
1.13.0,Authorization
header is now exposed in DEBUG log (Make NetworkTraceLoggingPolicy show the auth token in plain text azure-sdk-for-python#17424).x-ms-authorization-auxiliary
header (x-ms-authorization-auxiliary header should be redacted azure-sdk-for-python#17271).Changes
Create a custom policy
SafeNetworkTraceLoggingPolicy
to replaceNetworkTraceLoggingPolicy
. It by default redactsAuthorization
andx-ms-authorization-auxiliary
. Any client factory callingprepare_client_kwargs_track2
will have this policy configured.Testing Guide
Any Track 2 mgmt-plane command, like