【问题标题】:Docker and AzureKeyVault: unable to load shared library 'libsecret-1.so.0'Docker 和 AzureKeyVault:无法加载共享库“libsecret-1.so.0”
【发布时间】:2021-06-06 13:31:48
【问题描述】:

我有连接到 MongoDb 的 Asp.net 核心 Xunit 集成测试,以测试集合上的基本存储库。测试在 AKS 的容器中构建和运行。我已经设置了测试夹具来连接 Azure Key Vault 以检索到 MongoDb 的连接字符串。

        var pathToSetting= Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

        var configuration = new ConfigurationBuilder()
            .SetBasePath(pathToSetting)
            .AddJsonFile("appsettings.json")
            .AddEnvironmentVariables();

        var secretClient = new SecretClient(
            new Uri("url_to_Azure_keyVault"),
            new DefaultAzureCredential(),
            new SecretClientOptions()
            {
                Retry =
                {
                    Delay = TimeSpan.FromSeconds(2),
                    MaxDelay = TimeSpan.FromSeconds(4),
                    MaxRetries = 2,
                    Mode = RetryMode.Exponential
                }
            });

        configuration.AddAzureKeyVault(secretClient, new KeyVaultSecretManager());

我正在使用以下 Docker 文件进行集成测试:

#Grab an OS image made to run the .Net Core SDK
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build

#copy files for build
WORKDIR /testProject
COPY . .

RUN dotnet build tests/integrationTest.csproj  --output /testProject/artifacts

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS final
COPY --from=build ["/testProject/artifacts", "/testProject/artifacts"]
ENTRYPOINT dotnet test /testProject/artifacts/integrationTest.dll

测试在 Visual Studio 本地运行良好,但在容器本地和 AKS 中运行时失败并出现以下异常。

[xUnit.net 00:00:03.10]     IntegrationTest1 [FAIL]X 
Test1 [1ms]
  Error Message:
   System.AggregateException : One or more errors occurred. (SharedTokenCacheCredential authentication failed: Persistence check failed. Inspect inner exception for details) (The following constructor parameters did not have matching fixture data: TestFixture testFixture)
---- Azure.Identity.AuthenticationFailedException : SharedTokenCacheCredential authentication failed: Persistence check failed. Inspect inner exception for details
-------- Microsoft.Identity.Client.Extensions.Msal.MsalCachePersistenceException : Persistence check failed. Inspect inner exception for details
------------ System.DllNotFoundException : Unable to load shared library 'libsecret-1.so.0' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment
variable: liblibsecret-1.so.0: cannot open shared object file: No such file or directory

任何想法如何解决此错误?

【问题讨论】:

标签: azure docker asp.net-core azure-aks azure-keyvault


【解决方案1】:

不是根本原因,但今天早上我出现了同样的错误。将 Microsoft.Web.Identity 包从 1.7.0 降到 1.6.0 就可以了。

从其他 Azure 包上的 GitHub 问题看来,包装这些异常是一个常见的错误,并且会被记录。

【讨论】:

  • 感谢 dpmadden,我看到了类似的 github 页面,但找不到直接解决此问题的讨论。
【解决方案2】:

我在处理自己的问题时遇到了这个潜在的解决方法:

Wherever you create new DefaultAzureCredentialOptions, you should also set the property ExcludeSharedTokenCacheCredential to true.

In your WSL environment install libsecret-1-dev. In Ubuntu for example, run the command sudo apt install libsecret-1-dev. This will add libsecret-1.so.0 to your system so that MSAL can find it.

https://hungyi.net/posts/wsl2-msal-extensions/

它对我不起作用,但我使用的 docker 容器没有完全访问 apt 的权限。我无法安装 libsecret-1-dev。

【讨论】:

    猜你喜欢
    • 2021-06-15
    • 2013-10-27
    • 1970-01-01
    • 2020-01-24
    • 1970-01-01
    • 2016-12-20
    • 1970-01-01
    • 1970-01-01
    • 2021-05-10
    相关资源
    最近更新 更多