【问题标题】:Error when configuring MinIO in C# - The authorization header is malformed; the region is wrong; expecting 'eu-west-2'在 C# 中配置 MinIO 时出错 - 授权标头格式错误;该地区是错误的;期待“eu-west-2”
【发布时间】:2021-10-11 04:37:48
【问题描述】:

我一直在尝试将 MinIO 配置为伪 Amazon S3 提供程序。这样我就可以在开发和测试我的代码时使用 MinIO,但在发布它时仍然使用 Amazon S3。然而,我在尝试使用 MinIO 创建存储桶时遇到的错误是:

Amazon.S3.AmazonS3Exception: The authorization header is malformed; the region is wrong; expecting 'eu-west-2'.

我一直在关注this 教程,我注意到区域端点/ServiceUrl 没有正确设置。这是他们用来创建配置的代码:

var config = new AmazonS3Config 
{ 
    RegionEndpoint = RegionEndpoint.USEast1, // MUST set this before setting ServiceURL and it should match the `MINIO_REGION` environment variable. 
    ServiceURL = "http://localhost:9000", // replace http://localhost:9000 with URL of your MinIO server 
    ForcePathStyle = true // MUST be true to work correctly with MinIO server 
};

看起来不错,但我注意到当设置 RegionEndpoint 时,ServiceUrl 设置为 null,反之亦然。下面来自亚马逊的代码显示了这一点:

    public string ServiceURL
    {
      get => this.serviceURL;
      set
      {
        this.regionEndpoint = (RegionEndpoint) null;
        this.probeForRegionEndpoint = false;
        this.serviceURL = value;
      }
    }

    public RegionEndpoint RegionEndpoint
    {
      get
      {
        if (this.probeForRegionEndpoint)
        {
          this.RegionEndpoint = ClientConfig.GetDefaultRegionEndpoint();
          this.probeForRegionEndpoint = false;
        }
        return this.regionEndpoint;
      }
      set
      {
        this.serviceURL = (string) null;
        this.regionEndpoint = value;
        this.probeForRegionEndpoint = this.regionEndpoint == null;
      }
    }

我几乎可以理解亚马逊的这个设计决定,因为他们的服务 URL 包含区域,例如https://dynamodb.us-west-2.amazonaws.com.

我注意到 MinIO 代码中的注释说“// 必须在设置 ServiceURL 之前设置它,并且它应该与 MINIO_REGION 环境变量匹配。”,但根据我的发现,这不是真的.您不能同时设置 ServiceURL 和 RegionEndpoint。

如果我在 RegionEndpoint 之前指定 ServiceUrl,例如:

var config = new AmazonS3Config 
{ 
    ServiceURL = "http://localhost:9000", // replace http://localhost:9000 with URL of your MinIO server 
    RegionEndpoint = RegionEndpoint.EUWest2, // MUST set this before setting ServiceURL and it should match the `MINIO_REGION` environment variable. 
    ForcePathStyle = true // MUST be true to work correctly with MinIO server 
};

然后我得到:

Amazon.S3.AmazonS3Exception: 'The AWS Access Key Id you provided does not exist in our records.'

大概是因为 ServiceUrl 现在为空,默认情况下它会尝试连接到实际的 Amazon Url,而不是 http://localhost。

但是如果我在 ServiceUrl 之前指定 RegionEndoint,就像第一个示例一样,那么我得到:

Amazon.S3.AmazonS3Exception: The authorization header is malformed; the region is wrong; expecting 'eu-west-2'.

大概是因为 RegionEndpoint 现在为空。

我该怎么办?为什么我是唯一有这个问题的人?

当我连接到 Amazon S3 而不是 MinIO 时,我没有这个问题,因为我不需要指定 RegionEndpoint(因为它是从我在安装和配置 Amazon Web 时输入的详细信息中提取的服务命令行集成 (AWS CLI))或 ServiceUrl(因为它为我解决了所有问题)。

感谢阅读

【问题讨论】:

    标签: c# amazon-s3 minio


    【解决方案1】:

    没有答案,但我们遇到了同样的问题。在 MINIO 软件更新之前一切正常,然后它就坏了。

    我确实注意到,如果您在设置后检查配置,无论您设置什么,该区域仍然为空。

    不,你不是唯一一个。

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,可以通过向AmazonS3Config 实例添加一个名为“AuthenticationRegion”的额外设置来解决它

      var config = new AmazonS3Config 
      { 
          RegionEndpoint = RegionEndpoint.USEast1,
          ServiceURL = "http://localhost:9000",
          ForcePathStyle = true,
          AuthenticationRegion = RegionEndpoint.USEast1.SystemName, // or just "us-east-1"
      };
      

      【讨论】:

      • 我担心我工作的公司在你发布此消息的前一天让我离开,所以我无法验证它是否有效,但谢谢你的回答。
      猜你喜欢
      • 2018-05-19
      • 2021-08-19
      • 2023-03-22
      • 1970-01-01
      • 1970-01-01
      • 2017-03-07
      • 2019-10-29
      • 2021-02-21
      • 2019-11-23
      相关资源
      最近更新 更多