2

I have a project setup with a node.js api and a minio service with docker compose:

  app:
    image: node
#   ...
  minio:
    image: minio/minio
    volumes:
      - ./data:/data
    ports:
      - '9000:9000'
      - '9001:9001'
    command: server --console-address ":9001" /data

In my node script I run the following code:

import * as Minio from 'minio';

const minioClient = new Minio.Client({
  endPoint: 'minio',
  port: 9000,
  useSSL: false,
  accessKey: 'access',
  secretKey: 'secret',
});

minioClient.presignedUrl(
  'GET',
  'my-bucket',
  'test.txt',
  function (err, presignedUrl) {
    if (err) {
      return console.error(err);
    }
    console.log(presignedUrl);
  }
);

The result is a url like this:
http://minio:9000/files-c000000000000000000000000/test.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=u7gk0nycOepyDAWV%2F20230314%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230314T131440Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=315c9184a40009ff5af0815e597214b6422650e240d186979295c5188cbb2885

In my dev environment I need the url to use localhost instead of minio like this:\

http://localhost:9000/files-c000000000000000000000000/test1678799680428.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=u7gk0nycOepyDAWV%2F20230314%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230314T131440Z&X-Amz-Expires=604800&X-Amz-SignedHeaders=host&X-Amz-Signature=315c9184a40009ff5af0815e597214b6422650e240d186979295c5188cbb2885

What I have tried so far (and did not work):

  • Simple string replace for the hostname => The hash is only valid for the hostname the url is created with
  • Set the endPoint in Minio.Client to localhost. => The api could not connect to minIO any more.
  • Set environment variables MINIO_SERVER_URL, MINIO_BROWSER_REDIRECT_URL and MINIO_DOMAIN with localhost => Same Error

Workaround

A Simple workaround is to manually redirect the docker service name minio to 127.0.0.1. But I am searching for a solution without this workaround.

CimChd
  • 191
  • 6

1 Answers1

1

MINIO_SERVER_URL must be set with the hostname pointing to API port.

MINIO_SERVER_URL: http://s3-api-minio:9010

also check the hosts file for the resolution of the address

cat /etc/hosts
127.0.1.1 s3-console-minio s3-api-minio

This would display the name set in the share url. at this point you could use curl and verify within the host.

Result example:

http://s3-api-minio:9010/docker-bucket/test_scroll_tabs.txt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=DUKZ37YDZ4HDO404OUX1%2F20230315%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20230315T160705Z&X-Amz-Expires=604800&X-Amz-Security-Token=eyJhbGciOiJIUzUxMiIsInR5cCI6IkpXVCJ9.eyJhY2Nlc3NLZXkiOiJEVUtaMzdZRFo0SERPNDA0T1VYMSIsImV4cCI6MTY3ODkzODgwOCwicGFyZW50IjoibWluaW8ifQ.r36Y_lohR_R0KSO8EXbKLMO9OWfFxliXvFT3FNqEtfOhXMYgCHQUmUoJu-Z0H8tyeK0ostXyqONpvgufmgWH4A&X-Amz-SignedHeaders=host&versionId=null&X-Amz-Signature=3ccf8200900dd1c9a0fcfd04851748cf10916e909f0461ba08b3231079acab79

Note: However, to make it accessible to others over the network, host entry must be resolvable

Prakash S
  • 1,695
  • 3
  • 11
  • 20
  • Thanks for your reply. This would work but it is not what I want. I want no dns entry for the host. I just want to use localhost (or 127.0.0.1) in the generated urls. – CimChd Mar 16 '23 at 17:14
  • MINIO_SERVER_URL: http://localhost:9010 or MINIO_SERVER_URL: http://127.0.0.1:9010 would also work. as minio listens on all interfaces – Prakash S Mar 17 '23 at 07:14
  • No doesn't work. The problem is the generated url, not that I can't reach the minio server. – CimChd Mar 21 '23 at 14:58