aws-dotnet-extensions-configuration: DuplicateParameterException can break a production application

Describe the bug

The extension throws a DuplicateParameterException when a “duplicate” parameter is detected because the keys are case-insensitive in code but case-sensitive in Parameter Store. This means that an application that uses this extension on startup as describe in the documentation can be prevented from starting simply by adding a key to Parameter Store–no code changes.

Expected Behavior

The extension should gracefully handle a duplicate key, probably by letting the last value win since .NET configuration works that way anyway.

Current Behavior

The extension throws an exception. Handling the exception isn’t really an option since the rest of the configuration won’t be available.

Reproduction Steps

  1. Add a value to Parameter Store, e.g. /myApp/myKey
  2. Add the prefix to the configuration using the application extension method:
    builder.Configuration.AddSystemsManager("/myApp");
    
  3. Optionally start the app to show that it works
  4. Add a new value to Parameter Store having the same key as step 1 but with different casing, e.g. /myApp/mykey
  5. Restart the app and note that it throws a DuplicateParameterException on startup

Possible Solution

I don’t consider the addition of a configuration parameter to be an action that could cause an application to fail to start. While the conflict in keys is something I would definitely want to know about, I don’t want the application to not start at least in production. My suggested behavior is allowing the last value to win, though perhaps the exact behavior could be configurable itself.

Additional Information/Context

No response

AWS .NET SDK and/or Package version used

Amazon.Extensions.Configuration.SystemsManager 6.2.0

Targeted .NET Platform

.NET Core 7.0

Operating System and version

N/A

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

In your case the duplicate config value wasn’t used so it wouldn’t be problem but this library has no idea what values are going to be used or not. We could add an opt-in flag to ignore duplicate and use one of the values at random but who would use that flag?

I’m assuming some of the config values being pulled are being used and it would have been bad if the wrong value was used. So if the dev caused a duplicate for a critical config setting and you turn that flag on your system could get corrupted. Would you really leave yourself open for that type of corruption by turning this opt-in flag on?