-
Notifications
You must be signed in to change notification settings - Fork 173
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
-Proxy seems to be ignored on Get-MgPolicyClaimMappingPolicy #2310
Comments
Hi drdamour, I don't see a -Proxy parameter for this cmdlet: I don't recall seeing it for any of the Graph SDK cmdlets I've encountered. As for how to get the Graph SDK working with a proxy, the .NET proxy call you're using looks similar (but not the same) as the one I'm using:
That being said, I typically run PowerShell 5.1 (as opposed to 7.3, which you're using), so the above may not actually be a fix. Perhaps you might be able to use Is this problem specific to the Graph SDK? From what I'm reading, you're trying to trace the traffic yourself so that you can see the calls being made yourself. Can you see the packets going out via Fiddler? If not, this seems less of a Graph SDK problem, and more of a request on how to use Fiddler with PowerShell. Not sure whether it's the right tool, but have you considered something like WireShark, or |
@SeniorConsulting it's output in the help as an available switch [system.net.webrequest]::defaultwebproxy is for .net and not .net core generally, but i did try that as well and it did not work either. also tried winhttp set proxy and that didn't work either. yes i i see traffic with Invoke-WebRequest so it's not a problem with fiddler, this powershell seems to be ignoring those common proxy configurations. it's definitely a problem constrained to the graph powershell commands. |
there's def special behaviour in this regarding ps core vs win ps
in pscore it just passes through but in win ps it forces HttpClientHandler. NOTE: doesn't seem like proxy is passed in either case...that's weird.... tracing pscore behaviour through entry is to https://github.com/microsoftgraph/msgraph-sdk-dotnet-core/blob/1c0eb8d0a63216a340ec2cf494a2f4d08cc1eb87/src/Microsoft.Graph.Core/Requests/GraphClientFactory.cs#L55 proxy defaults to null (so that would explain why -Proxy doesn't seem to be doing anything...maybe it's support is on a roadmap. that ends up going through a bunch of platofrm specific if blocks and looks like it selects SocketsHttpHandler here https://github.com/microsoftgraph/msgraph-sdk-dotnet-core/blob/1c0eb8d0a63216a340ec2cf494a2f4d08cc1eb87/src/Microsoft.Graph.Core/Requests/GraphClientFactory.cs#L231 which explains why none of the global proxy configs work. Also looks like in win ps it'll use WinHttpHandler...which should respect winhttp set proxy Proxy is mentioned in a LOT of docs as being supported throughout this repo cf https://github.com/search?q=repo%3Amicrosoftgraph%2Fmsgraph-sdk-powershell%20proxy&type=code
|
Right you are. It seems like you've delved far further into this one than I have. I'll leave it to the actual devs to respond :) Thanks for the detailed notes. |
Thanks for bringing this to our attention and thank you SeniorConsulting for the insights. The recommended way of using the commands behind a proxy is via global proxy settings, which is honored by the underlaying
$proxy='http://localhost:8888'
$env:HTTP_PROXY=$proxy
$env:HTTPS_PROXY=$proxy
Connect-MgGraph
Get-MgPolicyClaimMappingPolicy
[system.net.webrequest]::defaultwebproxy = new-object system.net.webproxy('http://localhost:8888')
[system.net.webrequest]::defaultwebproxy.credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
[system.net.webrequest]::defaultwebproxy.BypassProxyOnLocal = $true
# or
# Use the system proxy settings (internet options).
Connect-MgGraph
Get-MgPolicyClaimMappingPolicy Both options work as expected in my test environment. See https://woshub.com/using-powershell-behind-a-proxy/ for more details. The |
@peombwa as stated in original issue i tried the suggested approach for powershell core 7.x, but it did not work as the code doesnt seem to use httpclient. did u attempt this suggestion and see success? |
@drdamour, all the commands use Yes, I tested both approaches and they work as expected:
Please verify that your proxy server is configured correctly (filter rules etc.). |
@peombwa weird...i'm not having success with proxy (fiddler) shut down request succeeds ( expected it wouldn't), with it on no capture request succeeds do you have a log level enabled that i don't? those dark blueish stuff. u sure it uses HttpClient, it sure looks like it used SocketsHttpHandler around here https://github.com/microsoftgraph/msgraph-sdk-dotnet-core/blob/1c0eb8d0a63216a340ec2cf494a2f4d08cc1eb87/src/Microsoft.Graph.Core/Requests/GraphClientFactory.cs#L231 |
I'm also not sure why it isn't working for you. Are you sure the provided port isn't forwarding requests to the internet? Please verify that your machine's proxy is configured correctly. I'm using https://mitmproxy.org to test the proxy. It shows the proxy working. Other customers have also had success using the proxy via the global settings.
|
Yes im sure many other powershell commands are appearing in fiddler proxy, but mg cmdlets seem to be a special case. will try on a diff machine and have peers try. what do i mean exactly by “machines proxy is configured correctly “? also u didnt mention about debug level i think |
Also im confused if this is leveraging httpclient in the way u describe surely [System.Net.Http.HttpClient]::DefaultProxy = New-Object System.Net.WebProxy('http://localhost:8888') should work…but it also does not on my system. |
Thanks for reporting the bug. Please ensure you've gone through the following checklist before opening an issue:
Describe the bug
Have fiddler listening on 8888 locally, but -Proxy isn't doing anything different
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Expect to see the http request/response in fiddler
Debug Output
Module Version
Environment Data
Screenshots
N/A
Additional context
tried common proxy configs like $Env:HTTPS_PROXY and
[System.Net.Http.HttpClient]::DefaultProxy = New-Object System.Net.WebProxy('http://localhost:8888')
as well. Also tried with -ProxyUseDefaultCredentials switchThe text was updated successfully, but these errors were encountered: