【问题标题】:Authentication Failure when connecting to Azurite连接到 Azurite 时验证失败
【发布时间】:2020-02-06 10:25:31
【问题描述】:

我在 docker-compose 中使用 Azurite 进行本地开发。我有一个使用 Java Azure SDK 与之对话的简单应用程序。我正在尝试使用默认的 Azurite 连接字符串 DefaultEndpointsProtocol=https;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw== 进行连接,但是当我尝试连接时出现身份验证错误:

app      | RequestId:648770d1-301e-00a3-28d6-dcfab7000000
app      | Time:2020-02-06T10:19:10.6959018Z</Message><AuthenticationErrorDetail>The MAC signature found in the HTTP request 'vSVMXMpgTMISc9Fgx2bu0kg7uu0duhmdn6dllfc4r1g=' is not the same as any computed signature. Server used following string to sign: 'GET
app      |
app      |
app      |
app      |
app      |
app      | Thu, 06 Feb 2020 10:19:09 GMT
app      |
app      |
app      |
app      |
app      |
app      | x-ms-client-request-id:4bd883d4-229a-4dec-bf6f-221f3636dccf
app      | x-ms-version:2019-02-02
app      | /devstoreaccount1/
app      | comp:list'.</AuthenticationErrorDetail></Error>"; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Status code 403, "<?xml version="1.0" encoding="utf-8"?><Error><Code>AuthenticationFailed</Code><Message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
app      | RequestId:648770d1-301e-00a3-28d6-dcfab7000000
app      | Time:2020-02-06T10:19:10.6959018Z</Message><AuthenticationErrorDetail>The MAC signature found in the HTTP request 'vSVMXMpgTMISc9Fgx2bu0kg7uu0duhmdn6dllfc4r1g=' is not the same as any computed signature. Server used following string to sign: 'GET
app      |
app      |
app      |
app      |
app      |
app      | Thu, 06 Feb 2020 10:19:09 GMT
app      |
app      |
app      |
app      |
app      |
app      | x-ms-client-request-id:4bd883d4-229a-4dec-bf6f-221f3636dccf
app      | x-ms-version:2019-02-02
app      | /devstoreaccount1/
app      | comp:list'.</AuthenticationErrorDetail></Error>"]

我不确定是什么问题,我还没有在网上找到解决方案。任何想法将不胜感激。

我正在使用以下依赖项:

<dependency>
  <groupId>com.azure</groupId>
  <artifactId>azure-storage-blob</artifactId>
  <version>12.3.0</version>
</dependency>

这是我的简单控制器:

package com.sky.video.azuritedemo

import com.azure.core.http.rest.PagedIterable
import com.azure.storage.blob.BlobServiceClientBuilder
import com.azure.storage.blob.models.BlobContainerItem
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController

@RestController
class AzureController() {

  @GetMapping("/container")
  fun getContainers(): PagedIterable<BlobContainerItem>? {
    val connectionString = System.getenv("AZURE_STORAGE_CONNECTION_STRING")

    val client = BlobServiceClientBuilder()
        .connectionString(connectionString)
        .buildClient()

    return client
        .listBlobContainers()
  }
}

并且 env 变量是在 docker-compose 中设置的:

version: '3'
services:
  app:
    build:
      context: .
    command: "mvn spring-boot:run"
    container_name: app
    depends_on:
      - azure
    environment:
      AZURE_STORAGE_CONNECTION_STRING: "DefaultEndpointsProtocol=https;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
    links:
      - azure
    ports:
      - 5005:5005
      - 8080:8080
    volumes:
      - ~/.m2:/root/.m2
      - .:/app
  azure:
    command: "azurite --blobHost 0.0.0.0 --queueHost 0.0.0.0  -d /tmp/logs/debug.log"
    container_name: azure
    environment:
      EXECUTABLE: blob
    image: mcr.microsoft.com/azure-storage/azurite
    ports:
      - "10000:10000"
      - "10001:10001"
    volumes:
      - ./logs:/tmp/logs

进一步调查表明,当我直接在本地计算机上运行 Azurite 和我的应用程序时,我遇到了同样的问题。

【问题讨论】:

标签: java spring azure kotlin


【解决方案1】:

请尝试使用以下连接字符串:

UseDevelopmentStorage=true

上述连接字符串将尝试连接到默认 IP 地址 (127.0.0.1) 和端口(例如,用于 blob 存储的 10000)。

如果您使用不同的 IP 地址和端口,请使用以下连接字符串:

DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;
AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;
BlobEndpoint=http://<ip-address>:<blob-port>/devstoreaccount1;

而不是

DefaultEndpointsProtocol=https;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==

【讨论】:

  • 这不起作用,因为它试图连接到 127.0.0.1 上的 Azurite,但是当我在 docker-compose 中运行时,这不是 Azurite 实例的 IP 地址
  • Azurite 实例的 IP 地址是多少?
  • 虽然它在我不知道的 docker 网络中,但我非常怀疑它在重新启动之间是否会相同。
  • 我认为您需要指定 IP 地址才能连接到存储模拟器。我已经编辑了我的答案并包含了一个备用连接字符串,您可以在其中指定 IP 地址和端口。
  • 即使我在主机上同时运行 Azurite 和我的应用程序并使用 127.0.0.1 进行连接,我也会遇到相同的错误
猜你喜欢
  • 2020-04-24
  • 1970-01-01
  • 2021-01-18
  • 2015-03-22
  • 2015-08-29
  • 2019-11-01
  • 2014-03-21
  • 2018-09-25
  • 1970-01-01
相关资源
最近更新 更多