Skip to content
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

WithProxy is ignored #658

Closed
chrisbecke opened this issue Jun 29, 2022 · 5 comments
Closed

WithProxy is ignored #658

chrisbecke opened this issue Jun 29, 2022 · 5 comments
Assignees

Comments

@chrisbecke
Copy link

chrisbecke commented Jun 29, 2022

Issue

We upgraded our own project to the net6.0 framework, and that included upgrading the minio-dotnet SDK to version 4.0.4 As a consequence of this update the Minio SDK now seems to be ignoring .WithProxy().

To get minio-dotnet to route traffic via a proxy it now seems necessary to use WithHttpClient.

To Reproduce

  • Create a new .net6 console application using Visual Studio.
  • Enable Docker Compose Support, and add a minio entry as per the docker-compose below.
  • Create a reverse proxy using express.js, and add that to the compose.
  • Run the project and see that .WithProxy is never used, but .WithHttpClient() does route through the proxy.

docker-compose.yml

version: '3.4'

services:
  copytest:
    image: ${DOCKER_REGISTRY-}copytest
    build:
      context: .
      dockerfile: CopyTest/Dockerfile
    depends_on:
    - proxy

  proxy:
    image: ${DOCKER_REGISTRY-}proxy
    build:
      context: proxy
      target: dev
    volumes:
    - ./proxy:/src
    - /src/node_modules
    depends_on:
    - minio

  minio:
    image: minio/minio:latest
    command: server /data --console-address :9001
    volumes:
    - /data
    ports:
    - 8080:9001

  mc:
    image: minio/mc:latest
    profiles: [ "tools" ]
    working_dir: /work
    volumes:
    - ./.mc:/root/.mc
    - ./:/work

Program.cs

using Minio;
using Minio.DataModel;
using System.Net;

var minio = new MinioClient()
                        .WithCredentials("minioadmin","minioadmin")
                        .WithEndpoint("minio:9000")
//                        .WithHttpClient( new HttpClient(new HttpClientHandler(){ Proxy = new WebProxy("proxy", 3000) }))
                        .WithProxy(new WebProxy("proxy", 3000))
                        .Build();

string fromBucketName = "uploads";
string fromObjectName = "test.txt";
string destBucketName = "staging";
string destObjectName = "test.txt";
ServerSideEncryption sseSrc = null;
ServerSideEncryption sseDest = null;

var cpSrcArgs = new CopySourceObjectArgs()
    .WithBucket(fromBucketName)
    .WithObject(fromObjectName)
    .WithServerSideEncryption(sseSrc);
var cpArgs = new CopyObjectArgs()
    .WithBucket(destBucketName)
    .WithObject(destObjectName)
    .WithCopyObjectSource(cpSrcArgs)
    .WithServerSideEncryption(sseDest);

await minio.CopyObjectAsync(cpArgs);

proxy/index.js

var express  = require('express');
var app      = express();
var httpProxy = require('http-proxy');
var apiProxy = httpProxy.createProxyServer();
var server = 'http://minio:9000';
 
app.all("/*", function(req, res) {
    console.log('redirecting to minio');
    apiProxy.web(req, res, {target: server});
});

app.listen(3000);

console.log('proxy listening');

proxy/Dockerfile

FROM node:14-alpine as base

WORKDIR /src
COPY package*.json /
EXPOSE 3000

FROM base as dev
ENV NODE_ENV=development
RUN npm install -g nodemon && npm install
COPY . /
CMD ["nodemon", "bin/www"]

In summary these were the steps I used to create the projects and run the test scenarios.

dotnet new CopyTest
dotnet add CopyTest package minio-dotnet
# Edit the generated Program.cs and paste in the above code now
mkdir proxy
cd proxy
npm init
npm install express
npm install http-proxy
# Add the index.js and Dockerfile now
cd ..
docker compose build proxy
docker compose up proxy
# Switch to a second terminal
docker compose run --rm mc alias set minio http://minio9000 minioadmin minioadmin
docker compose run --rm mc mb minio/uploads
docker compose run --rm mc mb minio/staging
docker compose run --rm mc cp docker-compose.yml minio/uploads/test.txt
docker compose build copytest
docker compose run copytest
# edit Program.cs to switch from WithProxy to WithHttpclient
docker compose build copytest
docker compose run copytest
@ebozduman
Copy link
Collaborator

@chrisbecke ,

This issue must have been fixed by PR #641 (Reuse HttpClient and fix the wrong TLS and Proxy settings during MinioClient creation).
Please let us know if you still see the issue, or close it if fixed.

@ebozduman ebozduman self-assigned this Aug 9, 2022
@ebozduman ebozduman added the fixed label Aug 9, 2022
@alexwlsnr
Copy link

I'm pretty sure this PR doesn't fix the issue @chrisbecke reported. I also experienced this following the documentation. For example:

 var client = new MinioClient()
    .WithEndpoint(this.Settings.S3Endpoint)
    .WithCredentials(
        this.Settings.S3AccessKey,
        this.Settings.S3SecretKey)
    .WithProxy(new WebProxy(this.Settings.HttpProxyUri))
    .WithSSL();

Doesn't apply the proxy settings. Directly supplying a HttpClient with a proxy set does appear to work:

var httpClientHandler = new HttpClientHandler()
{
    Proxy = new WebProxy(this.Settings.HttpProxyUri)
};

var client = new MinioClient()
    .WithEndpoint(this.Settings.S3Endpoint)
    .WithCredentials(
        this.Settings.S3AccessKey,
        this.Settings.S3SecretKey)
    .WithProxy(new WebProxy(this.Settings.HttpProxyUri))
    .WithHttpClient(new HttpClient(httpClientHandler));
    .WithSSL();

Which is a valid workaround, but the docs suggest setting the proxy alone should be effective.

@ebozduman
Copy link
Collaborator

Thank you @alexwlsnr
I'll look into it.

@ebozduman
Copy link
Collaborator

@chrisbecke ,
Could you provide the name of the docker image to reproduce the issue and test the fix I have?
or @alexwlsnr
Could you provide the information about your proxy server, what kind it is, its config information etc to reproduce the issue?
The issue cannot reproduced with a regular nginx reverse proxy as it takes care of traffic in both directions.

ebozduman added a commit to ebozduman/minio-dotnet that referenced this issue Aug 23, 2022
ebozduman pushed a commit that referenced this issue Aug 30, 2022
* Created when there is still no HttpClient available during Build().

* WithHttpClient(HttpClient) adds parameter bool disposeHttpClient = false to indicate whether to dispose httpClient.

* Fix unit tests

* run "cleanupcode minio.sln"
@harshavardhana
Copy link
Member

Fixed by #683

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants