6

I have Asp.net core Xunit integration tests that connect to MongoDb to test basic repositories on collections. The tests are built and run in a container in AKS. I have setup the test fixture to connect Azure Key Vault to retrieve connection string to a 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());

I am using the following Docker file for the integration tests:

#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

The tests run fine locally from Visual Studio but fail with exception below when run in container both locally and in 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

Any ideas how to troubleshoot this error ?

RedRose
  • 555
  • 7
  • 27

3 Answers3

9

I came across this potential fix while working on my own issue:

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/

It didn't work for me, but I am using a docker container that doesn't have full access to apt. I can't install libsecret-1-dev.

Jeremiah Adams
  • 488
  • 1
  • 8
  • 19
1

Not a root cause, but same error popped up for me this morning. Rolling Microsoft.Web.Identity package down from 1.7.0 to 1.6.0 did the trick.

Looks like from the GitHub issues on other Azure packages, wrapping these exceptions is a common bug that gets logged.

dpmadden
  • 21
  • 2
  • Thanks dpmadden, I saw similar github pages but I could not find a discussion that directly address this issue. – RedRose Mar 09 '21 at 14:21
1

Switching Azure.Identity 1.2.3 to 1.2.2 did the trick for me (this page helped me https://hungyi.net/posts/wsl2-msal-extensions/).

Andrew Dashkov
  • 301
  • 1
  • 8