dapr / dotnet-sdk

Dapr SDK for .NET

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Secretstore broken since 1.13

ManuDinicola opened this issue · comments

Expected Behavior

Expected that the load of secret from a kubernetes/file store works without issue.

Actual Behavior

Since the v1.13, the extension to load secret is broken.

  .AddDaprSecretStore(configuration =>
                {
                    configuration.KeyDelimiters = new List<string>() { ".", "__" };
                    configuration.SecretDescriptors = secretDescriptors;
                    configuration.Store = "kubernetes";
                    configuration.Client = daprClient;
                }
            )

Steps to Reproduce the Problem

Create a simple secret store component
ex :

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: kubernetes
spec:
  type: secretstores.local.file
  version: v1
  metadata:
  - name: secretsFile
    value: C:/Users/emmanuel.dinicola/.dapr/components/secrets.json
  - name: nestedSeparator
    value: ":"
  - name: multiValued
    value: true

Configure the secrets.json like this

{
  "pharma-common": {
    "MyFirstKey": "1",
    "MySecondKey": "2"
  }
}

This problem has been introduced by this #887
Indeed if you look the code that has been changed in DaprSecretStoreConfigurationProvider.cs

         foreach (var key in result.Keys)
                    {
                        if (data.ContainsKey(key))
                        {
                            throw new InvalidOperationException(
                                $"A duplicate key '{key}' was found in the secret store '{store}'. Please remove any duplicates from your secret store.");
                        }

                        data.Add(normalizeKey ? NormalizeKey(secretDescriptor.SecretName) : secretDescriptor.SecretName, result[key]);
                    }

The data.Add will throw error on the second key cause the secretDescriptor.SecretName will not change.

== APP == Unhandled exception. System.ArgumentException: An item with the same key has already been added. Key: pharma-common
== APP ==    at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
== APP ==    at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
== APP ==    at Dapr.Extensions.Configuration.DaprSecretStore.DaprSecretStoreConfigurationProvider.LoadAsync() in D:\GitPR\dotnet-sdk\src\Dapr.Extensions.Configuration\DaprSecretStoreConfigurationProvider.cs:line 232

If we back to the previous code in 1.12 and replace secretDescription.SecretName by key, then no more error.

Release Note

RELEASE NOTE:

Is there any chance that will be fixed soon? We want to upgrade to this version that are .net 8 compliant

Is there any chance that will be fixed soon? We want to upgrade to this version that are .net 8 compliant

We're looking into it. Expect updates soon.

Fixed with #1274 and released as part of v1.13.1