question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use proxy with Google.Cloud.Storage.V1

See original GitHub issue

Hello team,

By design in our “on prem” datacenter we need to use a proxy to go though internet. We have been able to upload some file to our GCS without any proxy but we are stuck to upload a file when we need to use a proxy.

We use:

  • .NET Core 2
  • Windows Server 2016 to run our website

Where should we define the proxy in the API ? We didn’t find any way to do it ! Is it even possible ? We tried several ways but without success.

Code is very basic :

using (StreamReader r = new StreamReader("xxxx.json"))
            {
                string jsonFromStream = r.ReadToEnd();
                json = JsonConvert.DeserializeObject(jsonFromStream);
            }

            var credential = GoogleCredential.FromJson(json.ToString());
            var storageClient = StorageClient.Create(credential);
            storageClient.UploadObject("lr-xxxx-yyyy", "blogexample/image.png", null, image);

Thanks, Alexandre

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:24 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
amanda-tarafacommented, Sep 29, 2021

@liiri Google.Cloud.Logging.V2 works over gRPC not over HTTP so the way to set a proxy is different. There are two steps:

  • For the credential, you use code just like the one above, i.e. create the credential with the HttpClientFactory that has a proxy set.

  • Then, create the service client as follows (which will make all auth related requests go through the proxy):

              GoogleCredential proxiedCredential = ...; // Similar to above
              LoggingServiceV2ClientBuilder builder = new LoggingServiceV2ClientBuilder
              {
                  TokenAccessMethod = (proxiedCredential as ITokenAccess).GetAccessTokenForRequestAsync
              };
              var loggingClient = builder.Build();
             // Use loggingClient normally.
    
  • For gRPC requests (i.e. the actual logging requests) to use a proxy, then, you need to look at what Grpc.Core requieres. And that is to set any of a number of environment variables as described on the first point in gRPC environment variables docs. Also you might want to take a look at issues like https://github.com/grpc/grpc/issues/13323 and https://github.com/grpc/grpc/issues/12815 which are related. If you cannot make this part work, It’s better if you ask directly on https://github.com/grpc/grpc as we just rely on gRPC’s implementation for proxy setting.

2reactions
amanda-tarafacommented, Sep 29, 2021

For posterity, we now have a better way to set a proxy for Google.Cloud.Storage.V1. If you are using Google.Cloud.Storage.V1 v3.5.0 (which is the latest at the moment of writing this) or an older version, you need to add an explicit dependency on Google.Api.Gax.Rest version 3.4.0.

IWebProxy proxy = ...;
Google.Apis.Http.HttpClientFactory factory = HttpClientFactory.ForProxy(proxy);

var scopes = new string[] { ... };
var credential= GoogleCredential.FromFile(sa_file); //Or any other way of obtaining the a Google credential
credential = credential.CreateScoped(scopes).CreateWithHttpClientFactory(factory);

var clientBuilder = new StorageClientBuilder
{
    Credential = credential,
    // All HTTP client instances for API calls will be obtained from this factory
    HttpClientFactory = factory
}

var client = clientBuilder.Build();

// Use client to perform Storage operations normally.
Read more comments on GitHub >

github_iconTop Results From Across the Web

Use target proxies | Load Balancing
Target proxies terminate incoming connections from clients and create new connections from the load balancer to the backends. Target proxies are referenced ...
Read more >
Cloud Storage authentication
For more information about accessing Cloud Storage through a proxy server, see the Troubleshooting topic. User account credentials. Use user account credentials ...
Read more >
Proxying requests to google cloud storage using Hadoop GCS ...
gs.storage.root.url and then run the command below. This will enable all the storage requests to flow through the proxy but the auth requests ......
Read more >
Re: [google-cloud-sdk] access my gcloud through proxy
I download google-cloud-sdk and setup to access my cloud storage through proxy. According to some experience from internet. it's work fine when I...
Read more >
Reverse proxy Google Cloud storage to authenticate ...
My main concern with this approach is that those endpoints would have a lot of traffic and the API reverse proxy wouldn't be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found