1

Trying to connect to a minio server using the following code:

var AWS = require('aws-sdk');

var s3  = new AWS.S3({
          accessKeyId: 'minio' ,
          secretAccessKey: 'minio123' ,
          endpoint: 'https://minio.dev' ,
          s3ForcePathStyle: true, // needed with minio?
          signatureVersion: 'v4',
          sslEnabled: false,
          rejectUnauthorized: false
});

// putObject operation.

var params = {Bucket: 'documents', Key: 'testobject', Body: 'Hello from MinIO!!'};

s3.putObject(params, function(err, data) {
      if (err)
       console.log(err)
      else   
       console.log("Successfully uploaded data to documents/testobject");
});

// getObject operation.

var params = {Bucket: 'documents', Key: 'testobject'};

var file = require('fs').createWriteStream('/tmp/mykey');

s3.getObject(params).
on('httpData', function(chunk) { file.write(chunk); }).
on('httpDone', function() { file.end(); }).
send();

I get the following error:

{ Error: unable to verify the first certificate
    at TLSSocket.onConnectSecure (_tls_wrap.js:1051:34)
    at TLSSocket.emit (events.js:189:13)
    at TLSSocket.EventEmitter.emit (domain.js:441:20)
    at TLSSocket._finishInit (_tls_wrap.js:633:8)
  message: 'unable to verify the first certificate',
  code: 'NetworkingError',
  region: 'us-east-1',
  hostname: 'minio.dev',
  retryable: true,
  time: 2019-07-11T23:38:45.382Z }

I have passed the options "sslEnabled: false", but this doesn't change anything. I've also tried to disable SSL on the node side and it also fails to change the behavior.

Does anybody have any ideas on how to ignore the self signed cert error? (if that is the issue, which I believe it is)

2
  • Do you resolve this problem? Commented Nov 22, 2019 at 12:35
  • No, I never figured out the issue. Commented Nov 24, 2019 at 6:02

1 Answer 1

0
const AWS = require('aws-sdk');
const https = require('https');

// Allow use with Minio
AWS.NodeHttpClient.sslAgent = new https.Agent({ rejectUnauthorized: process.env.NODE_TLS_REJECT_UNAUTHORIZED !== '0' });

// the rest of the code snippet remains unchanged

rejectUnauthorized: false is the key. In this example, I've tied it to the existence of a commonly used environment variable that toggles the behavior in the request module. AWS SDK doesn't use it for its API, but reusing it seemed appropriate since it performed the same function.

Now if NODE_TLS_REJECT_UNAUTHORIZED=0 is set, the whole Node process including the AWS SDK will work with mocked HTTPS endpoints.

WARNING: Only use this in a development environment, such as mocking public services on your local workstation. It can leave you open to Man-In-The-Middle attacks!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.