0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Alibaba Cloud OSSの代わりにローカルでMinIOを使いたかった(失敗)

Last updated at Posted at 2024-08-16

環境

やりたかったこと

docker-composeでMinIOを立てて、OSSのSDKを使ってアクセスしたかった

やったこと

  1. docker-compose.yamlでMinIOを起動できるようにする
    minioを起動し、init-minioでbucketを作成しています
    virtual-hosted styleを有効にするためにMINIO_DOMAINを指定しています

    docker-compose.yml
    services:
    minio:
        image: minio/minio:latest
        environment:
        MINIO_DOMAIN: localhost
        ports:
        - "9000:9000"
        - "9001:9001"
        volumes:
        - minio-data:/data
        command: server /export --console-address ":9001"
    init-minio:
        image: minio/mc:latest
        depends_on:
        - minio
        entrypoint: >
        /bin/sh -c "
        mc alias set minio http://minio:9000 minioadmin minioadmin;
        mc mb --ignore-existing minio/test;
        mc anonymous set public minio/test;
        "
    
    volumes:
    minio-data:
    
  2. /etc/hostsを設定する
    virtual-hosted styleでtest.localhost:9000などとアクセスされるので設定

    /etc/hosts
    127.0.0.1 *.localhost
    
  3. C#から実行してみる
    SDKのサンプルを元にバケット一覧を取得

    OssClient client = new OssClient("http://localhost:9000", "minioadmin", "minioadmin", conf);
    var buckets = client.ListBuckets();
    
    foreach (var bucket in buckets)
    {
        Console.WriteLine(bucket.Name + ", " + bucket.Location + ", " + bucket.Owner);
    }
    

起きたこと

下記エラーが発生した。使っているSDKのバージョンでは署名バージョンV4をサポートしていなかったため、認証に失敗してしまった。

The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256.

V4に対応したバージョンに更新したが改善されなかった

dotnet add package Aliyun.OSS.SDK.NetCore --version 2.14.1

ソースを見たところ、AWS4-HMAC-SHA256ではなくOSS4-HMAC-SHA256という文字列が使われていた。おそらく基本的な仕組みは同じだが、ヘッダー情報にもOSS4の方で設定されるので、MinIO側でもAWS4として処理できないのだと思われる。

余談

AWSのSDKを使ってAlibabaのOSSにアクセスするサポートはされているみたいだった。MinIOはS3互換だけど、OSS互換ではなかったということか。
AlibabのOSSを使う時もAWSのSDKを使った方がいいかも。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?